From 5efaba267fc5f01a3e82f300cfe657a7ca0c15f0 Mon Sep 17 00:00:00 2001 From: Wade Carpenter Date: Thu, 28 Nov 2024 13:58:13 -0800 Subject: [PATCH] demo: use fakeroot to avoid needing sudo ==================== Test output for //:mount_tmpfs_without_fakeroot: ++ mkdir -p /tmp/target ++ mount -t tmpfs none /tmp/target mount: /tmp/target: must be superuser to use mount. ==================== Test output for //:mount_tmpfs_fakeroot: ++ mkdir -p /tmp/target ++ mount -t tmpfs none /tmp/target ++ findmnt /tmp/target TARGET SOURCE FSTYPE OPTIONS /tmp/target none tmpfs rw,relatime,uid=1000,gid=1000,inode64 --- .bazelrc | 2 ++ .bazelversion | 1 + BUILD.bazel | 26 +++++++++++++++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 .bazelversion diff --git a/.bazelrc b/.bazelrc index 011eb53..d04e674 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1 +1,3 @@ common --lockfile_mode=off + +test --announce_rc diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 0000000..9907836 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +8.0.0rc6 diff --git a/BUILD.bazel b/BUILD.bazel index 3d75b80..a02e622 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,10 +1,26 @@ +v = """ +#!/bin/bash +set -uxeo pipefail +mkdir -p /tmp/target +mount -t tmpfs none /tmp/target +findmnt /tmp/target +""" + genrule( - name = "test_sh", - outs = ["test.sh"], - cmd = "touch $@", + name = "create_script", + srcs = [], + outs = ["mount_tmpfs.sh"], + cmd = "echo \"{}\" > $@".format(v), + executable = True, +) + +sh_test( + name = "mount_tmpfs_fakeroot", + srcs = ["mount_tmpfs.sh"], + tags = ["requires-fakeroot"], ) sh_test( - name = "test", - srcs = ["test.sh"], + name = "mount_tmpfs_without_fakeroot", + srcs = ["mount_tmpfs.sh"], )