Referring to a dependency module from rlocation in shell scripts

4 views
Skip to first unread message

Filip Filmar

unread,
5:52 PM (2 hours ago) 5:52 PM
to bazel-discuss

Hi folks.

How does one robustly refer to another repository when using rlocation in bash scripts?

Consider this example:

readonly _run_this="$(rlocation runfiles~/binary)"

this shell snippet refers to the location of the target called binary in a dep repo called @runfiles.

How does one do this in a robust way? To wit the “apparent” name runfiles~ is an implementation detail of bazel 7.x. If I upgrade to bazel 8.x, this will become an error as the "correct" name is now `runfiles+`.

Where this becomes a problem, is when we don’t know what bazel version will be used to compile this code. Ostensibly, both 7.x and 8.x should work. But in this case, the script becomes brittle, as one would expect given that it's relying on an implementation detail to resolve rlocation. I usually solve this in my code by pinning the bazel version. But this might not be an option when offering a module to an unknown user.

What’s the canonical solution to this? Resolving the current repository is handled using the runfiles_current_repository function. What about “non-current” repository?

F

Reply all
Reply to author
Forward
0 new messages