当不支持沙箱时,有没有办法让 bazel 使用沙箱目录?

Is there a way to get bazel to use sandbox directories when sandboxing is not supported?

我在 docker 容器中 运行ning bazel。在本地,当我 运行 bazel 没有标志时,我收到以下警告:

WARNING: Sandboxed execution is not supported on your system and thus hermeticity of actions cannot be guaranteed. See http://bazel.build/docs/bazel-user-manual.html#sandboxing for more information. You can turn off this warning via --ignore_unsupported_sandboxing.

虽然我失去了一些关于密封性的保证,但 Bazel 仍然会在 运行 我的任何 genrules 之前创建所有沙盒目录。

但是,在 CI 中,我没有看到该警告,而是在尝试沙盒时失败。所以我通过 --genrule_strategy=standalone 来阻止崩溃,但现在我的 genrules 正在工作区中执行,这是我绝对不希望的。

有没有办法让我获得我在本地看到的行为,其中显式沙盒调用被禁用,因为它们会失败,但 tmp 目录创建 srcs/deps/data 被正确复制仍然发生?

我可以将一个标志传递给 bazel 以触发该行为,或者我可以对我的系统做些什么来说服 bazel 那里不支持沙盒?

您使用的是哪个 bazel 版本,当它尝试使用沙盒时会崩溃?我怀疑 c2d773ef4c0916a44fd7936f7bbc22ec55102915 会解决这个问题,因为它可以检测沙箱是否工作得更稳健,看起来它会做你正在寻找的事情。

两个可能的选择:

1) 要禁用沙盒,--genrule_strategy=standalone 仅适用于 genrules。您还需要为其他规则禁用它,即添加 --spawn_strategy=standalone。您可能还需要针对特定​​规则类型禁用它,例如--strategy GoCompile=standalone.

2) 要使用沙盒,您可以在特权容器内 运行 Bazel,即使用 --privileged 标志启动其容器。这可能是您 CI.

中的一个配置选项