cp -r copies the symlinks, not the destination of symlinks. This results in
a TreeArtifact with symlinks to content outside the TreeArtifact, which is not
well defined in bazel[^1]. At least bazel 7.1.1's linux-sandbox (bazel
--spawn_strategy=sandboxed on Linux) does not follow the symlinks and destroys
the temporary directory containing the actual files after the action, leaving a
TreeArtifact of dangling symlinks.
cp -rL chases the symlinks and creates a TreeArtifact of regular files. This
has the desired behaviour in all bazel versions/sandboxes.
[^1]: See discussion in https://github.com/bazelbuild/bazel/issues/15454. It is
unclear whether we want to resolve these symlinks or leave them dangling, and
behaviour varies across bazel versions and execution environment.
cp -r
copies the symlinks, not the destination of symlinks. This results in a TreeArtifact with symlinks to content outside the TreeArtifact, which is not well defined in bazel[^1]. At least bazel 7.1.1's linux-sandbox (bazel --spawn_strategy=sandboxed on Linux) does not follow the symlinks and destroys the temporary directory containing the actual files after the action, leaving a TreeArtifact of dangling symlinks.cp -rL
chases the symlinks and creates a TreeArtifact of regular files. This has the desired behaviour in all bazel versions/sandboxes.[^1]: See discussion in https://github.com/bazelbuild/bazel/issues/15454. It is unclear whether we want to resolve these symlinks or leave them dangling, and behaviour varies across bazel versions and execution environment.