Skip to content
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

docs: clarify rlocationpath #430

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions docs/paths.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions lib/private/paths.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,31 @@ def _to_output_relative_path(file):
def _to_rlocation_path(ctx, file):
"""The rlocation path for a `File`

The path a built binary can pass to the `Rlocation` function of a runfiles library to find a
dependency at runtime, either in the runfiles directory (if available) or using the runfiles
manifest.
This produces the same value as the `rlocationpath` predefined source/output path variable.

This is similar to root path (a.k.a. [short_path](https://bazel.build/rules/lib/File#short_path))
in that it does not contain configuration prefixes, but differs in that it always starts with the
name of the repository.
From https://bazel.build/reference/be/make-variables#predefined_genrule_variables:

The rlocation path of a `File` in an external repository repo will start with `repo/`, followed by the
repository-relative path.
> `rlocationpath`: The path a built binary can pass to the `Rlocation` function of a runfiles
> library to find a dependency at runtime, either in the runfiles directory (if available)
> or using the runfiles manifest.

Passing this path to a binary and resolving it to a file system path using the runfiles libraries
is the preferred approach to find dependencies at runtime. Compared to root path, it has the
advantage that it works on all platforms and even if the runfiles directory is not available.
> This is similar to root path (a.k.a. [short_path](https://bazel.build/rules/lib/File#short_path))
> in that it does not contain configuration prefixes, but differs in that it always starts with the
> name of the repository.

Based on the $(rlocation) predefined source/output path variable:
https://bazel.build/reference/be/make-variables#predefined_genrule_variables.
> The rlocation path of a `File` in an external repository repo will start with `repo/`, followed by the
> repository-relative path.

> Passing this path to a binary and resolving it to a file system path using the runfiles libraries
> is the preferred approach to find dependencies at runtime. Compared to root path, it has the
> advantage that it works on all platforms and even if the runfiles directory is not available.

Args:
ctx: starlark rule execution context
file: a `File` object

Returns:
The rlocation path for the `File`
The rlocationpath for the `File`
"""
if file.short_path.startswith("../"):
return file.short_path[3:]
Expand Down