With sandboxing enabled, Bazel doesn't create output directories for TreeArtifacts, and tools have to create them manually. The output directories should be created for consistency with other spawn strategies.
This issue was the underlying problem in #6203.
Repro:
BUILD
load(":def.bzl", "r")
r(name = "a")
def.bzl
def _r(ctx):
d = ctx.actions.declare_directory("%s_dir" % ctx.label.name)
ctx.actions.run_shell(
outputs = [d],
command = "cd %s && pwd" % d.path,
)
return [DefaultInfo(files = depset([d]))]
r = rule(implementation = _r)
Building with sandboxing enabled fails, because the directory for the TreeArtifact isn't created:
$ bazel build ...
...
ERROR: /tmp/tmp.wido4a1xyh/BUILD:3:1: error executing shell command: '/bin/bash -c cd bazel-out/k8-fastbuild/bin/a_dir && pwd' failed (Exit 1) bash failed: error executing command /bin/bash -c 'cd bazel-out/k8-fastbuild/bin/a_dir && pwd'
Use --sandbox_debug to see verbose messages from the sandbox
Building with --spawn_strategy=standalone succeeds:
bazel build --spawn_strategy=standalone ...
... OK
With sandboxing enabled, Bazel doesn't create output directories for TreeArtifacts, and tools have to create them manually. The output directories should be created for consistency with other spawn strategies.
This issue was the underlying problem in #6203.
Repro:
BUILDdef.bzlBuilding with sandboxing enabled fails, because the directory for the TreeArtifact isn't created:
Building with
--spawn_strategy=standalonesucceeds: