From e91a85d73186a3ae9a485e11f275d9a3ba076d23 Mon Sep 17 00:00:00 2001 From: Tim Nieradzik Date: Sun, 27 Jan 2019 14:01:53 +0100 Subject: [PATCH] ArtefactResolution: Inherit target platforms from parent Pull request #6 uncovered a problem in `ArtefactResolution`: When a test module does not set any target platforms, its dependencies would not be resolved. --- .../seed/artefact/ArtefactResolution.scala | 6 +++-- src/main/scala/seed/artefact/Coursier.scala | 5 +++-- .../artefact/ArtefactResolutionSpec.scala | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/scala/seed/artefact/ArtefactResolution.scala b/src/main/scala/seed/artefact/ArtefactResolution.scala index fe8110e..19194db 100644 --- a/src/main/scala/seed/artefact/ArtefactResolution.scala +++ b/src/main/scala/seed/artefact/ArtefactResolution.scala @@ -169,8 +169,9 @@ object ArtefactResolution { module: Module, platforms: Set[Platform], parent: Module = Module() - ): Set[Dep] = - module.targets.toSet[Platform].intersect(platforms).flatMap { target => + ): Set[Dep] = { + val targets = if (module.targets.isEmpty) parent.targets else module.targets + targets.toSet[Platform].intersect(platforms).flatMap { target => // Shared libraries if (target == JVM) jvmDeps(build, @@ -194,6 +195,7 @@ object ArtefactResolution { List(native, parent.native.getOrElse(Module()), module))) ) ++ module.test.toSet.flatMap(libraryDeps(build, _, platforms, module)) + } def libraryArtefacts(build: Build, module: Module, diff --git a/src/main/scala/seed/artefact/Coursier.scala b/src/main/scala/seed/artefact/Coursier.scala index 684037c..c1ca21d 100644 --- a/src/main/scala/seed/artefact/Coursier.scala +++ b/src/main/scala/seed/artefact/Coursier.scala @@ -136,9 +136,10 @@ object Coursier { sources = optionalArtefacts, javaDoc = optionalArtefacts))) - require(deps.forall(d => result.map(_._1.module).exists(m => + val missing = deps.filter(d => !result.map(_._1.module).exists(m => m.organization.value == d.organisation && - m.name.value == d.artefact)), "Missing dependencies in artefact resolution") + m.name.value == d.artefact)) + require(missing.isEmpty, s"Missing dependencies in artefact resolution: $missing") result.map(a => (a._2.classifier, a._3)).toList } diff --git a/src/test/scala/seed/artefact/ArtefactResolutionSpec.scala b/src/test/scala/seed/artefact/ArtefactResolutionSpec.scala index 2d1aa3e..465f759 100644 --- a/src/test/scala/seed/artefact/ArtefactResolutionSpec.scala +++ b/src/test/scala/seed/artefact/ArtefactResolutionSpec.scala @@ -1,8 +1,13 @@ package seed.artefact +import java.nio.file.Paths + import minitest.SimpleTestSuite import seed.model.Build.Dep import seed.model.Platform.JavaScript +import seed.model.Build.{Module, Project} +import seed.model.Platform.JVM +import seed.model.Build object ArtefactResolutionSpec extends SimpleTestSuite { test("dependencyFromDep()") { @@ -12,4 +17,21 @@ object ArtefactResolutionSpec extends SimpleTestSuite { assertEquals(javaDep, Dep("org.scala-js", "scalajs-dom_sjs0.6_2.12", "0.9.6")) } + + test("Extract platform dependencies of test module in libraryDeps()") { + val build = + Build( + project = Project("2.12.8", scalaJsVersion = Some("0.6.26")), + module = Map( + "a" -> Module( + targets = List(JVM, JavaScript), + test = Some(Module( + sources = List(Paths.get("a/test")), + scalaDeps = List(Dep("io.monix", "minitest", "2.3.2"))))))) + + val libraryDeps = ArtefactResolution.allLibraryDeps(build) + assertEquals(libraryDeps, Set( + Dep("io.monix", "minitest_2.12", "2.3.2"), + Dep("io.monix", "minitest_sjs0.6_2.12", "2.3.2"))) + } }