bazel-contrib / bazel-contrib/rules_bazel_integration_test

FR: Allow using bazel from PATH

Open
#265 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Starlark
Stars
65
Forks
16
Avg merge
1d 9h
Merged PRs (30d)
9

Description

The basic use case is to allow easily using the same bazel that the user uses to run their builds. The main use case I have in mind for this is when you're using a custom build of bazel specified using `USE_BAZEL_VERSION`. e.g. if one does:

```
USE_BAZEL_VERSION=/tmp/bazel-dev bazel //my:test
```

Then the version of bazel at /tmp/bazel-dev will be used, without having to go into the MODULE.bazel config (or elsewhere) to reconfigure this. Having to do that is a hassle and changes the name of generated targets.

I think the `bazel_binaries.local()` tag class can be easily adopted for this purpose:
* Add an attribute, `shell_command`, which takes a single word, e.g. "bazel", "mybazel", "bazel-dev", etc.
* In `_local_bazel_binary_repo`, call `repository_ctx.which(shell_command)` to get the actual path
* Add `USE_BAZEL_VERSION` and `PATH` to the repo rule's environment variables that affect it.

The end result looks something like:

```
bazel_binaries.local(shell_command="bazel", name="self")
```

I was able to emulate this by using a local path to a script that just re-execs using the command "bazel", but it'd be nicer if I didn't have to plumb through a wrapper to achieve that.

Contributor guide

Open the contributing guide

Research direction

Start by reading the bazel_binaries.local tag class and the _local_bazel_binary_repo implementation. Verify how the repository rule currently selects Bazel and tracks environment changes, then confirm that a shell_command such as "bazel" resolves through PATH and that USE_BAZEL_VERSION and PATH trigger reevaluation.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.