Skip to content

Commit

Permalink
fix: watch mode when PATH contains CWD
Browse files Browse the repository at this point in the history
On MacOS, PATH=.:PWD would add build paths to the list of directories
being watched. Fsevents only reports absolute paths, so we need to try
and convert them to build/source/external paths. On Linux, watching .
would produce relative (source paths), so this issue wouldn't occur.

Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Mar 29, 2023
1 parent 7855597 commit 4504e55
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 79 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Fix dune crashing on MacOS in watch mode whenever `$PATH` contains `$PWD`
(#7441, fixes #6907, @rgrinberg)

- Fix `dune install` when cross compiling (#7410, fixes #6191, @anmonteiro,
@rizo)

Expand Down
12 changes: 8 additions & 4 deletions src/dune_engine/fs_memo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,13 @@ let invalidate_path_and_its_parent path =
directory should be added to or removed from the result. *)
let handle_fs_event ({ kind; path } : Dune_file_watcher.Fs_memo_event.t) :
Memo.Invalidation.t =
let path = Path.as_outside_build_dir_exn path in
match kind with
| File_changed -> Watcher.invalidate path
| Created | Deleted | Unknown -> invalidate_path_and_its_parent path
match Path.destruct_build_dir path with
| `Inside _ ->
(* This can occur on MacOS when [PATH=.:$PATH] for example *)
Memo.Invalidation.empty
| `Outside path -> (
match kind with
| File_changed -> Watcher.invalidate path
| Created | Deleted | Unknown -> invalidate_path_and_its_parent path)

let init = Watcher.init
79 changes: 4 additions & 75 deletions test/blackbox-tests/test-cases/watching/path-pwd.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,84 +19,13 @@ Reproduce #6907
> EOF

$ build y
Error: { payload = Some [ [ "id"; [ "auto"; "0" ] ] ]
; message =
"connection terminated. this request will never receive a response"
; kind = Connection_dead
}
Success

$ touch x

$ build y
Timed out
Internal error, please report upstream including the contents of _build/log.
Description:
("as_outside_build_dir_exn", { path = In_build_dir ".sync/0" })
Raised at Stdune__Code_error.raise in file
"otherlibs/stdune/src/code_error.ml", line 11, characters 30-62
Called from Dune_engine__Fs_memo.handle_fs_event in file
"src/dune_engine/fs_memo.ml", line 289, characters 13-47
Called from
Dune_engine__Scheduler.Run_once.handle_invalidation_events.handle_event in
file "src/dune_engine/scheduler.ml", line 966, characters 26-55
Called from Stdlib__List.fold_left in file "list.ml", line 121, characters
24-34
Called from Dune_engine__Scheduler.Run_once.build_input_change in file
"src/dune_engine/scheduler.ml", line 1002, characters 23-56
Called from Fiber.run.loop in file "otherlibs/fiber/src/fiber.ml", line 15,
characters 51-60
Called from Dune_engine__Scheduler.Run_once.run in file
"src/dune_engine/scheduler.ml", line 1069, characters 10-50
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune/src/exn.ml", line 36, characters 27-56
Called from Cmdliner_term.app.(fun) in file
"vendor/cmdliner/src/cmdliner_term.ml", line 24, characters 19-24
Called from Cmdliner_eval.run_parser in file
"vendor/cmdliner/src/cmdliner_eval.ml", line 34, characters 37-44
Called from Cmdliner_eval.eval_value in file
"vendor/cmdliner/src/cmdliner_eval.ml", line 202, characters 14-39
Called from Dune__exe__Main in file "bin/main.ml", line 97, characters 10-41

I must not crash. Uncertainty is the mind-killer. Exceptions are the
little-death that brings total obliteration. I will fully express my cases.
Execution will pass over me and through me. And when it has gone past, I
will unwind the stack along its path. Where the cases are handled there will
be nothing. Only I will remain.
exit 1
Success

$ stop_dune
Error: rpc server not running
Internal error, please report upstream including the contents of _build/log.
Description:
("as_outside_build_dir_exn", { path = In_build_dir ".sync/0" })
Raised at Stdune__Code_error.raise in file
"otherlibs/stdune/src/code_error.ml", line 11, characters 30-62
Called from Dune_engine__Fs_memo.handle_fs_event in file
"src/dune_engine/fs_memo.ml", line 289, characters 13-47
Called from
Dune_engine__Scheduler.Run_once.handle_invalidation_events.handle_event in
file "src/dune_engine/scheduler.ml", line 966, characters 26-55
Called from Stdlib__List.fold_left in file "list.ml", line 121, characters
24-34
Called from Dune_engine__Scheduler.Run_once.build_input_change in file
"src/dune_engine/scheduler.ml", line 1002, characters 23-56
Called from Fiber.run.loop in file "otherlibs/fiber/src/fiber.ml", line 15,
characters 51-60
Called from Dune_engine__Scheduler.Run_once.run in file
"src/dune_engine/scheduler.ml", line 1069, characters 10-50
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune/src/exn.ml", line 36, characters 27-56
Called from Cmdliner_term.app.(fun) in file
"vendor/cmdliner/src/cmdliner_term.ml", line 24, characters 19-24
Called from Cmdliner_eval.run_parser in file
"vendor/cmdliner/src/cmdliner_eval.ml", line 34, characters 37-44
Called from Cmdliner_eval.eval_value in file
"vendor/cmdliner/src/cmdliner_eval.ml", line 202, characters 14-39
Called from Dune__exe__Main in file "bin/main.ml", line 97, characters 10-41

I must not crash. Uncertainty is the mind-killer. Exceptions are the
little-death that brings total obliteration. I will fully express my cases.
Execution will pass over me and through me. And when it has gone past, I
will unwind the stack along its path. Where the cases are handled there will
be nothing. Only I will remain.
exit 1
Success, waiting for filesystem changes...
Success, waiting for filesystem changes...

0 comments on commit 4504e55

Please sign in to comment.