Open kolloch opened 1 month ago
I'm still thinking about how lazy tools could be made to work reliably.
select
ing tools unfortunately can't be done since we need to create one target per tool for runfiles to work properly and that requires knowing the tools at load rather than analysis time. But you can use an alias
as a tool and add a select
to it that switches to a stub tool showing an "unavailable unless you flip flag X" error.
Then I included the following snippet in the .envrc
that allows you to write your env target suffix into .bazelenv
:
watch_file .bazelenv
if [ -r .bazelenv ]; then
BAZEL_ENV=$(cat .bazelenv)
# remove leading whitespace characters
BAZEL_ENV="${BAZEL_ENV#"${BAZEL_ENV%%[![:space:]]*}"}"
# remove trailing whitespace characters
BAZEL_ENV="${BAZEL_ENV%"${BAZEL_ENV##*[![:space:]]}"}"
echo "Detected bazelenv: $BAZEL_ENV" >&2
else
BAZEL_ENV="devenv"
fi
watch_file bazel-out/bazel_env-opt/bin/env/$BAZEL_ENV/bin
PATH_add bazel-out/bazel_env-opt/bin/env/$BAZEL_ENV/bin
if [[ ! -d bazel-out/bazel_env-opt/bin/env/$BAZEL_ENV/bin ]]; then
log_error "ERROR[bazel_env.bzl]: Run 'bazel run //env:$BAZEL_ENV' to regenerate bazel-out/bazel_env-opt/bin/env/$BAZEL_ENV/bin"
fi
export BAZEL_BINDIR="$(expand_path bazel-bin)"
It would be nice to standardize on one approach here. E.g. one could make bazel run @bazel_env.bzl
read a config file for the target to use and/or some other options. And then also use that in .envrc
Some of our commands are cheap to provision (just a simple download), some of them are expensive since they will be built from source with many dependencies.
Always building all tools therefore seems excessive.
Possible solutions:
bazel_env add
to actually provision them. Or allowselect
in the attribute so that some simple lines in the user's .bazelrc suffice.