From 0ed758ef8a07dcc52323742d546a1b1f5998a0da Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Mon, 9 Jul 2018 11:44:10 +0100 Subject: [PATCH] Fix sandboxing when the build directory is absolute Fix #979 Signed-off-by: Jeremie Dimino --- src/build_system.ml | 7 +------ src/stdune/path.ml | 9 +++++++++ src/stdune/path.mli | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/build_system.ml b/src/build_system.ml index 95aa1ac1..56db2f5b 100644 --- a/src/build_system.ml +++ b/src/build_system.ml @@ -790,12 +790,7 @@ let rec compile_rule t ?(copy_source=false) pre_rule = match sandbox_dir with | Some sandbox_dir -> Path.rm_rf sandbox_dir; - let sandboxed path = - if Path.is_managed path then - Path.append sandbox_dir path - else - path - in + 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.sandbox action diff --git a/src/stdune/path.ml b/src/stdune/path.ml index c8c00eaa..e5066859 100644 --- a/src/stdune/path.ml +++ b/src/stdune/path.ml @@ -764,6 +764,15 @@ let drop_optional_build_context t = | None -> t | Some (_, t) -> t +let local_src = Local.of_string "src" +let local_build = Local.of_string "build" + +let sandbox_managed_paths ~sandbox_dir t = + match t with + | External _ -> t + | In_source_tree p -> append_local sandbox_dir (Local.append local_src p) + | In_build_dir p -> append_local sandbox_dir (Local.append local_build p) + let split_first_component t = match kind t, is_root t with | Local t, false -> diff --git a/src/stdune/path.mli b/src/stdune/path.mli index c17ca474..793c6255 100644 --- a/src/stdune/path.mli +++ b/src/stdune/path.mli @@ -103,6 +103,10 @@ val drop_build_context_exn : t -> t (** Drop the "_build/blah" prefix if present, return [t] otherwise *) val drop_optional_build_context : t -> t +(** Transform managed paths so that they are descedant of + [sandbox_dir]. *) +val sandbox_managed_paths : sandbox_dir:t -> t -> t + val explode : t -> string list option val explode_exn : t -> string list