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

Pass environment variable to compiler #1023

Closed
saksmt opened this issue Mar 18, 2020 · 7 comments
Closed

Pass environment variable to compiler #1023

saksmt opened this issue Mar 18, 2020 · 7 comments

Comments

@saksmt
Copy link

saksmt commented Mar 18, 2020

I wasn't able to find a way to pass environment variable to compiler on build or test.
Neither --action_env has any effect, nor there is any parameter in scala_library/scala_binary/scala_test that can be used for that matter.

Motivation: there are some macros that are configured through environment variables which need to be set on compile time, specifically scalactic. Probably it should be fixed in scalactic itself, but with 3.1.x it seems easier to fix it in rules_scala than try to migrate from older versions and there may be other plugins with same behavior anyway.

As I could understand code in rules_scala it looks not so hard to fix (but I may be wrong since I'm not really familiar with the codebase) by just passing additional argument from scala_* (say named compiler_env all the way to invocation of compiler. As for --action_env it may even be better but I don't really know how it works and more specifically why it doesn't.

@ittaiz
Copy link
Member

ittaiz commented Mar 18, 2020 via email

@saksmt
Copy link
Author

saksmt commented Mar 18, 2020

Yeah it is constant in a way that it should not be changed between builds. It just controls macro expansion. Example of such macro and fix that will actually work with rules_scala: scalatest/scalatest#1795. So compiler options are essentially the same thing in this case.

@ittaiz
Copy link
Member

ittaiz commented Apr 11, 2020

We had this in our .bazelrc during the migration from maven to bazel and we could access it in our tests easily:

test --action_env=BUILD_TOOL=BAZEL

Could you try and see if you can access it?
You said it doesn't work for you for tests or compilation so I'm trying to see if maybe you're misusing the existing idiomatic mechanism. If we'll find it works for tests but not for the compiler env I think it will be easier to triage.

Also- please expect delays due to corona and limited capacity

@saksmt
Copy link
Author

saksmt commented Apr 15, 2020

It is not about time when tests are run, it is about time when tests are compiled. And currently there is no way of providing any env variable so that it would be visible by compiler

@ittaiz
Copy link
Member

ittaiz commented Apr 17, 2020

The line I gave you was an example. In bazel compilation and tests are both actions.
When you use --action_env=Key=Value you add this K/V to all actions the build is spawning (unless specific rules will explicitly provide an empty env var map).
As you can see we simply call ctx.actions.run in the link you provided originally which means we work with the bazel idioms.
Please try the above out to see if you can get it to work.
If not please open a PR with a repro

@ittaiz
Copy link
Member

ittaiz commented Apr 17, 2020

to be clear- AFAICT rules_scala is WAI.
A repro would help shed some light.

@ittaiz ittaiz closed this as completed Apr 24, 2020
@ittaiz
Copy link
Member

ittaiz commented Apr 24, 2020

Closing since it sounds this is a usage problem.
Please Reopen if you think otherwise.

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

No branches or pull requests

2 participants