From 31f1eeea9989ffa133824f4a539c734d4c0d10d0 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Tue, 19 Sep 2023 21:43:30 +0200 Subject: [PATCH] bugfix: Never set empty Scala JS version from sbt PReviously, we were always expecting scala JS plugin to find the correct version of Scala JS, however I think for Scala 3 it's not a plugin, which is causing the version field to be empty. Now, we look for the scala-js library instead and default to the latest known scala js version. --- build.sbt | 7 ++++++- .../bloop/integrations/sbt/SbtBloop.scala | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/build.sbt b/build.sbt index 34dde47769..647229929b 100644 --- a/build.sbt +++ b/build.sbt @@ -336,6 +336,7 @@ val integrations = file("integrations") lazy val sbtBloop: Project = project .enablePlugins(ScriptedPlugin) .disablePlugins(ScalafixPlugin) + .enablePlugins(BuildInfoPlugin) .in(integrations / "sbt-bloop") .settings( scriptedBufferLog := false, @@ -347,7 +348,11 @@ lazy val sbtBloop: Project = project sbtPlugin := true, sbtVersion := SbtVersion, target := (file("integrations") / "sbt-bloop" / "target" / SbtVersion).getAbsoluteFile, - libraryDependencies += Dependencies.bloopConfig + libraryDependencies += Dependencies.bloopConfig, + buildInfoPackage := "bloop.integrations.sbt", + buildInfoKeys := List[BuildInfoKey]( + "latestScalaJsVersion" -> Dependencies.scalaJs1Version + ) ) lazy val buildpressConfig = (project in file("buildpress-config")) diff --git a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala index ea3b53c50d..3c8fe72837 100644 --- a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala +++ b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala @@ -723,7 +723,7 @@ object BloopDefaults { private final val CompilerPluginConfig = "plugin->default(compile)" /** Find native version. Copy pasted from Scala native. */ - def findVersion(deps: Seq[ModuleID], org: String): Option[String] = { + def findNativePluginVersion(deps: Seq[ModuleID], org: String): Option[String] = { def isPlugin(d: ModuleID, org: String) = d.configurations.toList.contains(CompilerPluginConfig) && d.organization == org deps.find(isPlugin(_, org)).map(_.revision) @@ -762,7 +762,7 @@ object BloopDefaults { val nativeLinkStubs = ScalaNativeKeys.nativeLinkStubs.?.value.getOrElse(emptyNative.linkStubs) val nativeCompileOptions = ScalaNativeKeys.nativeCompileOptions.?.value.toList.flatten val nativeLinkingOptions = ScalaNativeKeys.nativeLinkingOptions.?.value.toList.flatten - val nativeVersion = findVersion(libraryDeps, "org.scala-native").getOrElse(emptyNative.version) + val nativeVersion = findNativePluginVersion(libraryDeps, "org.scala-native").getOrElse(emptyNative.version) val nativeMode = ScalaNativeKeys.nativeMode.?.value match { case Some("debug") => Config.LinkerMode.Debug @@ -777,25 +777,28 @@ object BloopDefaults { } } else if (pluginLabels.contains(ScalaJsPluginLabel)) { Def.task { - val emptyScalaJs = Config.JsConfig.empty - val scalaJsVersion = findVersion(libraryDeps, "org.scala-js").getOrElse(emptyScalaJs.version) + val scalaJsVersion = libraryDeps + .find(module => module.organization == "org.scala-js" && module.name.startsWith("scalajs-library_")) + .map(_.revision) + .getOrElse(BuildInfo.latestScalaJsVersion) + val scalaJsStage = BloopKeys.bloopScalaJSStage.value match { case Some(ScalaJsFastOpt) => Config.LinkerMode.Debug case Some(ScalaJsFullOpt) => Config.LinkerMode.Release - case _ => emptyScalaJs.mode + case _ => Config.LinkerMode.Debug } val scalaJsModule = BloopKeys.bloopScalaJSModuleKind.value match { case Some(NoJSModule) => Config.ModuleKindJS.NoModule case Some(CommonJSModule) => Config.ModuleKindJS.CommonJSModule case Some(ESModule) => Config.ModuleKindJS.ESModule - case _ => emptyScalaJs.kind + case _ => Config.ModuleKindJS.NoModule } val scalaJsEmitSourceMaps = - ScalaJsKeys.scalaJSEmitSourceMaps.?.value.getOrElse(emptyScalaJs.emitSourceMaps) + ScalaJsKeys.scalaJSEmitSourceMaps.?.value.getOrElse(false) val jsdom = Some(false) - val jsConfig = Config.JsConfig(scalaJsVersion, scalaJsStage, scalaJsModule, scalaJsEmitSourceMaps, jsdom, None, None, emptyScalaJs.toolchain) + val jsConfig = Config.JsConfig(scalaJsVersion, scalaJsStage, scalaJsModule, scalaJsEmitSourceMaps, jsdom, None, None, Nil) Config.Platform.Js(jsConfig, mainClass) } } else {