-
Notifications
You must be signed in to change notification settings - Fork 12
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
Switch Inotify to irmin-watcher #65
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
open Lwt.Syntax | ||
|
||
(* A promise that never returns and consumes a file | ||
unwatcher *) | ||
let wait_forever (_unwatch : unit -> unit Lwt.t) = | ||
let forever, _ = Lwt.wait () in | ||
forever | ||
|
||
let do_watch input f = | ||
match input with | ||
| `Stdin -> Error (`Msg "--watch is incompatible with stdin input") | ||
| `File input -> | ||
let parent = Fpath.parent input in | ||
let parent = Fpath.to_string parent in | ||
let input_filename = Fpath.filename input in | ||
let inotify = Inotify.create () in | ||
let _watch_descriptor = | ||
Inotify.add_watch inotify parent [ Inotify.S_Close_write ] | ||
let callback filename = | ||
if String.equal filename input_filename then ( | ||
Logs.app (fun m -> m "Recompiling"); | ||
match f () with | ||
| Ok _ -> Lwt.return_unit | ||
| Error (`Msg s) -> | ||
Logs.warn (fun m -> m "%s" s); | ||
Lwt.return_unit) | ||
else Lwt.return_unit | ||
in | ||
let rec loop () = | ||
let events = Inotify.read inotify in | ||
List.iter | ||
(function | ||
| _, _, _, Some filename -> | ||
if String.equal filename input_filename then ( | ||
Logs.app (fun m -> m "Recompiling"); | ||
match f () with | ||
| Ok _ -> () | ||
| Error (`Msg s) -> Logs.warn (fun m -> m "%s" s)) | ||
else () | ||
| _ -> ()) | ||
events; | ||
loop () | ||
let main = | ||
let* unwatch = Irmin_watcher.hook 0 parent callback in | ||
wait_forever unwatch | ||
in | ||
loop () | ||
Lwt_main.run main | ||
|
||
let html_source = | ||
Format.sprintf | ||
|
@@ -51,7 +54,7 @@ let html_source = | |
</body> | ||
</html> | ||
|html} | ||
[%blob "compiler/src/bin/native/client/client.bc.js"] | ||
[%blob "client/client.bc.js"] | ||
Comment on lines
-54
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm it seems to work in both situation, is it some There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The long form doesn't work when you vendor (in the dune sense) slipshow ^^" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes! I understand. Thanks for the explanation :) |
||
|
||
let do_serve input f = | ||
let cond = Lwt_condition.create () in | ||
|
@@ -64,10 +67,6 @@ let do_serve input f = | |
let parent = Fpath.parent input in | ||
let parent = Fpath.to_string parent in | ||
let input_filename = Fpath.filename input in | ||
let* inotify = Lwt_inotify.create () in | ||
let _watch_descriptor = | ||
Lwt_inotify.add_watch inotify parent [ Inotify.S_Close_write ] | ||
in | ||
let content = ref "" in | ||
let new_content = | ||
match f () with | ||
|
@@ -92,26 +91,22 @@ let do_serve input f = | |
Dream.respond !content); | ||
] | ||
in | ||
let rec loop () = | ||
let* _descriptor, _event_kinds, _, filename = | ||
Lwt_inotify.read inotify | ||
in | ||
match filename with | ||
| Some filename when String.equal filename input_filename -> | ||
Logs.app (fun m -> m "Recompiling"); | ||
let new_content = | ||
match f () with | ||
| Ok s -> Slipshow.delayed_to_string s | ||
| Error (`Msg s) -> | ||
Logs.warn (fun m -> m "%s" s); | ||
s | ||
in | ||
content := new_content; | ||
Lwt_condition.broadcast cond (); | ||
loop () | ||
| _ -> loop () | ||
let callback filename = | ||
if String.equal filename input_filename then ( | ||
Logs.app (fun m -> m "Recompiling"); | ||
let new_content = | ||
match f () with | ||
| Ok s -> Slipshow.delayed_to_string s | ||
| Error (`Msg s) -> | ||
Logs.warn (fun m -> m "%s" s); | ||
s | ||
in | ||
content := new_content; | ||
Lwt_condition.broadcast cond ()); | ||
Lwt.return_unit | ||
in | ||
loop () | ||
let* unwatch = Irmin_watcher.hook 0 parent callback in | ||
wait_forever unwatch | ||
in | ||
Logs.app (fun m -> | ||
m | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
base64 | ||
bos | ||
lwt | ||
inotify | ||
irmin-watcher | ||
js_of_ocaml-compiler | ||
js_of_ocaml-lwt | ||
magic-mime | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the dune manual,
(file <filename>)
and<filename>
is the same. What is the reason to prefer on to the other?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that was from testing the ppx_blob issue I mentioned above