bazelbuild / bazelbuild/bazel

Add "runfile_path" to File

Open
#14,307 19 comments 3 reactions 0 assignees View on GitHub
P2 team-Rules-API type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the problem / feature request:

Add `runfile_path` property to `File` object.

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

Runfiles are identified by path including their workspace.

`short_path` is the location of the file relative to the current working directory, when the executable is run under Bazel.

However, that doesn't work if the executable is run outside of Bazel. For that, the file must be found in the runfiles manifest, or the runfiles symlink tree. However, neither of these use the same root as the cwd. Namely, the cwd directory is $runfiles/$workspace_name.

So path manipulation is required. And it requires `ctx.workspace_name()` which isn't available in `Args.add_all()` `map_each`.

Ideally, I could simply use `runfile_path` and get the path to use in runfile lookup/rlocation.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the File object and the Args.add_all() map_each API, then inspect how runfiles manifests and the symlink tree represent workspace-relative paths. Done means File exposes a runfile_path that can be used for runfile lookup outside Bazel without requiring ctx.workspace_name().

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.