Skip to content

Commit

Permalink
BuildConfig: Check compatibility of target platforms
Browse files Browse the repository at this point in the history
Ensure that inherited modules have compatible target platforms.
  • Loading branch information
tindzk committed Sep 15, 2019
1 parent c03aea7 commit 9ff855a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main/scala/seed/config/BuildConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ object BuildConfig {
hasCycle(name, Set())
}

val incompatibleModuleDepPlatform =
module.moduleDeps
.flatMap { name =>
build.get(name).map(m => name -> m.module)
}
.map { case (n, m) => (n, module.targets.diff(m.targets)) }
.find(_._2.nonEmpty)

val moduleName = Ansi.italic(name)

if (module.targets.isEmpty && module.target.isEmpty)
Expand Down Expand Up @@ -378,9 +386,16 @@ object BuildConfig {
.italic(s"[module.$name.test.${invalidPlatformTestModule.get.id}]")}?"
)
else if (cyclicModuleDep)
error(s"Module ${Ansi.italic(name)} cannot depend on itself")
error(s"Module $moduleName cannot depend on itself")
else if (cyclicModuleDep2)
error(s"Cycle detected in dependencies of module ${Ansi.italic(name)}")
error(s"Cycle detected in dependencies of module $moduleName")
else if (incompatibleModuleDepPlatform.isDefined)
error(
s"Module ${Ansi.italic(incompatibleModuleDepPlatform.get._1)} has missing target platform(s) (${incompatibleModuleDepPlatform.get._2
.map(_.id)
.map(Ansi.italic)
.mkString(", ")}) required by $moduleName"
)
else true
}

Expand Down
31 changes: 31 additions & 0 deletions src/test/scala/seed/config/BuildConfigSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,37 @@ object BuildConfigSpec extends SimpleTestSuite {
)
}

test("Platform compatibility when inheriting") {
val buildToml = """
|[project]
|scalaJsVersion = "0.6.26"
|scalaNativeVersion = "0.3.7"
|
|[module.foo]
|scalaVersion = "2.11.11"
|sources = ["foo/"]
|targets = ["js"]
|
|[module.bar]
|scalaVersion = "2.11.11"
|moduleDeps = ["foo"]
|sources = ["bar/"]
|targets = ["js", "native"]
""".stripMargin

val messages = ListBuffer[String]()
val log = new Log(messages += _, identity, LogLevel.Error, false)
parseBuild(buildToml, log, fail = true)(_ => "")
assert(
messages.exists(
_.contains(
s"Module ${Ansi.italic("foo")} has missing target platform(s) (${Ansi
.italic("native")}) required by ${Ansi.italic("bar")}"
)
)
)
}

test("Scala version compatibility") {
val buildToml = """
|[module.foo.jvm]
Expand Down

0 comments on commit 9ff855a

Please sign in to comment.