From 87fa4c080a39405e194959bb897f5ed310e4016f Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Fri, 3 Mar 2017 13:53:34 +0000 Subject: [PATCH] Fix the use of Path.reach for program names --- src/action.ml | 2 +- src/path.ml | 15 +++++++++++++++ src/path.mli | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/action.ml b/src/action.ml index a5b649d8..14dc238a 100644 --- a/src/action.ml +++ b/src/action.ml @@ -160,7 +160,7 @@ module Mini_shexp = struct in let env = Context.extend_env ~vars:env_extra ~env in Future.run Strict ~dir:(Path.to_string dir) ~env ~stdout_to - (Path.reach ~from:dir prog) args + (Path.reach_for_running ~from:dir prog) args let rec exec t ~dir ~env ~env_extra ~stdout_to ~tail = match t with diff --git a/src/path.ml b/src/path.ml index 69a78e06..2fcf38ef 100644 --- a/src/path.ml +++ b/src/path.ml @@ -261,6 +261,21 @@ let reach t ~from = ] | true, true -> Local.reach t ~from +let reach_for_running t ~from = + match is_local t, is_local from with + | false, _ -> t + | true, false -> + Sexp.code_error "Path.reach_for_running called with invalid combination" + [ "t" , sexp_of_t t + ; "from", sexp_of_t from + ] + | true, true -> + let s = Local.reach t ~from in + if String.is_prefix s ~prefix:"../" then + s + else + "./" ^ s + let descendant t ~of_ = if is_local t && is_local of_ then Local.descendant t ~of_ diff --git a/src/path.mli b/src/path.mli index d92043d6..e29d354f 100644 --- a/src/path.mli +++ b/src/path.mli @@ -49,6 +49,7 @@ val relative : t -> string -> t val absolute : string -> t val reach : t -> from:t -> string +val reach_for_running : t -> from:t -> string val descendant : t -> of_:t -> t option