Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use standard_watch_exclusions with fsevents #9643

Merged
merged 4 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changes/9643.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Use watch exclusions in watch mode on MacOS (#9643, fixes #9517,
@PoorlyDefinedBehaviour)
39 changes: 20 additions & 19 deletions src/dune_file_watcher/dune_file_watcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type kind =
; source : Fsevents.t
; sync : Fsevents.t
; latency : float
; on_event : Fsevents.Event.t -> Path.t -> Event.t option
}
| Inotify of Inotify_lib.t
| Fswatch_win of
Expand Down Expand Up @@ -549,18 +550,21 @@ let fsevents ?exclusion_paths ~latency ~paths scheduler f =
fsevents
;;

let fsevents_standard_event event path =
let kind =
match Fsevents.Event.action event with
| Rename | Unknown -> Fs_memo_event.Unknown
| Create -> Created
| Remove -> Deleted
| Modify -> if Fsevents.Event.kind event = File then File_changed else Unknown
in
Some (Event.Fs_memo_event { Fs_memo_event.kind; path })
let fsevents_standard_event ~should_exclude event path =
if should_exclude (Path.to_string path)
then None
else (
let kind =
match Fsevents.Event.action event with
| Rename | Unknown -> Fs_memo_event.Unknown
| Create -> Created
| Remove -> Deleted
| Modify -> if Fsevents.Event.kind event = File then File_changed else Unknown
in
Some (Event.Fs_memo_event { Fs_memo_event.kind; path }))
;;

let create_fsevents ?(latency = 0.2) ~(scheduler : Scheduler.t) () =
let create_fsevents ?(latency = 0.2) ~(scheduler : Scheduler.t) ~should_exclude () =
prepare_sync ();
let sync_table = Table.create (module String) 64 in
let sync =
Expand All @@ -581,14 +585,15 @@ let create_fsevents ?(latency = 0.2) ~(scheduler : Scheduler.t) () =
Option.map (Fs_sync.consume_event sync_table path) ~f:(fun id ->
Event.Sync id)))
in
let on_event = fsevents_standard_event ~should_exclude in
let source =
let paths = [ Path.root ] in
let exclusion_paths =
Path.(build Build.root)
:: ([ "_esy"; "_opam"; ".git"; ".hg" ]
|> List.rev_map ~f:(Path.relative (Path.source Path.Source.root)))
in
fsevents ~latency scheduler ~exclusion_paths ~paths fsevents_standard_event
fsevents ~latency scheduler ~exclusion_paths ~paths on_event
in
let cv = Condition.create () in
let dispatch_queue_ref = ref None in
Expand All @@ -613,7 +618,8 @@ let create_fsevents ?(latency = 0.2) ~(scheduler : Scheduler.t) () =
Mutex.unlock mutex;
Option.value_exn !dispatch_queue_ref
in
{ kind = Fsevents { latency; scheduler; sync; source; external_; dispatch_queue }
{ kind =
Fsevents { latency; scheduler; sync; source; external_; dispatch_queue; on_event }
; sync_table
}
;;
Expand Down Expand Up @@ -684,7 +690,7 @@ let create_default ?fsevents_debounce ~watch_exclusions ~scheduler () =
~debounce_interval:(Some 0.5 (* seconds *))
~backend
~watch_exclusions
| `Fsevents -> create_fsevents ?latency:fsevents_debounce ~scheduler ()
| `Fsevents -> create_fsevents ?latency:fsevents_debounce ~scheduler ~should_exclude ()
| `Inotify_lib -> create_inotifylib ~scheduler ~should_exclude
| `Fswatch_win ->
create_fswatch_win
Expand Down Expand Up @@ -729,12 +735,7 @@ let add_watch t path =
| None -> Ok ()
| Some ext ->
let watch =
lazy
(fsevents
~latency:f.latency
f.scheduler
~paths:[ path ]
fsevents_standard_event)
lazy (fsevents ~latency:f.latency f.scheduler ~paths:[ path ] f.on_event)
in
(match Watch_trie.add f.external_ ext watch with
| Watch_trie.Under_existing_node -> Ok ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let%expect_test _ =
test "dir/#file#";
test "dir/#subdir#/file";
test ".#file";
test ".#foobar.ml";
test "dir/.#file";
test "dir/.#subdir/file";
[%expect
Expand All @@ -40,6 +41,7 @@ let%expect_test _ =
should_exclude(dir/#file#) = true
should_exclude(dir/#subdir#/file) = false
should_exclude(.#file) = true
should_exclude(.#foobar.ml) = true
should_exclude(dir/.#file) = true
should_exclude(dir/.#subdir/file) = true
|}]
Expand Down
Loading