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

align behavior with semanticdb-scalac: last arg wins #1116

Merged
merged 1 commit into from
May 13, 2020

Conversation

bjaglin
Copy link
Collaborator

@bjaglin bjaglin commented May 9, 2020

Should fix #1110, as failure to look up the target root triggers the presentation compiler, with a version that might not match the bytecode injected (see #998).

The SemanticDBPlugin from sbt 1.3.x duplicates the targetroot option on Test (or any configuration that extends one where scalafix is enabled) via parent configuration delegation.: https://github.com/sbt/sbt/blob/a1b54d027a87654cbc782270872afc1b4c5a8852/main/src/main/scala/sbt/plugins/SemanticdbPlugin.scala#L42-L45.

In that case, semanticdb-scalac picks the last: https://github.com/scalameta/scalameta/blob/de206a796c7558f0ceb8bf3a557f3296f0ac34de/semanticdb/scalac/library/src/main/scala/scala/meta/internal/semanticdb/scalac/ConfigOps.scala#L105-L106, while scalafix was picking the first.

@bjaglin bjaglin marked this pull request as ready for review May 9, 2020 23:02
@daddykotex
Copy link
Contributor

Thanks to you, I could include a work around in the meantime:

lazy val scalaFixTestWorkAround = Def.settings(
  scalacOptions in Test := {
    val initial = (scalacOptions in Test).value
    val semanticDbOptions = initial.filter(_.contains("-P:semanticdb:"))
    val semanticDbLess = initial.filterNot(_.contains("-P:semanticdb:"))
    semanticDbLess ++ semanticDbOptions.lastOption.toSeq
  }
)

Then use as .settings(scalaFixTestWorkAround) on the modules you need.

@bjaglin
Copy link
Collaborator Author

bjaglin commented May 12, 2020

@daddykotex using the sbt 1.2.x way should also do the trick since the "problem" is in the sbt 1.3.x plugin:

 lazy val myproject = project.settings(
   scalaVersion := "2.12.11", // 2.11.12, or 2.13.2
+  addCompilerPlugin(scalafixSemanticdb), // enable SemanticDB
   scalacOptions ++= List(
+    "-Yrangepos",          // required by SemanticDB compiler plugin
+    "-Ywarn-unused-import" // required by `RemoveUnused` rule
   )
 )

https://scalacenter.github.io/scalafix/docs/users/installation.html#sbt

Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

LGTM 👍 thank you!

I apologize the late response, if you're blocked by review in other PRs maybe @mlachkar can help?

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.

Scala fix fails to run on test
4 participants