-
-
Notifications
You must be signed in to change notification settings - Fork 288
Expand $(location) and "Make variables" in env
#1771
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
Conversation
Implements the "values are subject to `$(location)` and "Make variable" substitution" contract for the common `env` attribute for binary and test rules. Fixes bazel-contrib#1770. --- Makes `env` attribute semantics for Scala binary and test targets conformant with those documented in the Bazel docs: - https://bazel.build/reference/be/common-definitions#common-attributes-binaries - https://bazel.build/reference/be/common-definitions#common-attributes-tests - https://bazel.build/reference/be/make-variables#use - https://bazel.build/rules/lib/providers/RunEnvironmentInfo Most of the new functions could live in a separate repository at some point. As for why we're using the "deprecated" `ctx.expand_make_variables`: - bazelbuild/bazel#5859 - bazelbuild/bazel-skylib#486 The "deprecated" comment in the `ctx.expand_make_variables` docstring has existed from the beginning of the file's existence (2018-05-11): - bazelbuild/bazel@abbb900
WojciechMazur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Updates `run_environment_info` to take a list of `attr.label_list` values directly instead of attribute names. This is less likely to silently fail, since a misspelled `ctx.attr` member will break the build.
|
@WojciechMazur Thanks for the quick turnaround. I've actually just pushed three small new changes; I'll merge once CI passes:
@WojciechMazur @simuons After this lands, I'll start a new version bump pull request. Once that lands, what do you think about pushing v7.2.0? (Or should it be v7.1.2, if we consider implementing this behavior a bugfix rather than a new feature?) |
This test helps clarify and codify the existing relationship between the `env` attribute, the `env_inherit` attribute, and the `--test_env` flag.
As it turns out, if Bazel is actually `bazel.exe`, then Bash _will not_ export its environment variables to the Bazel process on Windows. This means that `env_inherit` functionality will have no effect, breaking test_scala_test_env_attribute_with_env_inherit_and_test_env. In this case, we _must_ export them as Command Prompt variables. Setting `bazel_bin` in `setup_suite` and using it in `test_scala_binary_env_attribute_expansion` made that test case more portable as well.
83516c3 to
3bdbc35
Compare
Apparently our Windows build in continuous integration actually much prefers using `bazel` to `bazel.exe`: - https://buildkite.com/bazel/rules-scala-scala/builds/5785#019949dc-4cbb-4224-9d10-b7e0aacb5503/69-156 ```txt /c/b/bk-windows-dmg8/bazel/rules-scala-scala/test/shell/test_env_attribute_expansion.sh: line 26: /c/bazel/bazel /c/bazel/bazel.exe: No such file or directory /c/b/bk-windows-dmg8/bazel/rules-scala-scala/test/shell/test_env_attribute_expansion.sh: line 29: /c/bazel/bazel /c/bazel/bazel.exe: No such file or directory /c/b/bk-windows-dmg8/bazel/rules-scala-scala/tmp/test_env_attribute_expansion/expected.txt 2025-09-14 20:19:57.299728200 +0000 /c/b/bk-windows-dmg8/bazel/rules-scala-scala/tmp/test_env_attribute_expansion/actual.txt 2025-09-14 20:19:57.298429500 +0000 @@ -1,7 +0,0 @@ -LOCATION: West of House -DATA_PATH: test/data/foo.txt -DEP_PATH: test/HelloLib.jar -SRC_PATH: test/EnvAttributeBinary.scala -BINDIR: bazel-out/ -FROM_TOOLCHAIN_VAR: bazquux -ESCAPED: $(rootpath //test/data:foo.txt) $(BINDIR) $UNKNOWN ```
Wow, I was wrong about this being a Bazel bug on macOS. I ended up going on a bit of a journey to fix As for why I was wrong:
I have no idea why the Buildkite Windows environment uses |
Description
Implements the "values are subject to
$(location)and "Make variable" substitution" contract for the commonenvattribute for binary and test rules. Fixes #1770.Motivation
Makes
envattribute semantics for Scala binary and test targets conformant with those documented in the Bazel docs:Most of the new functions could live in a separate repository at some point.
As for why we're using the "deprecated"
ctx.expand_make_variables:expansion.bzlfor Fully Expanding Environment Variables bazelbuild/bazel-skylib#486The "deprecated" comment in the
ctx.expand_make_variablesdocstring has existed from the beginning of the file's existence (2018-05-11):