Skip to content

Commit

Permalink
ArtefactResolution: Inherit target platforms from parent
Browse files Browse the repository at this point in the history
Pull request #6 uncovered a problem in `ArtefactResolution`: When a
test module does not set any target platforms, its dependencies would
not be resolved.
  • Loading branch information
tindzk committed Jan 27, 2019
1 parent 567c51d commit e91a85d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main/scala/seed/artefact/ArtefactResolution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/seed/artefact/Coursier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/scala/seed/artefact/ArtefactResolutionSpec.scala
Original file line number Diff line number Diff line change
@@ -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()") {
Expand All @@ -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")))
}
}

0 comments on commit e91a85d

Please sign in to comment.