Skip to content

Commit

Permalink
IDEA: Set correct module dependencies
Browse files Browse the repository at this point in the history
Currently, only module dependencies of cross-platform modules are
set when generating an IDEA project. Also include the module
dependencies from platform-specific modules.

This fixes a regression introduced in 51a27f5.
  • Loading branch information
tindzk committed Sep 3, 2019
1 parent 12c3f47 commit 171e25d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/seed/generation/Idea.scala
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ object Idea {
),
moduleDeps =
(if (!isCrossBuild) List() else List(name)) ++
collectJsModuleDeps(build, module).flatMap(
collectJsModuleDeps(build, jsModule).flatMap(
name => BuildConfig.targetNames(build, name, JavaScript)
),
projectPath = projectPath,
Expand Down Expand Up @@ -363,7 +363,7 @@ object Idea {
),
moduleDeps =
(if (!isCrossBuild) List() else List(name)) ++
collectJvmModuleDeps(build, module)
collectJvmModuleDeps(build, jvmModule)
.flatMap(name => BuildConfig.targetNames(build, name, JVM)),
projectPath = projectPath,
buildPath = buildPath,
Expand Down Expand Up @@ -436,7 +436,7 @@ object Idea {
),
moduleDeps =
(if (!isCrossBuild) List() else List(name)) ++
collectNativeModuleDeps(build, module).flatMap(
collectNativeModuleDeps(build, nativeModule).flatMap(
name => BuildConfig.targetNames(build, name, Native)
),
projectPath = projectPath,
Expand Down
66 changes: 41 additions & 25 deletions src/test/scala/seed/generation/IdeaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import seed.model.{Build, Config}
import seed.generation.util.BuildUtil.tempPath

object IdeaSpec extends SimpleTestSuite {
private val packageConfig = PackageConfig(
tmpfs = false,
silent = false,
ivyPath = None,
cachePath = None
)

test("Normalise paths") {
assertEquals(
PathUtil.normalisePath(Idea.ModuleDir, Paths.get("/tmp"))(
Expand Down Expand Up @@ -93,7 +100,6 @@ object IdeaSpec extends SimpleTestSuite {

val projectPath = Paths.get(".")
val outputPath = Paths.get("/tmp")
val packageConfig = PackageConfig(false, false, None, None)
val compilerDeps0 = ArtefactResolution.allCompilerDeps(build)
val (_, platformResolution, compilerResolution) =
ArtefactResolution.resolution(
Expand Down Expand Up @@ -126,15 +132,43 @@ object IdeaSpec extends SimpleTestSuite {
assert(Files.exists(modulesPath.resolve("c.iml")))
}

test("Generate project with correct module dependencies") {
val result = BuildConfig
.load(Paths.get("test").resolve("platform-module-deps"), Log.urgent)
.get
val outputPath = tempPath.resolve("platform-module-deps")
Files.createDirectory(outputPath)
cli.Generate.ui(
Config(),
result.projectPath,
outputPath,
result.resolvers,
result.build,
Command.Idea(packageConfig),
Log.urgent
)

val ideaPath = outputPath.resolve(".idea")
val modulesPath = ideaPath.resolve("modules")

val exampleModule =
pine.XmlParser.fromString(
FileUtils.readFileToString(
modulesPath.resolve("example.iml").toFile,
"UTF-8"
)
)

val moduleNames = exampleModule
.byTagAll["orderEntry"]
.filter(_.attr("type").contains("module"))
.flatMap(_.attr("module-name"))
assertEquals(moduleNames, List("core"))
}

test("Generate project with custom compiler options") {
val result =
BuildConfig.load(Paths.get("test/compiler-options"), Log.urgent).get
val packageConfig = PackageConfig(
tmpfs = false,
silent = false,
ivyPath = None,
cachePath = None
)
val outputPath = tempPath.resolve("compiler-options")
Files.createDirectory(outputPath)
cli.Generate.ui(
Expand Down Expand Up @@ -190,12 +224,6 @@ object IdeaSpec extends SimpleTestSuite {
val result = BuildConfig
.load(Paths.get("test/multiple-scala-versions"), Log.urgent)
.get
val packageConfig = PackageConfig(
tmpfs = false,
silent = false,
ivyPath = None,
cachePath = None
)
val outputPath = tempPath.resolve("multiple-scala-versions-idea")
Files.createDirectory(outputPath)
cli.Generate.ui(
Expand Down Expand Up @@ -287,12 +315,6 @@ object IdeaSpec extends SimpleTestSuite {
test("Generate project with test project") {
val result =
BuildConfig.load(Paths.get("test/test-module"), Log.urgent).get
val packageConfig = PackageConfig(
tmpfs = false,
silent = false,
ivyPath = None,
cachePath = None
)
val outputPath = tempPath.resolve("test-module")
Files.createDirectory(outputPath)
cli.Generate.ui(
Expand Down Expand Up @@ -326,12 +348,6 @@ object IdeaSpec extends SimpleTestSuite {
test("Generate Scala Native project") {
val result =
BuildConfig.load(Paths.get("test/scala-native-module"), Log.urgent).get
val packageConfig = PackageConfig(
tmpfs = false,
silent = false,
ivyPath = None,
cachePath = None
)
val outputPath = tempPath.resolve("scala-native-module")
Files.createDirectory(outputPath)
cli.Generate.ui(
Expand Down
11 changes: 11 additions & 0 deletions test/platform-module-deps/build.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[project]
scalaVersion = "2.12.8"

[module.core.jvm]
root = "jvm"
sources = ["jvm/src/"]

[module.example.jvm]
moduleDeps = ["core"]
root = "example"
sources = ["example/src/"]

0 comments on commit 171e25d

Please sign in to comment.