This repository contains a parser for bazelrc files written in Go.
It is limited in its accuracy, as it is providing mostly syntactic parsing, and does not have a full awareness of how Bazel itself parses config (which also changes over time).
Some of its known limitations:
- It treats config-gated settings as independent commands, including platform-specific configs (i.e.
build:remote --jobs=100is independent ofbuild --jobs=200). - It does not understand what settings accumulate multiple uses (i.e. it doesn't know that
foois relevant inbuild --extra_toolchains=foo --extra_toolchains=bar). - It does not know about the types of values that are expected, so e.g. doesn't know that boolean flags may coerce
0and1tofalseandtrue. - Its handling of spaces inside flags (e.g.
--copt="--foo --bar") may not exactly match Bazel's.
There's plausibly a space for expanding the bazel canonicalize-flags command to make this library obsolete. Some of the limitations of bazel canonicalize-flags are:
- It require invoking bazel (and require setting up a whole server so is slow, requires the server lock, and may invalidate the analysis cache if not done very carefully)
- It doesn't support reading from
.bazelrcfiles at all, so pre-processing would still need to be done to load the flags to pass them to bazel.- Also, there isn't an easy way to support
--configflags, and the order of priority of handling flags enabled by--configis one of the more fiddly parts of flag parsing.
- Also, there isn't an easy way to support
bazel canonicalize-flagswill error if targets are specified (i.e.bazel canonicalize-flags -- --jobs=10 //:gazellewill error), so these would need detecting and stripping out.bazel canonicalize-flagsdoesn't provide structured output, just "flag per line", which causes issues for e.g. copts containing newlines.