diff --git a/src/action.ml b/src/action.ml index ddf439a3..28c60053 100644 --- a/src/action.ml +++ b/src/action.ml @@ -754,3 +754,22 @@ module Infer = struct let unexpanded_targets t = (Unexp.infer t).targets end + +let sandbox t ~sandboxed ~deps ~targets : t = + Progn + [ Progn (List.filter_map deps ~f:(fun path -> + if Path.is_managed path then + Some (Symlink (path, sandboxed path)) + else + None)) + ; map t + ~dir:Path.root + ~f_string:(fun ~dir:_ x -> x) + ~f_path:(fun ~dir:_ p -> sandboxed p) + ~f_program:(fun ~dir:_ x -> Result.map x ~f:sandboxed) + ; Progn (List.filter_map targets ~f:(fun path -> + if Path.is_managed path then + Some (Rename (sandboxed path, path)) + else + None)) + ] diff --git a/src/action.mli b/src/action.mli index ea79a690..ae33e4f9 100644 --- a/src/action.mli +++ b/src/action.mli @@ -117,10 +117,10 @@ module Infer : sig val unexpanded_targets : Unexpanded.t -> String_with_vars.t list end -val map +(** Return a sandboxed version of an action *) +val sandbox : t - -> dir:Path.t - -> f_program:(dir:Path.t -> Prog.t -> Prog.t) - -> f_string:(dir:Path.t -> string -> string) - -> f_path:(dir:Path.t -> Path.t -> Path.t) + -> sandboxed:(Path.t -> Path.t) + -> deps:Path.t list + -> targets:Path.t list -> t diff --git a/src/action_exec.ml b/src/action_exec.ml index 59c4b32a..d85e5f32 100644 --- a/src/action_exec.ml +++ b/src/action_exec.ml @@ -227,22 +227,3 @@ let exec ~targets ~context t = let purpose = Process.Build_job targets in let ectx = { purpose; context } in exec t ~ectx ~dir:Path.root ~env ~stdout_to:None ~stderr_to:None - -let sandbox t ~sandboxed ~deps ~targets : Action.t = - Progn - [ Progn (List.filter_map deps ~f:(fun path -> - if Path.is_managed path then - Some (Action.Symlink (path, sandboxed path)) - else - None)) - ; Action.map t - ~dir:Path.root - ~f_string:(fun ~dir:_ x -> x) - ~f_path:(fun ~dir:_ p -> sandboxed p) - ~f_program:(fun ~dir:_ x -> Result.map x ~f:sandboxed) - ; Progn (List.filter_map targets ~f:(fun path -> - if Path.is_managed path then - Some (Action.Rename (sandboxed path, path)) - else - None)) - ] diff --git a/src/action_exec.mli b/src/action_exec.mli index c3b1d6cb..ebec0af7 100644 --- a/src/action_exec.mli +++ b/src/action_exec.mli @@ -5,11 +5,3 @@ val exec -> context:Context.t option -> Action.t -> unit Fiber.t - -(* Return a sandboxed version of an action *) -val sandbox - : Action.t - -> sandboxed:(Path.t -> Path.t) - -> deps:Path.t list - -> targets:Path.t list - -> Action.t diff --git a/src/build_system.ml b/src/build_system.ml index 4c3a5278..0f0a67a7 100644 --- a/src/build_system.ml +++ b/src/build_system.ml @@ -796,7 +796,7 @@ let rec compile_rule t ?(copy_source=false) pre_rule = let sandboxed path = Path.sandbox_managed_paths ~sandbox_dir path in make_local_parent_dirs t all_deps ~map_path:sandboxed; make_local_parent_dirs t targets ~map_path:sandboxed; - Action_exec.sandbox action + Action.sandbox action ~sandboxed ~deps:all_deps_as_list ~targets:targets_as_list