Skip to content

Commit

Permalink
Print "Leaving directory '...'" in addition to "Entering directory ..."
Browse files Browse the repository at this point in the history
The "Entering ..." message was introduced in 157e4d6.  Adding a matching
"Leaving directory "..."' message helps when dune is invoked in sequence with
other programs: otherwise, editors use dune's root to interpret path printed by
programs executed after dune (instead of the original working directory).
Discussed in ocaml#138.

Signed-off-by: Clément Pit-Claudel <[email protected]>
  • Loading branch information
cpitclaudel committed Feb 1, 2020
1 parent 330e5ff commit 603d001
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/dune/scheduler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -629,31 +629,33 @@ let prepare ?(config = Config.default) () =
Signal_watcher.init ();
Process_watcher.init ();
let cwd = Sys.getcwd () in
if cwd <> initial_cwd && not !Clflags.no_print_directory then
Printf.eprintf "Entering directory '%s'\n%!"
( if Config.inside_dune then
let descendant_simple p ~of_ =
match String.drop_prefix p ~prefix:of_ with
| None
| Some "" ->
None
| Some s -> Some (String.drop s 1)
in
match descendant_simple cwd ~of_:initial_cwd with
| Some s -> s
| None -> (
match descendant_simple initial_cwd ~of_:cwd with
| None -> cwd
| Some s ->
let rec loop acc dir =
if dir = Filename.current_dir_name then
acc
else
loop (Filename.concat acc "..") (Filename.dirname dir)
in
loop ".." (Filename.dirname s) )
else
cwd );
(if cwd <> initial_cwd && not !Clflags.no_print_directory then
let directory =
if Config.inside_dune then
let descendant_simple p ~of_ =
match String.drop_prefix p ~prefix:of_ with
| None
| Some "" ->
None
| Some s -> Some (String.drop s 1)
in
match descendant_simple cwd ~of_:initial_cwd with
| Some s -> s
| None -> (
match descendant_simple initial_cwd ~of_:cwd with
| None -> cwd
| Some s ->
let rec loop acc dir =
if dir = Filename.current_dir_name then
acc
else
loop (Filename.concat acc "..") (Filename.dirname dir)
in
loop ".." (Filename.dirname s) )
else
cwd in
Printf.eprintf "Entering directory '%s'\n%!" directory;
at_exit (fun () -> Printf.eprintf "Leaving directory '%s'\n%!" directory));
let t =
{ original_cwd = cwd
; concurrency =
Expand Down

0 comments on commit 603d001

Please sign in to comment.