-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use of ctx.info_file and ctx.version_file in rule implementations #13360
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
Comments
Where are |
+1 to documenting these. |
Clarification for future readers: the problem is that the content of |
We can't read file content prior to execution. But perhaps workspace status information can be (or is currently?) exposed in some alternate API. |
See also #13300 requesting better documentation for reading files in Starlark. |
Assigning to @buildbreaker2021, who's currently working on this functionality, to review if there's need to update documentation and/or if this issue can be resolved. |
There is an API already implemented(although private still) which will support use-cases like these. bazel/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkActionFactoryApi.java Lines 849 to 926 in 8828015
|
Is there a way today to access, e.g. |
Is this how we are supposed to consume it? def _impl(ctx):
script = ctx.actions.declare_file(ctx.label.name + ".upload.sh")
script_content = """#!/bin/bash
STABLE_GIT_COMMIT=$(grep "^STABLE_GIT_COMMIT " "{info_file}" | cut -d ' ' -f 2)
echo $STABLE_GIT_COMMIT > $1
""".format(
info_file = ctx.info_file.path,
)
ctx.actions.write(
output = script,
content = script_content,
is_executable = True,
)
result = ctx.actions.declare_file(ctx.label.name + ".output")
ctx.actions.run(
inputs = [ctx.info_file],
outputs = [result],
executable = script,
arguments = [result.path],
use_default_shell_env = True,
)
return [DefaultInfo(
files = depset([result]),
runfiles = ctx.runfiles(files = [result]),
)]
access_fileinfo = rule(
implementation = _impl,
) |
Description of the problem / feature request:
At the moment information in ctx.info_file and ctx.version_file cannot be used for rule implementation.
Feature requests: what underlying problem are you trying to solve with this feature?
See for instance bazel-contrib/rules_python#451. Therein, I would like to use git info, routed via workspace status script, to make an output file name of a Python wheel. Since I cannot read a file from context, at the moment I process ctx.info_file and ctx.version_file in a separate Python script and then dump a wheel version to a .txt file. The new py_wheel_push rule in that PR consumes my .txt file and then assembles the correct file name. However, it is desirable that py_wheel rule already assembles the correct wheel name, which at the moment is not possible if I want to use info from workspace status -- e.g. a wheel version in py_wheel rule as
version = "{FOO}"
, where I expect FOO to be picked up from the workspace status.Are there any plans to enable use of the workspace status in rule implementations?
What operating system are you running Bazel on?
Ubuntu 18.04
What's the output of
bazel info release
?release 2.0.0
Have you found anything relevant by searching the web?
The only thing I could find is that Bazel context cannot read files, and that's for good reasons as far as I understand.
The text was updated successfully, but these errors were encountered: