Skip to content

Use ::: as scalacopts delimiter #1053

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

Merged
merged 13 commits into from
Jun 8, 2020

Conversation

wisechengyi
Copy link
Contributor

@wisechengyi wisechengyi commented Jun 2, 2020

Description

As suggested in #1049, using ::: as the delimiter instead of , to separate scalac options, in order to avoid collision with ,.

Motivation

Per scalac doc https://docs.scala-lang.org/overviews/compiler-options/index.html: there could be options like -Ywarn-unused:WARNING1,WARNING2

For example before this change, if

scalaopts = ['-Ywarn-unused:-implicits,-locals,-explicits,-patvars,-privates']

the build would fail with

scalac error: bad option: '-locals'
  scalac -help  gives more information
one error found
java.lang.RuntimeException: Build failed
	at io.bazel.rulesscala.scalac.ScalacProcessor.compileScalaSources(ScalacProcessor.java:256)
	at io.bazel.rulesscala.scalac.ScalacProcessor.processRequest(ScalacProcessor.java:76)
	at io.bazel.rulesscala.worker.GenericWorker.runPersistentWorker(GenericWorker.java:45)
	at io.bazel.rulesscala.worker.GenericWorker.run(GenericWorker.java:111)
	at io.bazel.rulesscala.scalac.ScalaCInvoker.main(ScalaCInvoker.java:41)

@wisechengyi wisechengyi requested a review from ittaiz as a code owner June 2, 2020 22:54
@wisechengyi wisechengyi changed the title Scalacopts delimiter Use ::: as scalacopts delimiter Jun 2, 2020
Copy link
Contributor

@ittaiz ittaiz left a comment

Choose a reason for hiding this comment

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

Thanks!
I’m not sure I understand how the current test guards us from regression.
I understand previously it would have broke rules_scala but I don’t see how the added test demonstrates the support of this attribute.

@wisechengyi
Copy link
Contributor Author

@ittaiz sorry just saw the message in the slack.

Just added

  1. test/scalacopts, so will be covered by bazel build test/...
  2. unit test on option parsing: src/java/io/bazel/rulesscala/scalac/CompileOptionsTest.java

Let me know if further adjustment is needed. Thanks!

@ittaiz
Copy link
Contributor

ittaiz commented Jun 5, 2020

ok, I think the current test indeed guards us but IMHO in a mechanical white box way.
I think a more semantic test could both help regression and demonstrate the feature set more.
For example we could add a target that has `scalacopts = [ "-language:implicitConversions, postfixOps", -language:higherKinds, -Xfatal-warnings]" and I'd have the scala file of that target use these three features. I've added the fatal-warnings since I think (not sure) that you can use them right now without the flags but they will generate a warning so the fatal makes sure that they're actually used.

I'd be happy to push a commit to this PR with the test if the above isn't clear.

Btw,
We can also do an integration test by having a scala file with warnings, use your examples to turn on these warnings and use again fatal-warnings. then the integration test asserts the build fails.
I think the first option is simpler and faster (unit tests are cached) but just wanted to give it for completeness. Both check actual feature.

@wisechengyi
Copy link
Contributor Author

wisechengyi commented Jun 5, 2020

Thanks! Makes sense. My initial plan was to introduce an unused import in the code then use scalacopts to fail on unused import, which aligns with what you suggested, but ran into backwards incompatibility issue with 2.11.

Let me see if I can somehow only test this with 2.12 via test_versions.sh

@ittaiz
Copy link
Contributor

ittaiz commented Jun 5, 2020

If you fail on an unused import then this needs to be an external shell integration test (otherwise the build won’t pass).

If you hit a wall with my offer LMK and I’ll help. You can even push a half baked commit.

Re integration tests- There is work in the bazel space to allow such integration tests to be part of the bazel build.
I have an OSS library (bazel integration testing) which does this but it’s not trivial to use and has its costs. There is a chance that whatever will come from bazel will be easier.

Comment on lines +10 to +13
import c.universe._
// c.settings are the values from scalac's -Xmacro-settings
val s = c.settings.mkString(",")
c.Expr(q"""${s}""")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here is the relevant part using scalac options

Copy link
Contributor

@ittaiz ittaiz left a comment

Choose a reason for hiding this comment

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

Thanks!
I think we’re really close

Copy link
Contributor

@ittaiz ittaiz left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!
Will merge once green.

@ittaiz ittaiz merged commit fb6e0f0 into bazel-contrib:master Jun 8, 2020
SocksDevil pushed a commit to SocksDevil/rules_scala that referenced this pull request Jul 6, 2020
* initial

* polish

* lint

* one more

* remove integ test

* add unit test

* add tests that uses scalacopts

* minor

* comment

* accumlative macro options

* rm tests

* more clear options
@wisechengyi wisechengyi deleted the scalacopts_delimiter branch October 13, 2021 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants