Open mvukov opened 3 years ago
Where are ctx.info_file
and ctx.version_file
in the Bazel docs?
Unfortunately, they are not documented. See https://github.com/bazelbuild/bazel/issues/9363 and https://github.com/bazelbuild/bazel/issues/11422. FWIW, I had to dig into rules_docker repo to learn how to access the workspace status.
+1 to documenting these.
Clarification for future readers: the problem is that the content of ctx.info_file
and version_file
cannot be used in a rule implementation.
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.
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 https://github.com/bazelbuild/rules_python/pull/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.