From a82022fc5eecd5a53e620308a9d2bb38baeb0435 Mon Sep 17 00:00:00 2001 From: Oscar Bonilla <6f6231@gmail.com> Date: Mon, 13 Sep 2021 10:09:30 -0700 Subject: [PATCH] Don't resolve symlinks for --sandbox_base On macOS BigSur, the sandbox-exec command behaves slightly different than on Catalina when firm links are present. Resolving symlinks can prevent the sandbox for allowing write operations to the sandbox base. This effectively reverts a piece of 656a0ba on macOS, namely: > When using --experimental_sandbox_base, ensure that symlinks in the path are > resolved. Before this, you had to check whether on your system /dev/shm is a > symlink to /run/shm and then use that instead. Now it no longer matters, as > symlinks are resolved. but I think this is okay since macOS doesn't have /dev/shm or /run. See https://github.com/bazelbuild/bazel/issues/13766 for full details. --- .../com/google/devtools/build/lib/sandbox/SandboxModule.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java index 0f73a413d97bde..1f2b1c104a9dcc 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java @@ -126,6 +126,10 @@ private static Path computeSandboxBase(SandboxOptions options, CommandEnvironmen env.getRuntime().getProductName(), Fingerprint.getHexDigest(env.getOutputBase().toString())); FileSystem fileSystem = env.getRuntime().getFileSystem(); + if (OS.getCurrent() == OS.DARWIN) { + // Don't resolve symlinks on macOS: See https://github.com/bazelbuild/bazel/issues/13766 + return fileSystem.getPath(options.sandboxBase).getRelative(dirName); + } Path resolvedSandboxBase = fileSystem.getPath(options.sandboxBase).resolveSymbolicLinks(); return resolvedSandboxBase.getRelative(dirName); }