Skip to content

Commit 3748084

Browse files
lberkicopybara-github
authored andcommitted
Mount user-specified bind mounts before Bazel's own magic.
This makes it possible to mount directories under /tmp somewhere else. Before, /tmp was overridden by the implementation of hermetic /tmp. Fixes #20527. RELNOTES: None. PiperOrigin-RevId: 592247867 Change-Id: Ib5b75cd21ffe4fa4c8ee3f75d82894da6dd61f54
1 parent 132f73a commit 3748084

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ private ImmutableList<BindMount> getBindMounts(
423423

424424
LinuxSandboxUtil.validateBindMounts(bindMounts);
425425
ImmutableList.Builder<BindMount> result = ImmutableList.builder();
426+
bindMounts.forEach((k, v) -> result.add(BindMount.of(k, v)));
426427

427428
if (sandboxTmp != null) {
428429
// First mount the real exec root and the empty directory created as the working dir of the
@@ -445,7 +446,6 @@ private ImmutableList<BindMount> getBindMounts(
445446
result.add(BindMount.of(tmpPath, sandboxTmp));
446447
}
447448

448-
bindMounts.forEach((k, v) -> result.add(BindMount.of(k, v)));
449449
return result.build();
450450
}
451451

src/test/shell/bazel/bazel_sandboxing_test.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,34 @@ EOF
306306
bazel build //pkg:a &>$TEST_log || fail "expected build to succeed"
307307
}
308308

309+
function test_add_mount_pair_tmp_source() {
310+
if [[ "$PLATFORM" == "darwin" ]]; then
311+
# Tests Linux-specific functionality
312+
return 0
313+
fi
314+
315+
create_workspace_with_default_repos WORKSPACE
316+
317+
sed -i.bak '/sandbox_tmpfs_path/d' $TEST_TMPDIR/bazelrc
318+
319+
mkdir -p pkg
320+
cat > pkg/BUILD <<'EOF'
321+
genrule(
322+
name = "gen",
323+
outs = ["gen.txt"],
324+
cmd = "cp /etc/data.txt $@",
325+
)
326+
EOF
327+
328+
local mounted=$(mktemp -d "/tmp/bazel_mounted.XXXXXXXX")
329+
trap "rm -fr $mounted" EXIT
330+
echo GOOD > "$mounted/data.txt"
331+
332+
# This assumes the existence of /etc on the host system
333+
bazel build --sandbox_add_mount_pair="$mounted:/etc" //pkg:gen || fail "build failed"
334+
assert_contains GOOD bazel-bin/pkg/gen.txt
335+
}
336+
309337
# The test shouldn't fail if the environment doesn't support running it.
310338
check_sandbox_allowed || exit 0
311339

0 commit comments

Comments
 (0)