bazelbuild / bazelbuild/bazel

Provide Starlark analogue to "rlocationpath" Make variable for rule authors to use

Open
#17,259 10 comments 5 reactions 0 assignees View on GitHub
P3 type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the feature request:

Per [discussion in the "rules" channel](https://bazelbuild.slack.com/archives/CDCMRLS23/p1674078669014879) of the "Bazel" Slack workspace, at present we have [the `rlocationpath` "Make" variable](https://bazel.build/reference/be/make-variables) available for use in target definitions, but we have no analogous Starlark function available to rule authors. It would be helpful to provide either a Starlark function that accepts a `File` or add a method to `File` that returns the equivalent string value as the `rlocationpath` "Make" variable, such that one could feed that value into a runfiles library's `Rlocation` function to find a particular runfile.

### What underlying problem are you trying to solve with this feature?

While writing a rule that externalizes command-line flags or arguments supplied to an action created by `ctx.actions.run` or `ctx.actions.run_shell`, I'd like to supply values that nominate runfiles, such that the program that runs within that action can use a runfiles library to project those command-line flag values to the proper paths, allowing it to read the nominated files.

### Which operating system are you running Bazel on?

macOS 13.1

### What is the output of `bazel info release`?

release 6.0.0

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?

_No response_

### Have you found anything relevant by searching the web?

I have searched the Web extensively looking for advice on how to use the nascent runfiles libraries. @fmeum's ["Runfiles and where to find them" video on YouTube](https://www.youtube.com/watch?v=5NbgUMH1OGo) helps understand how to _consume_ these paths. Not addressed commonly, though, is how one _creates_ these paths.

### Any other information, logs, or outputs that you want to share?

@fmeum [mentioned](https://bazelbuild.slack.com/archives/CDCMRLS23/p1674111770913389?thread_ts=1674078669.014879&cid=CDCMRLS23) his [`runfile_path` Starlark function](https://github.com/bazelbuild/rules_fuzzing/blob/22a866a3c98f374ab3284a7d26fc8318c17a711c/fuzzing/private/util.bzl#L39-L42) in the _bazelbuild/rules\_fuzzing_ repository as a potential implementation that emulates `rlocationpath` well enough.

Contributor guide

Open the contributing guide

Research direction

Start with the documented rlocationpath Make variable and the rules_fuzzing runfile_path Starlark function linked in the issue. Review how rule authors use File values with ctx.actions.run and ctx.actions.run_shell, and how runfiles libraries consume Rlocation inputs. Done means rule authors can obtain an equivalent runfile path for an action argument.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.