Skip to content

Commit 9c910f0

Browse files
committed
Add macOS test and no-fuse flag
1 parent 0b6c8c1 commit 9c910f0

File tree

6 files changed

+84
-6
lines changed

6 files changed

+84
-6
lines changed

lib/sandbox.macos.ml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ type t = {
99
fallback_library_path : string;
1010
(* Scoreboard -- where we keep our symlinks for knowing homedirs for users *)
1111
scoreboard : string;
12+
(* Should the sandbox mount and unmount the FUSE filesystem *)
13+
no_fuse : bool;
1214
(* Whether or not the FUSE filesystem is mounted *)
1315
mutable fuse_mounted : bool;
1416
(* Whether we have chowned/chmoded the data *)
@@ -21,6 +23,7 @@ type config = {
2123
uid: int;
2224
fallback_library_path : string;
2325
scoreboard : string;
26+
no_fuse : bool;
2427
}[@@deriving sexp]
2528

2629
let run_as ~env ~user ~cmd =
@@ -50,12 +53,12 @@ let copy_to_log ~src ~dst =
5053
and copy back out the result. It's not super efficienct, but is necessary.*)
5154
let post_build ~result_dir ~home_dir (t : t) =
5255
Os.sudo ["rsync"; "-aHq"; "--delete"; home_dir ^ "/"; result_dir ] >>= fun () ->
53-
if not t.fuse_mounted then Lwt.return () else
56+
if not t.fuse_mounted || t.no_fuse then Lwt.return () else
5457
let f = ["umount"; "-f"; "/usr/local"] in
5558
Os.sudo f >>= fun _ -> t.fuse_mounted <- false; Lwt.return ()
5659

5760
(* Using rsync to delete old files seems to be a good deal faster. *)
58-
let rec pre_build ~result_dir ~home_dir (t : t) =
61+
let pre_build ~result_dir ~home_dir (t : t) =
5962
Os.sudo [ "mkdir"; "-p"; "/tmp/obuilder-empty" ] >>= fun () ->
6063
Os.sudo [ "rsync"; "-aHq"; "--delete"; "/tmp/obuilder-empty/"; home_dir ^ "/" ] >>= fun () ->
6164
Os.sudo [ "rsync"; "-aHq"; result_dir ^ "/"; home_dir ] >>= fun () ->
@@ -64,7 +67,7 @@ let rec pre_build ~result_dir ~home_dir (t : t) =
6467
Os.sudo [ "chmod"; "-R"; "g+w"; home_dir ] >>= fun () ->
6568
Lwt.return (t.chowned <- true)
6669
end) >>= fun () ->
67-
if t.fuse_mounted then Lwt.return () else
70+
if t.fuse_mounted || t.no_fuse then Lwt.return () else
6871
let f = [ "obuilderfs"; t.scoreboard ; "/usr/local"; "-o"; "allow_other" ] in
6972
Os.sudo f >>= fun _ -> t.fuse_mounted <- true; Lwt.return ()
7073

@@ -131,6 +134,7 @@ let create ~state_dir:_ c =
131134
gid = 1000;
132135
fallback_library_path = c.fallback_library_path;
133136
scoreboard = c.scoreboard;
137+
no_fuse = c.no_fuse;
134138
fuse_mounted = false;
135139
chowned = false;
136140
}
@@ -162,8 +166,17 @@ let scoreboard =
162166
~docv:"SCOREBOARD"
163167
["scoreboard"]
164168

169+
let no_fuse =
170+
Arg.value @@
171+
Arg.flag @@
172+
Arg.info
173+
~doc:"Whether the macOS sandbox should mount and unmount the FUSE filesystem. \
174+
This is useful for testing."
175+
~docv:"NO-FUSE"
176+
["no-fuse"]
177+
165178
let cmdliner : config Term.t =
166-
let make uid fallback_library_path scoreboard =
167-
{ uid; fallback_library_path; scoreboard; }
179+
let make uid fallback_library_path scoreboard no_fuse =
180+
{ uid; fallback_library_path; scoreboard; no_fuse }
168181
in
169-
Term.(const make $ uid $ fallback_library_path $ scoreboard)
182+
Term.(const make $ uid $ fallback_library_path $ scoreboard $ no_fuse)

test/macos/dune

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(rule
2+
(alias macos)
3+
(deps
4+
./specs/simple.macos.spec
5+
./macos.sh
6+
../../main.exe)
7+
(targets ./simple.out)
8+
(action
9+
(with-stdout-to ./simple.out (run ./macos.sh))))
10+
11+
(rule
12+
(alias macos)
13+
(action (diff simple.expected simple.out)))

test/macos/macos.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
mkdir -p /tmp/scoreboard
3+
../../main.exe build . -f ./specs/simple.macos.spec --uid=705 --store=rsync:/tmp/rsync --fallback=/ --scoreboard=/tmp/scoreboard --no-fuse
4+
../../main.exe build . -f ./specs/simple.macos.spec --uid=705 --store=rsync:/tmp/rsync --fallback=/ --scoreboard=/tmp/scoreboard --no-fuse
5+
sudo rm -rf /tmp/rsync

test/macos/simple.expected

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(from patricoferris/empty@sha256:b95ca2b377dd736f609f0a10d63318c9f627a817823cf416402a29bfe9202bb9)
2+
---> saved as "1e8a7b908b7883f051110a922dc647791b81e0d658f5c1bdd8242d9ab898f8ae"
3+
/: (run (shell "mkdir hello"))
4+
---> saved as "ba0dc81067c02a45ad4a8cdbbca046aa1e59a37deca612c6a4f8698ae67e200f"
5+
/: (run (shell "echo 'hello world' > ./hello/hello.txt"))
6+
---> saved as "ee3328c16f05527e80a95b87c110aac986495aef607f14b9ef4371398a8659d8"
7+
/: (run (shell "cat ./hello/hello.txt"))
8+
hello world
9+
---> saved as "c97a5a234cc9bfcc601b2f7a98975bf294fa7552301c182358fc32ceb21308d8"
10+
/: (run (shell "rm -rf hello"))
11+
---> saved as "de2d77926d7e89828a3578ef5173bbce6050e2a7e39488b1de54dcffa864a600"
12+
/: (run (shell ls))
13+
dev
14+
etc
15+
local
16+
proc
17+
sys
18+
---> saved as "0b38a347b26152e1115a76902af06ff34a4f38aa2182e3af04e2867801fce841"
19+
Got: "0b38a347b26152e1115a76902af06ff34a4f38aa2182e3af04e2867801fce841"
20+
(from patricoferris/empty@sha256:b95ca2b377dd736f609f0a10d63318c9f627a817823cf416402a29bfe9202bb9)
21+
---> using "1e8a7b908b7883f051110a922dc647791b81e0d658f5c1bdd8242d9ab898f8ae" from cache
22+
/: (run (shell "mkdir hello"))
23+
---> using "ba0dc81067c02a45ad4a8cdbbca046aa1e59a37deca612c6a4f8698ae67e200f" from cache
24+
/: (run (shell "echo 'hello world' > ./hello/hello.txt"))
25+
---> using "ee3328c16f05527e80a95b87c110aac986495aef607f14b9ef4371398a8659d8" from cache
26+
/: (run (shell "cat ./hello/hello.txt"))
27+
hello world
28+
---> using "c97a5a234cc9bfcc601b2f7a98975bf294fa7552301c182358fc32ceb21308d8" from cache
29+
/: (run (shell "rm -rf hello"))
30+
---> using "de2d77926d7e89828a3578ef5173bbce6050e2a7e39488b1de54dcffa864a600" from cache
31+
/: (run (shell ls))
32+
dev
33+
etc
34+
local
35+
proc
36+
sys
37+
---> using "0b38a347b26152e1115a76902af06ff34a4f38aa2182e3af04e2867801fce841" from cache
38+
Got: "0b38a347b26152e1115a76902af06ff34a4f38aa2182e3af04e2867801fce841"
File renamed without changes.

test/macos/specs/simple.macos.spec

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; Tests a bug where some directories/file from previous steps that were
2+
; deleted where still hanging around.
3+
4+
((from patricoferris/empty@sha256:b95ca2b377dd736f609f0a10d63318c9f627a817823cf416402a29bfe9202bb9)
5+
(run (shell "mkdir hello"))
6+
(run (shell "echo 'hello world' > ./hello/hello.txt"))
7+
(run (shell "cat ./hello/hello.txt"))
8+
(run (shell "rm -rf hello"))
9+
(run (shell "ls")))

0 commit comments

Comments
 (0)