Skip to content

Commit

Permalink
Add macOS test and no-fuse flag
Browse files Browse the repository at this point in the history
  • Loading branch information
patricoferris committed May 5, 2022
1 parent 26fd270 commit 8c3f200
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/sandbox.macos.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type t = {
fallback_library_path : string;
(* Scoreboard -- where we keep our symlinks for knowing homedirs for users *)
scoreboard : string;
(* Should the sandbox mount and unmount the FUSE filesystem *)
no_fuse : bool;
(* Whether or not the FUSE filesystem is mounted *)
mutable fuse_mounted : bool;
(* Whether we have chowned/chmoded the data *)
Expand All @@ -21,6 +23,7 @@ type config = {
uid: int;
fallback_library_path : string;
scoreboard : string;
no_fuse : bool;
}[@@deriving sexp]

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

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

Expand Down Expand Up @@ -131,6 +134,7 @@ let create ~state_dir:_ c =
gid = 1000;
fallback_library_path = c.fallback_library_path;
scoreboard = c.scoreboard;
no_fuse = c.no_fuse;
fuse_mounted = false;
chowned = false;
}
Expand Down Expand Up @@ -162,8 +166,17 @@ let scoreboard =
~docv:"SCOREBOARD"
["scoreboard"]

let no_fuse =
Arg.value @@
Arg.flag @@
Arg.info
~doc:"Whether the macOS sandbox should mount and unmount the FUSE filesystem. \
This is useful for testing."
~docv:"NO-FUSE"
["no-fuse"]

let cmdliner : config Term.t =
let make uid fallback_library_path scoreboard =
{ uid; fallback_library_path; scoreboard; }
let make uid fallback_library_path scoreboard no_fuse =
{ uid; fallback_library_path; scoreboard; no_fuse }
in
Term.(const make $ uid $ fallback_library_path $ scoreboard)
Term.(const make $ uid $ fallback_library_path $ scoreboard $ no_fuse)
13 changes: 13 additions & 0 deletions test/macos/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(rule
(alias macos)
(deps
./specs/simple.macos.spec
./macos.sh
../../main.exe)
(targets ./simple.out)
(action
(with-stdout-to ./simple.out (run ./macos.sh))))

(rule
(alias macos)
(action (diff simple.expected simple.out)))
5 changes: 5 additions & 0 deletions test/macos/macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
mkdir -p /tmp/scoreboard
../../main.exe build . -f ./specs/simple.macos.spec --uid=705 --store=rsync:/tmp/rsync --fallback=/ --scoreboard=/tmp/scoreboard --no-fuse
../../main.exe build . -f ./specs/simple.macos.spec --uid=705 --store=rsync:/tmp/rsync --fallback=/ --scoreboard=/tmp/scoreboard --no-fuse
sudo rm -rf /tmp/rsync
38 changes: 38 additions & 0 deletions test/macos/simple.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(from patricoferris/empty@sha256:b95ca2b377dd736f609f0a10d63318c9f627a817823cf416402a29bfe9202bb9)
---> saved as "1e8a7b908b7883f051110a922dc647791b81e0d658f5c1bdd8242d9ab898f8ae"
/: (run (shell "mkdir hello"))
---> saved as "ba0dc81067c02a45ad4a8cdbbca046aa1e59a37deca612c6a4f8698ae67e200f"
/: (run (shell "echo 'hello world' > ./hello/hello.txt"))
---> saved as "ee3328c16f05527e80a95b87c110aac986495aef607f14b9ef4371398a8659d8"
/: (run (shell "cat ./hello/hello.txt"))
hello world
---> saved as "c97a5a234cc9bfcc601b2f7a98975bf294fa7552301c182358fc32ceb21308d8"
/: (run (shell "rm -rf hello"))
---> saved as "de2d77926d7e89828a3578ef5173bbce6050e2a7e39488b1de54dcffa864a600"
/: (run (shell ls))
dev
etc
local
proc
sys
---> saved as "0b38a347b26152e1115a76902af06ff34a4f38aa2182e3af04e2867801fce841"
Got: "0b38a347b26152e1115a76902af06ff34a4f38aa2182e3af04e2867801fce841"
(from patricoferris/empty@sha256:b95ca2b377dd736f609f0a10d63318c9f627a817823cf416402a29bfe9202bb9)
---> using "1e8a7b908b7883f051110a922dc647791b81e0d658f5c1bdd8242d9ab898f8ae" from cache
/: (run (shell "mkdir hello"))
---> using "ba0dc81067c02a45ad4a8cdbbca046aa1e59a37deca612c6a4f8698ae67e200f" from cache
/: (run (shell "echo 'hello world' > ./hello/hello.txt"))
---> using "ee3328c16f05527e80a95b87c110aac986495aef607f14b9ef4371398a8659d8" from cache
/: (run (shell "cat ./hello/hello.txt"))
hello world
---> using "c97a5a234cc9bfcc601b2f7a98975bf294fa7552301c182358fc32ceb21308d8" from cache
/: (run (shell "rm -rf hello"))
---> using "de2d77926d7e89828a3578ef5173bbce6050e2a7e39488b1de54dcffa864a600" from cache
/: (run (shell ls))
dev
etc
local
proc
sys
---> using "0b38a347b26152e1115a76902af06ff34a4f38aa2182e3af04e2867801fce841" from cache
Got: "0b38a347b26152e1115a76902af06ff34a4f38aa2182e3af04e2867801fce841"
File renamed without changes.
9 changes: 9 additions & 0 deletions test/macos/specs/simple.macos.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; Tests a bug where some directories/file from previous steps that were
; deleted where still hanging around.

((from patricoferris/empty@sha256:b95ca2b377dd736f609f0a10d63318c9f627a817823cf416402a29bfe9202bb9)
(run (shell "mkdir hello"))
(run (shell "echo 'hello world' > ./hello/hello.txt"))
(run (shell "cat ./hello/hello.txt"))
(run (shell "rm -rf hello"))
(run (shell "ls")))

0 comments on commit 8c3f200

Please sign in to comment.