Export `BAZEL_VERSION` to allow for version specific `.bazelrc` files
Having a BAZEL_VERSION environment variable will allow for:
try-import %workspace%/.bazelrc.${BAZEL_VERSION}
We already implement environment variable replacement within the component.
There will need to be three variables to allow flexible imports:
BAZEL_MAJOR_VERSIONBAZEL_MAJOR_MINOR_VERSIONBAZEL_MAJOR_MINOR_PATCH_VERSION
We can set BAZEL_VERSION to BAZEL_MAJOR_MINOR_PATCH_VERSION for convenience.
To create these variables, we will need to run bazelisk --version to get the bazel <version> output.
The following Bash snippet performs the string manipulation necessary:
bazelisk --version | while IFS=' .' read -r PREFIX MAJOR MINOR PATCH; do
test "${PREFIX}" == "bazel"
test "${MAJOR}" -ge 0
test "${MINOR}" -ge 0
test "${PATCH}" -ge 0
BAZEL_MAJOR_VERSION="${MAJOR}"
BAZEL_MAJOR_MINOR_VERSION="${MAJOR}.${MINOR}"
BAZEL_MAJOR_MINOR_PATCH_VERSION="${MAJOR}.${MINOR}.${PATCH}"
BAZEL_VERSION="${BAZEL_MAJOR_MINOR_PATCH_VERSION}"
done
Ideally, we do not want to export these variables and only use them in the .bazelrc environment variable replacement.