Use $(location ) to set env var in .bazelrc
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### Description of the bug:
**Description of the bug:**
We'd like to set an environment variable (e.g. `--test_env`) pointing to an artifact which is part of a bazel module
currently this can be done by setting it as a relative path to `external//path/to/artifact`
But lacks maintainability.
A better solution would be to set it to `($location @@modules_repo_name//:SomeTarget)`
Currently this results in an error like this (from the example below):
```
ERROR: no such target '@@rules_license+//:LICENSE)': target 'LICENSE)' not declared in package '' defined by /home/q476994/.cache/bazel/_bazel_q476994/29ce9988bdb091793566352b41ee3f8e/external/rules_license+/BUILD (did you mean LICENSE, or license?)
```
Note: The actual use case is pointing to a coverage tool executable
### Which category does this issue belong to?
Configurability, Core
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
https://github.com/iancanadell-bmw/make_vars_bazelrc
`bazel test //...:all`
### Which operating system are you running Bazel on?
Ubuntu 2204 on WSL
### What is the output of `bazel info release`?
release: release 8.0.1; But also present in 7.1.2
### 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 HEAD` ?
```text
see minimal example above
```
:smile:
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
_No response_
### Have you found anything relevant by searching the web?
No
### Any other information, logs, or outputs that you want to share?
Maybe not really a bug. But then it would be a feature request
Contributor guide
Research direction
Start with the linked minimal example and its .bazelrc, then run `bazel test //...:all` on Bazel 7.1.2 or 8.0.1 to reproduce the `--test_env` location expansion error. Done means a module artifact can be referenced through `$(location ...)` in `.bazelrc` without the target name being parsed incorrectly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- build-system
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100