bazelbuild / bazelbuild/bazel-toolchains
rbe_configs_gen: confusing error when custom container contains .bazelrc
- Dominant language
- Go
- Stars
- 202
- Forks
- 100
- PR merge metrics
- No merged PRs in 30d
Description
*Disclaimer: I understand this may be an invalid use case and I am using the tool tool incorrectly 🙃*
## Background:
My team needs to produce native CPP build for CentOS and CentOS 7 has an older version of glibc so we are using a CentOS-based custom container[1].
I thought I would be clever and define a custom platform within my sandbox container and included a `build --host_platform //toolchain:centos` in the bazelrc of our container allowing us to use constraints to prevent someone from accidentally building e.g. an RPM on Ubuntu.
## Issue
Fast forward to an investigation into using RBE and I got a confusing error when running rbe_configs_gen
```
ERROR: While resolving toolchains for target @local_config_cc//:cc-compiler-k8: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package 'toolchain': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
- /workdir/cpp_configs_project/toolchain
ERROR: Analysis of target '@local_config_cc//:cc-compiler-k8' failed; build aborted: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package 'toolchain': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
- /workdir/cpp_configs_project/toolchain
```
`@local_config_cc//` wha? is Bazel somehow broken?
I now now realize this was due to Bazel reading the `.bazelrc` defined in the container and this is admittedly self-inflicted but it took me quite a while to figure this out. Removing the .bazelrc file from our container solves the problem.
## Suggested Solutions
1) Do nothing, hopefully anyone who runs into this issue finds this issue by the keywords I included in this issue
1) add `--bazelrc=/dev/null` to the bazel commands run by rbe_configs_gen
I think doing nothing is a perfectly acceptable solution, my main reason for raising this issue is making it searchable in case anyone makes the same mistake in the future.
---
[1] Maybe we would be better served by extending an existing ubuntu rbe base image and installing the desired version of GCC *but* for now we are exploring making a custom container based on CentOS to try to closely match the target environment.
Contributor guide
Research direction
Start at the rbe_configs_gen entry point and inspect the Bazel commands it runs, focusing on how a custom container's .bazelrc is picked up. Compare the proposed --bazelrc=/dev/null behavior with the current commands; done should mean the tool no longer produces a misleading toolchain error from the container's Bazel configuration.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100