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

Relative path for compiler plugin while using sbt >= 1.4.0 breaks compilation. #1421

Closed
ckipp01 opened this issue Dec 3, 2020 · 10 comments · Fixed by #2485
Closed

Relative path for compiler plugin while using sbt >= 1.4.0 breaks compilation. #1421

ckipp01 opened this issue Dec 3, 2020 · 10 comments · Fixed by #2485
Labels
bug A defect or misbehaviour. install sbt

Comments

@ckipp01
Copy link
Member

ckipp01 commented Dec 3, 2020

I've noticed that when using sbt >= 1.4.0 and sbt-bloop, there is a difference in how a compiler plugin is listed under project.scala.options in the bloop json file. We'll use wart remover as an example. When using sbt 1.3.13 and wart remover the path to the plugin is absolute and pointing towards my coursier cache. However, in sbt >= 1.4.0 it's a relative path to /target/compiler_plugins/<plugin>. For example using 1.3.13

"project": {
  "scala": {
    "options": [
      "-Xplugin:/Users/ckipp/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/wartremover/wartremover_2.13.3/2.4.13/wartremover_2.13.3-2.4.13.jar"
    ]
  }
}

Using >= 1.4.0

"project": {
  "scala": {
    "options": [
      "-Xplugin:target/compiler_plugins/wartremover_2.13.3-2.4.13.jar",
    ]
  }
}

This causes issues when compiling:

❯ bloop compile (bloop projects)
Compiling wart-remover-bloop (1 Scala source)
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.Var
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.TryPartial
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.TraversableOps
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.Throw
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.StringPlusAny
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.Serializable
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.Return
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.Product
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.OptionPartial
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.Null
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.NonUnitStatements
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.IsInstanceOf
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.EitherProjectionPartial
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.DefaultArguments
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.AsInstanceOf
[E] [E-1] bad option: -P:wartremover:traverser:org.wartremover.warts.Any
Compiled wart-remover-bloop (92ms)
[E] Failed to compile 'wart-remover-bloop-test','wart-remover-bloop'

If the path is changed to an absolute path pointing in the target directory, then there is no problem. I'm unsure if that path is given from sbt in this manner, if Bloop is in charge of getting it from sbt and making sure it's absolute, or even something else.

You can reproduce this by the following steps

  • Run g8 scala/hello-world.g8
  • Add in addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.13")
  • Add in addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.5-8-6cc6911d")
  • Run sbt bloopInstall
  • Run bloop compile $(bloop projects)
@tgodzik
Copy link
Contributor

tgodzik commented Dec 3, 2020

Thanks for finding this! I will need to take a look at this soon.

@tgodzik
Copy link
Contributor

tgodzik commented Dec 3, 2020

Is this the reason for scalameta/metals#2279 ?

@ckipp01
Copy link
Member Author

ckipp01 commented Dec 3, 2020

Is this the reason for scalameta/metals#2279 ?

I don't believe so. I still don't know what's going on there. When I compare the json files for 1.4.2 and 1.4.3 all of the sbt source jars are missing. However, when I checked they were published, so I have no idea why as of 1.4.3 the sources aren't getting included.

@ckipp01
Copy link
Member Author

ckipp01 commented Dec 3, 2020

So it looks like this may be wart remover specific. This commit is the one that seems to have caused it wartremover/wartremover@fadeadc since they needed to go away from the absolute path in relation to this sbt/sbt#6027.

@tgodzik
Copy link
Contributor

tgodzik commented Dec 3, 2020

Is that relative path relative to the workspace? Maybe we could detect if a path is relative and try to do workspace.resolve(path) ?

@tgodzik
Copy link
Contributor

tgodzik commented Dec 3, 2020

We already do something similar here: https://github.com/scalacenter/bloop/blob/master/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala#L616

We could see if an option starts with -Xplugin: but doesn't follow with / and then try to use the working dir to find the absolute path.

@sjrd
Copy link
Contributor

sjrd commented Dec 3, 2020

but doesn't follow with /

Because of Windows and its C:\ or C:/

@tgodzik
Copy link
Contributor

tgodzik commented Dec 4, 2020

but doesn't follow with /

Because of Windows and its C:\ or C:/

Right, thanks @sjrd ! As always I forgot about windows 😓

@pavelfatin
Copy link

@tgodzik tgodzik added bug A defect or misbehaviour. install sbt labels Dec 30, 2020
tgodzik added a commit to tgodzik/bloop that referenced this issue Oct 25, 2024
Otherwise this doesn't work, looks like Bloop and sbt's working dir have a mismatch?

Fixes scalacenter#1421 finally
tgodzik added a commit to tgodzik/bloop that referenced this issue Oct 25, 2024
Otherwise this doesn't work, looks like Bloop and sbt's working dir have a mismatch?

Fixes scalacenter#1421 finally
@andyczerwonka
Copy link

I forgot about windows

I do that 4x a day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A defect or misbehaviour. install sbt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants