From cf7e6aa09fd0c293599781e27bfba70f39759c77 Mon Sep 17 00:00:00 2001 From: Tim Nieradzik Date: Tue, 17 Sep 2019 16:03:38 +0200 Subject: [PATCH] Bloop: Fix classpath of modules with transitive dependencies --- src/main/scala/seed/config/BuildConfig.scala | 32 ++++++++----------- .../generation/BloopIntegrationSpec.scala | 32 +++++++++++++++++++ src/test/scala/seed/generation/IdeaSpec.scala | 2 +- test/platform-module-deps/build.toml | 9 ++++-- 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/main/scala/seed/config/BuildConfig.scala b/src/main/scala/seed/config/BuildConfig.scala index 4a47ffe..d58b797 100644 --- a/src/main/scala/seed/config/BuildConfig.scala +++ b/src/main/scala/seed/config/BuildConfig.scala @@ -546,14 +546,12 @@ object BuildConfig { module: Module ): List[Path] = module.moduleDeps - .filter(name => hasTarget(build, name, Platform.JavaScript)) .flatMap( name => - buildPath - .resolve(targetName(build, name, JavaScript)) +: collectJsClassPath( - buildPath, - build, - build(name).module + build(name).module.js.toList.flatMap( + js => + buildPath.resolve(targetName(build, name, JavaScript)) +: + collectJsClassPath(buildPath, build, js) ) ) .distinct @@ -564,14 +562,12 @@ object BuildConfig { module: Module ): List[Path] = module.moduleDeps - .filter(name => hasTarget(build, name, Platform.Native)) .flatMap( name => - buildPath - .resolve(targetName(build, name, Native)) +: collectNativeClassPath( - buildPath, - build, - build(name).module + build(name).module.native.toList.flatMap( + native => + buildPath.resolve(targetName(build, name, Native)) +: + collectNativeClassPath(buildPath, build, native) ) ) .distinct @@ -582,15 +578,13 @@ object BuildConfig { module: Module ): List[Path] = module.moduleDeps - .filter(name => hasTarget(build, name, Platform.JVM)) .flatMap( name => - buildPath.resolve(targetName(build, name, JVM)) +: - collectJvmClassPath( - buildPath, - build, - build(name).module - ) + build(name).module.jvm.toList.flatMap( + jvm => + buildPath.resolve(targetName(build, name, JVM)) +: + collectJvmClassPath(buildPath, build, jvm) + ) ) .distinct diff --git a/src/test/scala/seed/generation/BloopIntegrationSpec.scala b/src/test/scala/seed/generation/BloopIntegrationSpec.scala index bb03a53..5359166 100644 --- a/src/test/scala/seed/generation/BloopIntegrationSpec.scala +++ b/src/test/scala/seed/generation/BloopIntegrationSpec.scala @@ -369,4 +369,36 @@ object BloopIntegrationSpec extends TestSuite[Unit] { assert(lines.contains("native")) } } + + test("Inherit classpath of platform-specific base modules") { _ => + val result = BuildConfig + .load(Paths.get("test").resolve("platform-module-deps"), Log.urgent) + .get + val buildPath = tempPath.resolve("platform-module-deps-bloop") + Files.createDirectory(buildPath) + cli.Generate.ui( + Config(), + result.projectPath, + buildPath, + result.resolvers, + result.build, + Command.Bloop(packageConfig), + Log.urgent + ) + + val bloopBuildPath = buildPath.resolve("build").resolve("bloop") + + val bloopPath = buildPath.resolve(".bloop") + + val root = readBloopJson(bloopPath.resolve("example.json")) + val paths = root.project.classpath.filter(_.startsWith(buildPath)) + + assertEquals( + paths, + List( + bloopBuildPath.resolve("base"), + bloopBuildPath.resolve("core") + ) + ) + } } diff --git a/src/test/scala/seed/generation/IdeaSpec.scala b/src/test/scala/seed/generation/IdeaSpec.scala index 223e6fe..11043fa 100644 --- a/src/test/scala/seed/generation/IdeaSpec.scala +++ b/src/test/scala/seed/generation/IdeaSpec.scala @@ -169,7 +169,7 @@ object IdeaSpec extends SimpleTestSuite { .byTagAll["orderEntry"] .filter(_.attr("type").contains("module")) .flatMap(_.attr("module-name")) - assertEquals(moduleNames, List("core")) + assertEquals(moduleNames, List("core", "base")) } test("Generate non-JVM cross-platform module") { diff --git a/test/platform-module-deps/build.toml b/test/platform-module-deps/build.toml index cda68a2..22efd64 100644 --- a/test/platform-module-deps/build.toml +++ b/test/platform-module-deps/build.toml @@ -1,9 +1,14 @@ [project] scalaVersion = "2.12.8" +[module.base.jvm] +root = "base" +sources = ["base/src/"] + [module.core.jvm] -root = "jvm" -sources = ["jvm/src/"] +moduleDeps = ["base"] +root = "jvm" +sources = ["jvm/src/"] [module.example.jvm] moduleDeps = ["core"]