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

Let Starlark executable rules specify their environment #15232

Closed
wants to merge 2 commits into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Apr 13, 2022

The new RunEnvironmentInfo provider allows any executable or test
Starlark rule to specify the environment for when it is executed, either
as part of a test action or via the run command.

Refactors testing.TestEnvironment to construct a RunEnvironmentInfo and
adds a warning (but not an error) if the provider constructed in this
way is returned from a non-executable non-test rule. If a
RunEnvironmentInfo is constructed directly via the Starlark constructor,
this warning becomes an error.

Fixes #7364
Fixes #15224
Fixes #15225

@fmeum fmeum requested a review from lberki as a code owner April 13, 2022 10:32
@fmeum fmeum force-pushed the run-environment-info branch 2 times, most recently from 8f48123 to 2b981c0 Compare April 13, 2022 11:20
@fmeum
Copy link
Collaborator Author

fmeum commented Apr 13, 2022

@comius Alternative names I considered are EnvironmentInfo (which I like better than RunEnvironmentInfo, but may be too generic) or ExecutionEnvironmentInfo. What do you think?

@fmeum fmeum force-pushed the run-environment-info branch 2 times, most recently from 5480d51 to 61a9f58 Compare April 13, 2022 12:08
@lberki lberki requested review from comius and removed request for lberki April 13, 2022 12:26
@lberki
Copy link
Contributor

lberki commented Apr 13, 2022

Ivo, are you the right person for this or is it @brandjon ?

@fmeum fmeum changed the title Let Starlark rules specify their environment via RunEnvironmentInfo Let Starlark executable rules specify their environment Apr 13, 2022
@comius comius self-assigned this Apr 13, 2022
@comius
Copy link
Contributor

comius commented Apr 13, 2022

Ivo, are you the right person for this or is it @brandjon ?

I've reviewed the TestEnvInfo already, so it seems I'm the right person.

@rickeylev
Copy link
Contributor

I'm interested in using this functionality, so I reviewed what I could. I'm not too familiar with apis, so my review wasn't very deep.

fmeum added 2 commits May 4, 2022 08:27
The new RunEnvironmentInfo provider allows any executable or test
Starlark rule to specify the environment for when it is executed, either
as part of a test action or via the run command.

Refactors testing.TestEnvironment to construct a RunEnvironmentInfo and
adds a warning (but not an error) if the provider constructed in this
way is returned from a non-executable non-test rule. If a
RunEnvironmentInfo is constructed directly via the Starlark constructor,
this warning becomes an error.
@fmeum
Copy link
Collaborator Author

fmeum commented May 4, 2022

I'm interested in using this functionality, so I reviewed what I could. I'm not too familiar with apis, so my review wasn't very deep.

Thanks for the comments @rickeylev, I pushed a new commit to address them (and resolved the merge conflicts).

@rickeylev
Copy link
Contributor

LGTM.

@comius can you review?

@sgowroji sgowroji added the awaiting-review PR is awaiting review from an assigned reviewer label May 5, 2022
@bazel-io bazel-io closed this in 1e40541 May 12, 2022
@fmeum fmeum deleted the run-environment-info branch May 12, 2022 09:37
@fmeum
Copy link
Collaborator Author

fmeum commented May 12, 2022

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label May 12, 2022
@ckolli5
Copy link

ckolli5 commented Jun 17, 2022

@bazel-io fork 5.3.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Jun 17, 2022
@ckolli5
Copy link

ckolli5 commented Jun 29, 2022

Hello @fmeum, I cherry-picked these changes and raised a PR against release-5.3.0 branch. Presubmit checks are failing in that PR. Could you please cherry picked with appropriate commits and raise a PR against release-5.3.0? Thanks!

fmeum added a commit to fmeum/bazel that referenced this pull request Jun 29, 2022
The new RunEnvironmentInfo provider allows any executable or test
Starlark rule to specify the environment for when it is executed, either
as part of a test action or via the run command.

Refactors testing.TestEnvironment to construct a RunEnvironmentInfo and
adds a warning (but not an error) if the provider constructed in this
way is returned from a non-executable non-test rule. If a
RunEnvironmentInfo is constructed directly via the Starlark constructor,
this warning becomes an error.

Fixes bazelbuild#7364
Fixes bazelbuild#15224
Fixes bazelbuild#15225

Closes bazelbuild#15232.

PiperOrigin-RevId: 448185352
@fmeum
Copy link
Collaborator Author

fmeum commented Jun 29, 2022

@ckolli5 I created #15766 with the additional required cherry-picks.

ckolli5 pushed a commit that referenced this pull request Jun 29, 2022
* Specify fixedEnv/inheritedEnv interaction in ActionEnvironment

Previously, ActionEnvironment did not publicly document how fixed and
inherited environment variables interact, but still cautioned users to
keep the two sets disjoint without enforcing this. As a result, neither
could users rely on the interaction nor could ActionEnvironment benefit
from the additional freedom of not specifying the behavior.

With this commit, ActionEnvironment explicitly specifies that the values
of environment variable inherited from the client environment take
precedence over fixed values and codifies this behavior in a test.
This has been the effective behavior all along and has the advantage
that users can provide overrideable defaults for environment variables.

Closes #15170.

PiperOrigin-RevId: 439315634

* Intern trivial ActionEnvironment and EnvironmentVariables instances

When an ActionEnvironment is constructed out of an existing one, the
ActionEnvironment and EnvironmentVariables instances, which are
immutable, can be reused if no variables are added.

Also renames addVariables and addFixedVariables to better reflect that
they are operating on an immutable type.

Closes #15171.

PiperOrigin-RevId: 440312159

* Let Starlark executable rules specify their environment

The new RunEnvironmentInfo provider allows any executable or test
Starlark rule to specify the environment for when it is executed, either
as part of a test action or via the run command.

Refactors testing.TestEnvironment to construct a RunEnvironmentInfo and
adds a warning (but not an error) if the provider constructed in this
way is returned from a non-executable non-test rule. If a
RunEnvironmentInfo is constructed directly via the Starlark constructor,
this warning becomes an error.

Fixes #7364
Fixes #15224
Fixes #15225

Closes #15232.

PiperOrigin-RevId: 448185352

* Fix strict deps violation

```
src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java:990: error: [strict] Using type com.google.devtools.build.lib.cmdline.LabelValidator from an indirect dependency (TOOL_INFO: "//src/main/java/com/google/devtools/build/lib/cmdline:LabelValidator"). See command below **
      LabelValidator.parseAbsoluteLabel(labelString);
      ^
```
@ShreeM01 ShreeM01 removed the awaiting-review PR is awaiting review from an assigned reviewer label Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants