-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add native polling mode support on Windows (#7010)
Co-authored-by: Uma Kothuri <[email protected]> Signed-off-by: Uma Kothuri <[email protected]> Signed-off-by: nojebar <[email protected]>
- Loading branch information
Showing
13 changed files
with
1,030 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
;; A little binary to test out Windows file watcher library | ||
|
||
(executable | ||
(name dune_fswatch_win) | ||
(libraries fswatch_win stdune dyn)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
open! Stdune | ||
|
||
let paths = | ||
let paths = ref [] in | ||
let anon p = paths := p :: !paths in | ||
Arg.parse [] anon "dune_fswatch_win [path]+"; | ||
List.rev !paths | ||
|
||
let () = | ||
let t = Fswatch_win.create () in | ||
List.iter ~f:(Fswatch_win.add t) paths; | ||
let f event = | ||
Printf.printf "%s\n%!" (Dyn.to_string (Fswatch_win.Event.to_dyn event)) | ||
in | ||
while true do | ||
List.iter ~f (Fswatch_win.wait t ~sleep:500) | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(library | ||
(name fswatch_win) | ||
(libraries stdune dune_util) | ||
(foreign_stubs | ||
(language c) | ||
(names fswatch_win_stubs))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Event = struct | ||
type action = | ||
| Added | ||
| Removed | ||
| Modified | ||
| Renamed_old | ||
| Renamed_new | ||
|
||
type t = | ||
{ directory : string | ||
; path : string | ||
; action : action | ||
} | ||
|
||
let directory t = t.directory | ||
|
||
let path t = t.path | ||
|
||
let action t = t.action | ||
|
||
let dyn_of_action = function | ||
| Added -> Dyn.variant "Added" [] | ||
| Removed -> Dyn.variant "Removed" [] | ||
| Modified -> Dyn.variant "Modified" [] | ||
| Renamed_old -> Dyn.variant "Renamed_old" [] | ||
| Renamed_new -> Dyn.variant "Renamed_new" [] | ||
|
||
let to_dyn t = | ||
Dyn.record | ||
[ ("directory", Dyn.string t.directory) | ||
; ("path", Dyn.String t.path) | ||
; ("action", dyn_of_action t.action) | ||
] | ||
end | ||
|
||
type t | ||
|
||
external create : unit -> t = "fswatch_win_create" | ||
|
||
external wait : t -> sleep:int -> Event.t list = "fswatch_win_wait" | ||
|
||
external add : t -> string -> unit = "fswatch_win_add" | ||
|
||
let wait t ~sleep = | ||
List.filter | ||
(function | ||
| { Event.action = Modified; path; directory } -> ( | ||
try not (Sys.is_directory (Filename.concat directory path)) | ||
with Sys_error _ -> true) | ||
| _ -> true) | ||
(wait t ~sleep) | ||
|
||
external shutdown : t -> unit = "fswatch_win_shutdown" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(** File-watching support under Windows *) | ||
|
||
module Event : sig | ||
(** The type of events *) | ||
type action = | ||
| Added (** The file was added. *) | ||
| Removed (** The file was removed. *) | ||
| Modified (** The file was modified. *) | ||
| Renamed_old | ||
(** The file was renamed. This corresponds to the old name. *) | ||
| Renamed_new | ||
(** The file was renamed. This corresponds to the new name. *) | ||
|
||
type t | ||
|
||
(** The directory being watched. *) | ||
val directory : t -> string | ||
|
||
(** The path to the file relevant to the event. Relative to the directory | ||
being watched (see {!directory}). *) | ||
val path : t -> string | ||
|
||
(** The description of the event action. *) | ||
val action : t -> action | ||
|
||
(** For debugging. *) | ||
val to_dyn : t -> Dyn.t | ||
end | ||
|
||
(** The type of file watchers. Each file watcher can watch an arbitrary | ||
collection of directories. Multiple file watchers can be used | ||
simultaneously, if needed. *) | ||
type t | ||
|
||
(** Create a file watcher. This creates a native thread that will monitor for | ||
changes in the background. *) | ||
val create : unit -> t | ||
|
||
(** Start watching a directory for changes. The watching is recursive: all | ||
subdirectories are watched as well. Watching a single file is not possible. *) | ||
val add : t -> string -> unit | ||
|
||
(** Wait for events. This function will block until it receives some file change | ||
notifications. After it receives a notification, it will wait for [sleep] | ||
milliseconds before retrieving them and returning them to the user. This is | ||
done to avoid triggering multiple rebuilds in close succession. *) | ||
val wait : t -> sleep:int -> Event.t list | ||
|
||
(** Shutdown the file watcher. This tears down the background thread and frees | ||
all allocated resources. It is an error to call [add] or [wait] after this | ||
function returns. *) | ||
val shutdown : t -> unit |
Oops, something went wrong.