Skip to content

Commit

Permalink
BuildConfig: Detect invalid references on platform modules (#86)
Browse files Browse the repository at this point in the history
Invalid module references currently cause an exception during artefact
resolution:

```
Exception in thread "main" java.util.NoSuchElementException: key not found: invalid-module
	at scala.collection.immutable.Map$Map2.apply(Map.scala:129)
	at seed.config.BuildConfig$.$anonfun$collectJsModuleDeps$1(BuildConfig.scala:541)
	at scala.collection.immutable.List.flatMap(List.scala:335)
	at seed.config.BuildConfig$.collectJsModuleDeps(BuildConfig.scala:539)
	at seed.config.BuildConfig$.collectModuleDepsBase(BuildConfig.scala:587)
	at seed.config.BuildConfig$.$anonfun$collectModuleDeps$2(BuildConfig.scala:599)
	at scala.collection.immutable.List.flatMap(List.scala:335)
	at seed.config.BuildConfig$.collectModuleDeps(BuildConfig.scala:599)
	at seed.artefact.ArtefactResolution$.allRuntimeLibs(ArtefactResolution.scala:225)
	at seed.artefact.ArtefactResolution$.$anonfun$allRuntimeLibs$8(ArtefactResolution.scala:247)
	at scala.collection.immutable.List.flatMap(List.scala:335)
	at seed.artefact.ArtefactResolution$.allRuntimeLibs(ArtefactResolution.scala:244)
	at seed.artefact.ArtefactResolution$.runtimeResolution(ArtefactResolution.scala:379)
	at seed.cli.Generate$.ui(Generate.scala:38)
	at seed.Cli$.main(Cli.scala:394)
	at seed.Cli.main(Cli.scala)
```

The fix is to include all platform modules in the detection logic.
  • Loading branch information
tindzk authored Feb 25, 2020
1 parent 57d6422 commit 753c372
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/scala/seed/config/BuildConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,13 @@ object BuildConfig {
}

val invalidModuleDeps =
module.moduleDeps.filter(!build.isDefinedAt(_))
module.moduleDeps.filter(!build.isDefinedAt(_)) ++
Platform.All.flatMap(
p =>
platformModule(module, p._1).toList
.flatMap(_.moduleDeps.filter(!build.isDefinedAt(_)))
)

val invalidTargetModules =
module.target.toList
.flatMap(_._2.`class`)
Expand Down Expand Up @@ -388,11 +394,11 @@ object BuildConfig {
error(s"`root` cannot be set on native test module $moduleName")
else if (invalidModuleDeps.nonEmpty)
error(
s"Module dependencies of $moduleName not found in scope: ${invalidModuleDeps.mkString(", ")}"
s"Module dependencies of $moduleName not found in scope: ${invalidModuleDeps.map(Ansi.italic).mkString(", ")}"
)
else if (invalidTargetModules.nonEmpty)
error(
s"Invalid module(s) referenced in $moduleName: ${invalidTargetModules.mkString(", ")}"
s"Invalid module(s) referenced in $moduleName: ${invalidTargetModules.map(Ansi.italic).mkString(", ")}"
)
else if (invalidTargetModules2.nonEmpty)
error(
Expand Down
56 changes: 56 additions & 0 deletions src/test/scala/seed/config/BuildConfigSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,62 @@ object BuildConfigSpec extends SimpleTestSuite {
)
}

test("Detect invalid module reference") {
val buildToml = """
|[project]
|scalaVersion = "2.12.4"
|
|[module.shared]
|root = "shared/"
|sources = ["shared/src/"]
|targets = ["jvm"]
|
|[module.content]
|root = "content/"
|moduleDeps = ["shared", "invalid-module"]
|sources = ["content/src/"]
|targets = ["jvm"]
""".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 dependencies of ${Ansi.italic("content")} not found in scope: ${Ansi.italic("invalid-module")}"
)
)
)
}

test("Detect invalid module reference (2)") {
val buildToml = """
|[project]
|scalaVersion = "2.12.4"
|
|[module.shared.jvm]
|root = "shared/"
|sources = ["shared/src/"]
|
|[module.content.jvm]
|root = "content/"
|moduleDeps = ["shared", "invalid-module"]
|sources = ["content/src/"]
""".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 dependencies of ${Ansi.italic("content")} not found in scope: ${Ansi.italic("invalid-module")}"
)
)
)
}

test("Resolve source paths") {
val buildToml = """
|[project]
Expand Down

0 comments on commit 753c372

Please sign in to comment.