Skip to content

Commit ea6c65d

Browse files
committed
Fix scala-js#4610: Warn when -scalajs or -Xplugin:scalajs-compiler.jar is missing.
Often, this happens because a user accidentally used `scalacOptions := ...` instead of using `++=`. The symptoms are however obscure, and it can be difficult to diagnose. We now explicitly detect this, and emit a warning if something is amiss. This feature is not automatically tested because `scripted` does not have any feature to test that a specific log message is written.
1 parent 81ef662 commit ea6c65d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,26 @@ private[sbtplugin] object ScalaJSPluginInternal {
366366
val classpath = Attributed.data(fullClasspath.value)
367367
val log = streams.value.log
368368
val tlog = sbtLogger2ToolsLogger(log)
369+
val config = configuration.value.name
370+
371+
/* #4610 Warn if `-Xplugin:scalajs-compiler.jar` (Scala 2) or
372+
* `-scalajs` (Scala 3) is missing from the `scalacOptions`.
373+
* This feature is not automatically tested.
374+
*/
375+
def warnMissingScalacOption(thingMissing: String): Unit = {
376+
log.warn(
377+
s"$thingMissing was missing from `$config / scalacOptions`, but it is required to produce Scala.js IR.")
378+
log.warn("Linking, running and/or testing will probably go wrong.")
379+
log.warn("The most likely cause is that you used `scalacOptions := ...` instead of using `++=`.")
380+
}
381+
val scalacOpts = scalacOptions.value
382+
if (scalaVersion.value.startsWith("2.")) {
383+
if (!scalacOpts.exists(opt => opt.startsWith("-Xplugin:") && opt.contains("scalajs-compiler")))
384+
warnMissingScalacOption("The `scalajs-compiler.jar` compiler plugin")
385+
} else {
386+
if (!scalacOpts.contains("-scalajs"))
387+
warnMissingScalacOption("The `-scalajs` flag")
388+
}
369389

370390
val (irFiles, paths) = enhanceIRVersionNotSupportedException {
371391
tlog.time("Update IR cache") {

0 commit comments

Comments
 (0)