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

Added run_under_env argument to RunEnvironmentInfo #16540

Closed
wants to merge 1 commit into from

Conversation

UebelAndre
Copy link
Contributor

@UebelAndre UebelAndre commented Oct 24, 2022

Executable Starlark rules can use the run_under_env parameter of RunEnvironmentInfo to define an environment variable with the value of --run_under when it's set. This is useful in cases where executable targets execute some sort of process-wrapper which either sub-processes or execs into the expected process. Before, --run_under would happen on the process wrapper which made debuggers and profiling tools harder to use as the process they were attached to was not the process users cared about.

After this change, by having an executable Starlark rule return RunEnvironmentInfo(run_under_env = "RUN_UNDER_VALUE"), run or test invocations which pass --run_under='strace -c' will cause the executable to have RUN_UNDER_VALUE='strace -c' set in it's environment.

RELNOTES: Executable Starlark rules can use the run_under_env parameter of RunEnvironmentInfo to define an environment variable with the value of --run_under when it's set. This allows Starlark rule authors to control how this value is used.

closes #16232

@UebelAndre
Copy link
Contributor Author

Some open questions for this draft:

  • How are integration tests written for Bazel?
  • Should the value set to run_under_env include the shell executable?

@fmeum
Copy link
Collaborator

fmeum commented Oct 24, 2022

  • How are integration tests written for Bazel?

Given that the existing RunEnvironmentInfo tests are in

function test_starlark_rule_with_run_environment() {
, you should probably add shell tests there.

  • Should the value set to run_under_env include the shell executable?

That is a good question I don't have a good answer to - I yet have to use --run_under in a non-trivial way. Do Starlark rules have access to the shell toolchain?

@UebelAndre
Copy link
Contributor Author

Do Starlark rules have access to the shell toolchain?

I don't think so. I'm not aware of shell_toolchain being something that exists. I think if I could get an integration test it might lead to an answer here.

@@ -61,6 +63,15 @@ public interface RunEnvironmentInfoApi extends StructApi {
structField = true)
List<String> getInheritedEnvironment();

// @StarlarkMethod(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fmeum I noticed you did not have a change like like this for arugments in your PR. Was that intentional? Is this needed?

Copy link
Collaborator

@fmeum fmeum Oct 24, 2022

Choose a reason for hiding this comment

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

That was intentional: Adding such a method/struct field would give Starlark rules access to this information in the provider. I wasn't sure whether arguments is something that other rules should be able to inspect, so I decided not to expose it for now.

Do you see a reason for depending rules to access the value of run_under_env? If there is no clear use case, it may be better not to expose it for now. API creep is real and incompatible changes removing functionality are painful.

Note that depending rules can always just forward the provider unchanged, so not exposing this doesn't prevent e.g. transition wrappers.

@UebelAndre UebelAndre requested a review from fmeum October 26, 2022 01:45
@UebelAndre UebelAndre marked this pull request as ready for review October 26, 2022 01:45
@UebelAndre
Copy link
Contributor Author

@fmeum with the first passing build (which took quite a bit of time and effort), I think it's worth a thorough review. Would you be willing to take another look?

@sgowroji sgowroji added team-Build-Language awaiting-review PR is awaiting review from an assigned reviewer labels Oct 26, 2022
src/test/shell/bazel/bazel_rules_test.sh Outdated Show resolved Hide resolved
src/test/shell/bazel/bazel_rules_test.sh Outdated Show resolved Hide resolved
src/test/shell/bazel/bazel_rules_test.sh Outdated Show resolved Hide resolved
src/test/shell/bazel/bazel_rules_test.sh Show resolved Hide resolved
src/test/shell/bazel/bazel_rules_test.sh Outdated Show resolved Hide resolved
@fmeum
Copy link
Collaborator

fmeum commented Oct 26, 2022

Looks very good now, thanks for investing the time!

Given that he also reviewed the other RunEnvironmentInfo PRs, @comius would likely be in the best position to review this PR.

@UebelAndre UebelAndre requested review from fmeum and removed request for lberki October 26, 2022 16:11
@UebelAndre
Copy link
Contributor Author

@fmeum I think I've addressed all the feedback and the PR is ready for another review.

Copy link
Collaborator

@fmeum fmeum 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, nothing to add :-)

This still has to be reviewed and imported by a Googler though.

@UebelAndre UebelAndre mentioned this pull request Oct 26, 2022
9 tasks
@UebelAndre UebelAndre changed the title Added run_under_env argument to RunEnvironmentInfo Added run_under_env argument to RunEnvironmentInfo Oct 26, 2022
@comius comius self-requested a review October 26, 2022 19:04
@UebelAndre
Copy link
Contributor Author

@comius Hello again, would you have time this week to review this as well? 😅

@brandjon brandjon added team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts and removed team-Build-Language labels Nov 5, 2022
@UebelAndre
Copy link
Contributor Author

I don't have time to do a rebase which is sad because I think these changes would be really good. Closing so the changes don't appear to be in work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review PR is awaiting review from an assigned reviewer team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow starlark rules to pass --run_under to executables
5 participants