Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Never set empty Scala JS version from sbt #2161

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

tgodzik
Copy link
Contributor

@tgodzik tgodzik commented Sep 19, 2023

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.

@sjrd would this be a correct assumption?

@tgodzik tgodzik requested review from adpi2 and ckipp01 September 19, 2023 19:47
@tgodzik tgodzik mentioned this pull request Sep 19, 2023
Copy link
Member

@adpi2 adpi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe findVersion should be renamed findPluginVersion.

@@ -777,8 +777,12 @@ 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 emptyScalaJs = Config.JsConfig.empty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just set all the default values and removed this, it should be more obvious now.

@sjrd
Copy link
Contributor

sjrd commented Sep 20, 2023

This is "less bad" than looking at the version of the compiler plugin, for sure. However it's still not what sbt-scalajs itself will do. What matters is the version of the linker. You can look at the version of the org.scala.js % scalajs-linker_2.12 artifact within the key Global / scalaJSLinkerImpl / fullClasspath.

@tgodzik
Copy link
Contributor Author

tgodzik commented Sep 21, 2023

This is "less bad" than looking at the version of the compiler plugin, for sure. However it's still not what sbt-scalajs itself will do. What matters is the version of the linker. You can look at the version of the org.scala.js % scalajs-linker_2.12 artifact within the key Global / scalaJSLinkerImpl / fullClasspath.

Hmm... I tried different ways, but I can get that setting in the Bloop plugin itself. How would you normally access it from a different plugin? I tried looking in globalSettings of the Scala JS plugin, but the setting is not initialized.

I also tried faking the setting key and doing:

val linkerClasspath = (Global / ScalaJsKeys.scalaJSLinkerImpl / Keys.fullClasspath ).value

but that throws an exception:

[error] Couldn't run bloopGenerate. Cause: Incomplete(node=Some(Task(_)), tpe=Error, msg=None, causes=List(Incomplete(node=Some(Task(_)), tpe=Error, msg=None, causes=List(), directCause=Some(sbt.internal.util.Init$RuntimeUndefined: References to undefined settings at runtime.

I am thinking of leaving the current mechanism as I don't have any idea how to do it properly :/

@sjrd
Copy link
Contributor

sjrd commented Sep 21, 2023

In another plugin, or in your sbt build itself, you would read the constant value org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.scalaJSVersion.

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.
@tgodzik
Copy link
Contributor Author

tgodzik commented Sep 21, 2023

Maybe findVersion should be renamed findPluginVersion.

Renamed to findNativePluginVersion to be more explicit

@tgodzik
Copy link
Contributor Author

tgodzik commented Sep 21, 2023

In another plugin, or in your sbt build itself, you would read the constant value org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.scalaJSVersion.

But I would need to depend explicitely on the ScalaJS plugin, no?

@tgodzik
Copy link
Contributor Author

tgodzik commented Sep 21, 2023

But I would need to depend explicitely on the ScalaJS plugin, no?

That seems to work, but then I need find the version from the file path, which is another complication. I think the current approach should do for the time being and it at least fixes the issue at hand

Copy link
Member

@adpi2 adpi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tgodzik tgodzik merged commit 571b328 into scalacenter:main Sep 22, 2023
15 of 17 checks passed
@tgodzik tgodzik deleted the set-version branch September 22, 2023 08:35
@kubukoz
Copy link
Contributor

kubukoz commented Nov 13, 2023

Can someone please make a release? I'm seeing

java.lang.RuntimeException: Expected compatible Scala.js version [0.6, 1],  given

on 1.5.11 and it seems like this should've solved it :)

@tgodzik
Copy link
Contributor Author

tgodzik commented Nov 17, 2023

I want to include some sbt fixes still, so will release after that. Sorry for the delay!

@nkgm
Copy link

nkgm commented Nov 30, 2023

This remains an issue for me in 1.5.12:

2023.11.30 12:37:50 INFO  Connected to Build server: Bloop v1.5.12
2023.11.30 12:37:50 INFO  time: Imported build in 0.14s
2023.11.30 12:37:55 INFO  time: indexed workspace in 5.33s
2023.11.30 12:37:55 INFO  {
  "jsonrpc": "2.0",
  "id": "7",
  "error": {
    "code": -32603,
    "message": "java.lang.RuntimeException: Expected compatible Scala.js version [0.6, 1],  given\n\tat scala.sys.package$.error(package.scala:30)\n\tat bloop.engine.tasks.toolchains.ScalaJsToolchain$.artifactNameFrom(ScalaJsToolchain.scala:131)\n\tat bloop.engine.tasks.TestTask$.discoverTestFrameworks(TestTask.scala:246)\n\tat bloop.engine.tasks.TestTask$.findTestNamesWithFramework(TestTask.scala:381)\n\tat bloop.bsp.BloopBspServices.$anonfun$scalaTestClasses$3(BloopBspServices.scala:582)\n\tat scala.collection.immutable.List.map(List.scala:297)\n\tat bloop.bsp.BloopBspServices.$anonfun$scalaTestClasses$1(BloopBspServices.scala:580)\n\tat bloop.bsp.BloopBspServices.$anonfun$ifInitialized$4(BloopBspServices.scala:371)\n\tat bloop.task.Task.$anonfun$runAsync$8(Task.scala:268)\n\tat monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:170)\n\tat monix.eval.internal.TaskRestartCallback.syncOnSuccess(TaskRestartCallback.scala:101)\n\tat monix.eval.internal.TaskRestartCallback.onSuccess(TaskRestartCallback.scala:74)\n\tat monix.eval.internal.TaskCreate$CallbackForCreate.run(TaskCreate.scala:252)\n\tat monix.execution.internal.Trampoline.monix$execution$internal$Trampoline$$immediateLoop(Trampoline.scala:66)\n\tat monix.execution.internal.Trampoline.startLoop(Trampoline.scala:32)\n\tat monix.execution.schedulers.TrampolineExecutionContext$JVMOptimalTrampoline.startLoop(TrampolineExecutionContext.scala:132)\n\tat monix.execution.internal.Trampoline.execute(Trampoline.scala:40)\n\tat monix.execution.schedulers.TrampolineExecutionContext.execute(TrampolineExecutionContext.scala:57)\n\tat monix.execution.schedulers.BatchingScheduler.execute(BatchingScheduler.scala:50)\n\tat monix.execution.schedulers.BatchingScheduler.execute$(BatchingScheduler.scala:47)\n\tat monix.execution.schedulers.AsyncScheduler.execute(AsyncScheduler.scala:31)\n\tat monix.eval.internal.TaskCreate$CallbackForCreate.startExecution(TaskCreate.scala:236)\n\tat monix.eval.internal.TaskCreate$CallbackForCreate.tryOnSuccess(TaskCreate.scala:202)\n\tat monix.eval.internal.TaskCreate$CallbackForCreate.onSuccess(TaskCreate.scala:195)\n\tat bloop.task.Task$.result$2(Task.scala:465)\n\tat bloop.task.Task$.$anonfun$parSequenceUnordered$3(Task.scala:475)\n\tat bloop.task.Task$.$anonfun$parSequenceUnordered$3$adapted(Task.scala:473)\n\tat scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)\n\tat java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)\n\tat java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)\n\tat java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)\n\tat java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)\n\tat java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)\n\tat java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)\n"
  }
}

@tgodzik
Copy link
Contributor Author

tgodzik commented Nov 30, 2023

Did you use bloop-sbt 1.5.12 to export the json definition also? Do you have a reproduction?

@nkgm
Copy link

nkgm commented Nov 30, 2023

Apparently not, thanks for pointing that out!

@tgodzik
Copy link
Contributor Author

tgodzik commented Nov 30, 2023

There is a small regression, so we haven't updated it in Metals yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants