如何取消在 bazelrc 中设置的标志?

How do I unset flags set in bazelrc?

我的 bazel.rc 有设置远程缓存的标志,但在某些情况下我想禁用它,例如当运行在有网络限制的环境中。

如何 "unset" 在 bazel.rc 中设置标志?例如,bazel.rc 设置 --google_credentials=/path/to/key,那么我如何覆盖它并传入 null 以便它不查找凭据?

我想保留我剩下的 bazel.rc,所以我不想简单地忽略它。

部分bazel.rc:

build --google_credentials=/path/to/key
build --google_default_credentials
build --google_auth_scopes=https://www.googleapis.com/auth/cloud-source-tools
build --bes_backend=buildeventservice.googleapis.com
build --bes_best_effort=false
build --bes_timeout=10s
build --project_id=123456
build --remote_cache=remotebuildexecution.googleapis.com
build --remote_instance_name=projects/myproject
build --spawn_strategy=remote
build --genrule_strategy=remote
build --tls_enabled=1
build --remote_accept_cached=true

在命令行中指定的标志将覆盖 bazelrc 文件中的任何内容。所以可以指定--google_credentials=来清除值。

还有其他设置方法。在您的情况下,默认情况下您想要 --foo=1 --bar=2 ,但有时您想关闭它们。必须记住所有标志才能关闭它会很烦人,因此您可以创建配置。您的 bazelrc 文件将如下所示:

build --foo=1 --bar=2
build:nofoo --foo= --bar=

当正常执行bazel build时,您会得到--foo=1--bar=2。当您不想要 foobar 时,您可以执行 bazel build --config=nofoo,它会扩展为 bazel build --foo=1 --bar=2 --foo= --bar=,其中后面的标志将覆盖前面的标志。