-
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 tool executables (from FilesToRunProvider) to action inputs. #10110
Add tool executables (from FilesToRunProvider) to action inputs. #10110
Conversation
e986297
to
b4991d2
Compare
b4991d2
to
ca0e703
Compare
/cc @lberki I am not sure about the team label here |
Well, that's an interesting one. I didn't expect that we allow the creation of a Since we use
I think the best approach is to do something halfway between: do (1) for call sites from Java and (2) for call sites from Starlark. @laurentlb , WDYT? |
A similar situation happens with the presence of the executable in the runfiles. That case is handled with an implementation similar to what lberki suggests here. Broken native rules receive an |
New commit added to implement "Just silently add the executable to |
@@ -44,6 +44,9 @@ public FilesToRunProvider( | |||
NestedSet<Artifact> filesToRun, | |||
@Nullable RunfilesSupport runfilesSupport, | |||
@Nullable Artifact executable) { | |||
if (executable != null) { | |||
filesToRun = NestedSetBuilder.fromNestedSet(filesToRun).add(executable).build(); |
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.
This will create an extra NestedSet
instance for every call site, most importantly, in the constructor of FileConfiguredTarget
, which means an extra object for each input file, which is probably unacceptable overhead.
How about special-casing at least #fromSingleExecutableArtifact()
so that this overhead is not present?
Given that the only other call site is in RuleConfiguredTargetBuilder#build()
, I'd prefer putting logic there because, well, that place already has logic. In addition to being a personal preference, you also have more information, notably, ruleContext.getRule().getRuleClassObject().isSkylark()
, which you can use to determine whether this is a Starlark rule and thus adding the binary to the nested set is necessary.
Even better is changing SkylarkRuleConfiguredTargetUtil#addSimpleProviders()
-- that place has control over both the executable and
filesToBuildfields of
RuleConfiguredTargetBuilderand is specific to Starlark rules, so you can just add the "executable is forcibly added to
filesToRun`" logic there.
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.
Given that the only other call site is in
RuleConfiguredTargetBuilder#build()
, I'd prefer putting logic there because, well, that place already has logic.
Done.
Added a comment -- TL;DR: I think it's better to tweak What I'm slightly unhappy about is that you probably can't just assert whether the executable is in |
I've expanded |
Gentle ping @lberki |
@lberki As requested, here's your ping. :) Please let me know if I can import and cherry-pick this into Bazel 1.2.0. |
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.
I'm sorry for the delay. I've had a little too many issues that landed on my desk in the last few days.
Fixes #7390 Summary: rules are allowed to set `DefaultInfo(files = depset(), executable = ...)`. If the resulting targets are used as tool inputs to another target, the executable will not be added to the downstream targets' action inputs. This manifests as either an `execvp()` error (from `ctx.actions.run()`) or a Bash error in genrules. This PR fixes that so the use case of non-default executables works as expected. This is useful for building scripts with complex runfiles, where `bazel run //:something` and `bazel build //:something && bazel-bin/something` cannot be supported by the same output file. cc @ccate @jmmv Closes #10110. PiperOrigin-RevId: 280170524
Fixes #7390 Summary: rules are allowed to set `DefaultInfo(files = depset(), executable = ...)`. If the resulting targets are used as tool inputs to another target, the executable will not be added to the downstream targets' action inputs. This manifests as either an `execvp()` error (from `ctx.actions.run()`) or a Bash error in genrules. This PR fixes that so the use case of non-default executables works as expected. This is useful for building scripts with complex runfiles, where `bazel run //:something` and `bazel build //:something && bazel-bin/something` cannot be supported by the same output file. cc @ccate @jmmv Closes #10110. PiperOrigin-RevId: 280170524
Fixes #7390 Summary: rules are allowed to set `DefaultInfo(files = depset(), executable = ...)`. If the resulting targets are used as tool inputs to another target, the executable will not be added to the downstream targets' action inputs. This manifests as either an `execvp()` error (from `ctx.actions.run()`) or a Bash error in genrules. This PR fixes that so the use case of non-default executables works as expected. This is useful for building scripts with complex runfiles, where `bazel run //:something` and `bazel build //:something && bazel-bin/something` cannot be supported by the same output file. cc @ccate @jmmv Closes #10110. PiperOrigin-RevId: 280170524
Previously, tool runfiles were not present at execution time. For example, if the provided tool was a py_binary, the py_binary would fail to run due to the omission of the runfiles. This relates to bazelbuild/bazel#10110
Previously, tool runfiles were not present at execution time. For example, if the provided tool was a py_binary, the py_binary would fail to run due to the omission of the runfiles. This relates to bazelbuild/bazel#10110
Previously, tool runfiles were not present at execution time. For example, if the provided tool was a py_binary, the py_binary would fail to run due to the omission of the runfiles. This relates to bazelbuild/bazel#10110
Fixes #7390
Summary: rules are allowed to set
DefaultInfo(files = depset(), executable = ...)
. If the resulting targets are used as tool inputs to another target, the executable will not be added to the downstream targets' action inputs. This manifests as either anexecvp()
error (fromctx.actions.run()
) or a Bash error in genrules.This PR fixes that so the use case of non-default executables works as expected. This is useful for building scripts with complex runfiles, where
bazel run //:something
andbazel build //:something && bazel-bin/something
cannot be supported by the same output file.cc @ccate @jmmv