-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add arguments
parameter to RunEnvironmentInfo
#16430
base: master
Are you sure you want to change the base?
Conversation
d747d2e
to
f8bd861
Compare
Executable Starlark rules can use the new `arguments` parameter on `RunEnvironmentInfo` to specify the arguments that Bazel should pass on the command line with `test` or `run`. If set to a non-`None` value, this parameter overrides the value of the `args` attribute that is implicitly defined for all rules. This allows Starlark rules to implement their own version of this attribute which isn't bound to its proprietary processing (data label expansion and tokenization). Along the way, this commit adds test coverage and documentation for the interplay between `RunEnvironmentInfo`'s `environment` and `--test_env`. The value of the `arguments` field of `RunEnvironmentInfo` is intentionally not exposed to Starlark yet: It is not clear how these arguments should be represented and whether rules relying on the magic `args` attribute should also provide this field. RELNOTES: Executable starlark rules can use the `arguments` parameter of `RunEnvironmentInfo` to specify their command-line arguments with `bazel run` and `bazel test`.
@comius Would you be available to review this PR? |
arguments
parameter to RunEnvironmentInfo
arguments
parameter to RunEnvironmentInfo
Adding @comius since he reviewed #15232 . @comius : do I understand correctly that Then it's kind of odd that it's added to the set of providers the rule makes accessible to rules that depend on it; it seems unnecessary and it's Yet Another Little Thing on the interface of Bazel. I suppose we can't remove it anymore without an incompatible flag? :( |
@lberki I should add that advertising I do agree that this extends the interface, but maybe that extension isn't unnecessary :-) |
If it was a conscious choice (as opposed to just a side effect of whatever the most convenient choice was at that time), all the power to y'all! I didn't do a lot of archeology, just noticed this odd provider and thought I'd flag it. |
@comius sorry for the ping. Would you happen to have bandwidth this week to review this PR? |
I don't think this is the direction we should be following. Adding a way to customise args attribute will result in "proprietary processing" invented by each rule author for their rules - or copy-pasting the code around that does it. I'd rather pursue the direction where the Can you close this PR and rather introduce a flag and optional allow list, that fixes the Are there other arguments for customization? Otherwise, I really don't want users to figure out on which rules args work and on which rules they don't. |
Can you expand on what you mean by "flag and optional allow list"?
My use case for this functionality is to be able to write tests rules with unique attributes that are translated to arguments to a test binary. |
Flag like Optional allow list, something in the spirit of 67d3bca
Why can't this be done with a macro? If I understand you correctly, you want to translate "unique attributes to arguments". Isn't that:
? |
Some arguments accept paths to files which some users would expect to be able to pass a label to. The macro would not work with select statements which is something I need on a number of my rules. |
You mean something like this?
|
I don't think you can pass selects to expansions like that. Is there evidence of that working? Additionally, there may be things only knowable within a rule (like whether or not coverage is enabled) that would also need to be translated into an arugment. |
This also doesn't seem like it'd support having lists of files expanded into |
I also have cases where I have a custom set of |
No, it's not working. What you can do if you need a case like this, is pass dict, and then wrap it into a
You can implement expansion like that in a macro.
But it's completely doable with a second rule. You can pass foo_* to that rule as a label. Access the providers. And also execute it using If the usability is problematic, you can wrap 2 rules together into a macro, to achieve the appearance of a single rule. |
Something being “doable” I don’t think is reason enough to reject improvements. I’ve proven what I want is doable since have the functionality I want. But I continue to see other developers attempt to solve for the same gap in functionality in different ways which leads to very hard to maintain projects. I have other examples of this but feel sharing them won’t change the outcome of the PR so I respectfully express my disagreement with the decision to reject this PR and leave the rest to you and @fmeum |
I disagree this is a gap in functionality. Args tokenization is a tech-debt loaded code. This PR seems to provide users to implement workarounds over it. The solution should be a more principle one and accepting the PR could make that harder if not even impossible. |
I don't think the main purpose of this PR is to fix arguments tokenisation. At least the reasons I want it are not for this, but rather mirror the use cases that @UebelAndre provided. |
Can I introduce another motivation for something like this PR, and run it past you @comius? I currently have a private ruleset which generates a shell script per test target, string-formatting in some paths and other strings from its attributes. There are two major problems with this:
I think if this PR were modified to accept WDYT @comius? |
@comius can I nudge you at ^^? |
RunfilesSupport.withExecutable(ruleContext, computedDefaultRunfiles, executable); | ||
if (starlarkArgsProvided) { | ||
runfilesSupport = RunfilesSupport.withExecutableNoArgs( | ||
ruleContext, computedDefaultRunfiles, executable); |
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.
What is the argument against creating a RunfilesSupport.withExecutableAndArgs()
method that overrides the argv computed from the attributes of the rule? That looks simpler than plumbing another set of arguments to RunCommand
/ TestActionBuilder
and carefully making sure that the one in RunEnvironmentInfo
overrides the one in RunfilesSupport
.
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.
@fmeum ^^
In the absence of @comius I did my best. |
@illicitonion I wonder whether your use case would be better served by a Starlark def string_args():
args = []
def add(o):
if type(o) == "File":
args.append(o.path)
else:
args.append(str(o))
def build():
return list(args)
return struct(
add = add,
build = build,
) Keeping |
I proposed a plan on #12313 and want to at least dedicate some time to making progress on it before pursuing making arguments configurable from rule implementation functions. I do share @comius concern that my PR could end up making |
If I'm understanding this right, I think this is basically equivalent to giving If so, then yeah, the two pieces of:
works for my use-case. |
I'll let @lberki handle this. |
Executable Starlark rules can use the new
arguments
parameter onRunEnvironmentInfo
to specify the arguments that Bazel should pass on the command line withtest
orrun
.If set to a non-
None
value, this parameter overrides the value of theargs
attribute that is implicitly defined for all rules. This allows Starlark rules to implement their own version of this attribute which isn't bound to its proprietary processing (data label expansion and tokenization).Along the way, this commit adds test coverage and documentation for the interplay between
RunEnvironmentInfo
'senvironment
and--test_env
.The value of the
arguments
field ofRunEnvironmentInfo
is intentionally not exposed to Starlark yet: It is not clear how these arguments should be represented and whether rules relying on the magicargs
attribute should also provide this field.RELNOTES: Executable starlark rules can use the
arguments
parameter ofRunEnvironmentInfo
to specify their command-line arguments withbazel run
andbazel test
.Fixes #16076
Work towards #12313