From 8cea102d3cc37930d84f8dd1dc1b89925a841d9a Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 17 May 2018 20:23:48 +0700 Subject: [PATCH] Fix type of Path.reach_for_running It should return a string rather than a path. Also, make Process.run use it rather than relying on the caller to do it. --- src/action.ml | 2 +- src/process.ml | 10 +++++----- src/stdune/path.mli | 2 +- test/blackbox-tests/test-cases/inline_tests/run.t | 2 +- test/unit-tests/path.mlt | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/action.ml b/src/action.ml index 67295852..f6083123 100644 --- a/src/action.ml +++ b/src/action.ml @@ -741,7 +741,7 @@ let exec_run_direct ~ectx ~dir ~env ~stdout_to ~stderr_to prog args = Process.run Strict ~dir ~env ~stdout_to ~stderr_to ~purpose:ectx.purpose - (Path.reach_for_running ~from:dir prog) args + prog args let exec_run ~stdout_to ~stderr_to = let stdout_to = get_std_output stdout_to in diff --git a/src/process.ml b/src/process.ml index f1d8bace..bc9668c5 100644 --- a/src/process.ml +++ b/src/process.ml @@ -232,7 +232,7 @@ let run_internal ?dir ?(stdout_to=Terminal) ?(stderr_to=Terminal) ~env ~purpose if display = Verbose then Format.eprintf "@{Running@}[@{%d@}]: %s@." id (Colors.strip_colors_for_stderr command_line); - let prog = Path.to_string prog in + let prog = Path.reach_for_running prog ~from:(Option.value ~default:Path.build_dir dir) in let argv = Array.of_list (prog :: args) in let output_filename, stdout_fd, stderr_fd, to_close = match stdout_to, stderr_to with @@ -347,11 +347,11 @@ let run_capture_line ?dir ~env ?(purpose=Internal_job) fail_mode prog args = | [x] -> x | l -> let cmdline = - let prog = Path.to_string prog in - let s = String.concat (prog :: args) ~sep:" " in + let prog_display p = String.concat (p :: args) ~sep:" " in match dir with - | None -> s - | Some dir -> sprintf "cd %s && %s" (Path.to_string dir) s + | None -> prog_display (Path.to_string prog) + | Some dir -> sprintf "cd %s && %s" (Path.to_string dir) + (prog_display (Path.reach_for_running prog ~from:dir)) in match l with | [] -> diff --git a/src/stdune/path.mli b/src/stdune/path.mli index 44663266..b1777d9a 100644 --- a/src/stdune/path.mli +++ b/src/stdune/path.mli @@ -70,7 +70,7 @@ val absolute : string -> t val to_absolute_filename : t -> root:string -> string val reach : t -> from:t -> string -val reach_for_running : t -> from:t -> t +val reach_for_running : t -> from:t -> string val descendant : t -> of_:t -> t option val is_descendant : t -> of_:t -> bool diff --git a/test/blackbox-tests/test-cases/inline_tests/run.t b/test/blackbox-tests/test-cases/inline_tests/run.t index cc478036..76dd7362 100644 --- a/test/blackbox-tests/test-cases/inline_tests/run.t +++ b/test/blackbox-tests/test-cases/inline_tests/run.t @@ -1,6 +1,6 @@ $ env -u OCAMLRUNPARAM jbuilder runtest simple run alias simple/runtest (exit 2) - (cd _build/default/simple && ./.foo_simple.inline-tests/run.exe) + (cd _build/default/simple && _build/default/simple/.foo_simple.inline-tests/run.exe) Fatal error: exception File "simple/.foo_simple.inline-tests/run.ml", line 1, characters 10-16: Assertion failed [1] diff --git a/test/unit-tests/path.mlt b/test/unit-tests/path.mlt index 9eb77b9c..dfcb4fed 100644 --- a/test/unit-tests/path.mlt +++ b/test/unit-tests/path.mlt @@ -287,19 +287,19 @@ Path.is_in_build_dir Path.build_dir Path.reach_for_running Path.build_dir ~from:Path.root [%%expect{| -- : Stdune.Path.t = ./_build +- : string = "./_build" |}] Path.(reach_for_running (relative build_dir "foo/baz") ~from:(relative build_dir "foo/bar/baz")) [%%expect{| -- : Stdune.Path.t = ../../baz +- : string = "../../baz" |}] Path.(reach_for_running (Path.absolute "/fake/path") ~from:(relative build_dir "foo/bar/baz")) [%%expect{| -- : Stdune.Path.t = /fake/path +- : string = "/fake/path" |}] Path.(reach_for_running (relative build_dir "foo/baz") @@ -310,5 +310,5 @@ Exception: Stdune__Exn.Code_error . Path.(reach_for_running (relative root "foo") ~from:(Path.relative root "foo")) [%%expect{| -- : Stdune.Path.t = ./. +- : string = "./." |}]