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

Work with fsevents/cf libs #31

Merged
merged 2 commits into from
Apr 26, 2021
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
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Main workflow

on:
- pull_request
- push

jobs:
build:
strategy:
fail-fast: false
matrix:
os:
- macos-latest
ocaml-version:
- 4.12.0
- 4.11.1
- 4.10.2
- 4.09.1
- 4.08.1

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use OCaml ${{ matrix.ocaml-version }}
uses: avsm/setup-ocaml@v1
with:
ocaml-version: ${{ matrix.ocaml-version }}
- run: opam pin add . --no-action
- run: opam depext irmin-watcher --yes --with-doc --with-test
- run: opam install . --deps-only --with-doc --with-test
- run: opam exec -- dune build
- run: opam exec -- dune runtest
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 0.14.2
version = 0.18.0
break-infix = fit-or-vertical
parse-docstrings = true
indicate-multiline-delimiters = no
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### dev

- Switch to GitHub Actions from Travis (#31, @avsm)
- Initialise backends only when needed via a
lazy watcher interface (#31, @samoht @avsm)
- Use fsevents and cf-lwt packages (#31, @avsm)
- Use ocamlformat.0.18.0 (#31, @avsm)

### 0.4.1 (2019-07-02)

- Clearer name for hook logger (@talex5, #21)
Expand Down
16 changes: 12 additions & 4 deletions irmin-watcher.opam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bug-reports: "https://github.com/mirage/irmin-watcher/issues"
license: "ISC"

build: [
["dune" "subst"] {pinned}
["dune" "subst"] {dev}
["dune" "build" "-p" name "-j" jobs]
]

Expand All @@ -23,16 +23,24 @@ depends: [
"logs"
"fmt"
"astring"
"inotify" {os = "linux"}
"osx-fsevents" {os = "macos" & >= "0.2.0"}
"inotify" {os = "linux"}
"cf-lwt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"cf-lwt"
"cf-lwt" {os = "macos"}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually not needed any more -- I modified the dependent libraries to be optional but installable on Linux, so it'll work in a duniverse. So they can be firm dependencies now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to not force these dependencies if possible (to avoid future compilation issues on Linux due to unrelated issues on macos).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need it to work in a duniverse though. The non-macOS builds don't do anything on Linux at all -- i used enabled_if to just not compile them when system <> macOS. https://github.com/mirage/ocaml-cf/blob/main/lib/dune#L7

So the whole dependency should be a noop if os != macos (but it will jsut work if irmin-watcher is cloned into a duniverse and compiled on a mac)

"fsevents-lwt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"fsevents-lwt"
"fsevents-lwt" {os = "macos"}

]

synopsis: "Portable Irmin watch backends using FSevents or Inotify"
description: """
irmin-watcher implements [Irmin's watch hooks][watch] for various OS,
using FSevents in OSX and Inotify on Linux.
using FSevents in macOS and Inotify on Linux.

irmin-watcher is distributed under the ISC license.

[watch]: http://mirage.github.io/irmin/irmin/Irmin/Private/Watch/index.html#type-hook
"""

pin-depends: [
[ "fsevents.dev" "git+https://github.com/mirage/ocaml-fsevents.git#f9e797e16bdbc730804cd684f07808022495c333" ]
[ "fsevents-lwt.dev" "git+https://github.com/mirage/ocaml-fsevents.git#f9e797e16bdbc730804cd684f07808022495c333" ]
[ "cf.dev" "git+https://github.com/mirage/ocaml-cf.git#918e2b9a7ab6871e48cce0508bce5e45981375f6" ]
[ "cf-lwt.dev" "git+https://github.com/mirage/ocaml-cf.git#918e2b9a7ab6871e48cce0508bce5e45981375f6" ]
]
2 changes: 1 addition & 1 deletion src/backend.fsevents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ let v =
stop_runloop () >>= fun () ->
unlisten () >>= fun () -> unpoll ()
in
Core.create listen
lazy (Core.create listen)

let mode = `FSEvents

Expand Down
2 changes: 1 addition & 1 deletion src/backend.fsevents.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{e %%VERSION%% — {{:%%PKG_HOMEPAGE%%} homepage}} *)

val v : Core.t
val v : Core.t Lazy.t
(** [v id p f] is the hook calling [f] everytime a sub-path of [p] is modified.
Return a function to call to remove the hook. Use the FSevent framework to
be notified on filesystem changes. *)
Expand Down
2 changes: 1 addition & 1 deletion src/backend.inotify.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let v =
stop_watch () >>= fun () ->
unlisten () >>= fun () -> unpoll ()
in
Core.create listen
lazy (Core.create listen)

let mode = `Inotify

Expand Down
2 changes: 1 addition & 1 deletion src/backend.inotify.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{e %%VERSION%% — {{:%%PKG_HOMEPAGE%%} homepage}} *)

val v : Core.t
val v : Core.t Lazy.t
(** [v id p f] is the hook calling [f] everytime a sub-path of [p] is modified.
Return a function to call to remove the hook. Use inofity to be notified on
filesystem changes. *)
Expand Down
4 changes: 2 additions & 2 deletions src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
(select
backend.ml
from
(osx-cf.lwt osx-fsevents.lwt -> backend.fsevents.ml)
(cf-lwt fsevents-lwt -> backend.fsevents.ml)
(inotify.lwt -> backend.inotify.ml)
(lwt.unix -> backend.polling.ml))
(select
backend.mli
from
(osx-cf.lwt osx-fsevents.lwt -> backend.fsevents.mli)
(cf-lwt fsevents-lwt -> backend.fsevents.mli)
(inotify.lwt -> backend.inotify.mli)
(lwt.unix -> backend.polling.mli))))
2 changes: 1 addition & 1 deletion src/irmin_watcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%%NAME%% %%VERSION%%
---------------------------------------------------------------------------*)

let v = Backend.v
let v = Lazy.force Backend.v

let mode = (Backend.mode :> [ `FSEvents | `Inotify | `Polling ])

Expand Down
10 changes: 6 additions & 4 deletions src/polling.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ let src = Logs.Src.create "irw-polling" ~doc:"Irmin watcher using using polling"

module Log = (val Logs.src_log src : Logs.LOG)

let with_delay delay =
let listen ~wait_for_changes dir =
Log.info (fun l -> l "Polling mode");
Hook.v ~wait_for_changes ~dir

let with_delay delay =
let wait_for_changes () = Lwt_unix.sleep delay >|= fun () -> `Unknown in
Core.create (fun dir -> Hook.v ~wait_for_changes ~dir)
Core.create (listen ~wait_for_changes)

let mode = `Polling

let v =
Log.info (fun l -> l "Polling mode");
let wait_for_changes () =
Lwt_unix.sleep !Core.default_polling_time >|= fun () -> `Unknown
in
Core.create (fun dir -> Hook.v ~wait_for_changes ~dir)
lazy (Core.create (listen ~wait_for_changes))

(*---------------------------------------------------------------------------
Copyright (c) 2016 Thomas Gazagnaire
Expand Down
2 changes: 1 addition & 1 deletion src/polling.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val with_delay : float -> t
[p] is modified. Return a function to call to remove the hook. Active
polling is done every [delay] seconds. *)

val v : t
val v : t Lazy.t
(** [v] is [with_delay !default_polling_time]. *)

val mode : [ `Polling ]
Expand Down
8 changes: 7 additions & 1 deletion test/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
(test
(executable
(name test)
(libraries alcotest logs.fmt irmin-watcher mtime mtime.clock.os))

(rule
(alias runtest)
(deps test.exe)
(action
(run ./test.exe -q --color=always)))
4 changes: 2 additions & 2 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let write f d =
let move a b = Unix.rename (tmpdir / a) (tmpdir / b)

let remove f =
try Unix.unlink (tmpdir / f) with e -> Alcotest.fail @@ Printexc.to_string e
try Unix.unlink (tmpdir / f) with e -> Alcotest.fail (Printexc.to_string e)

let poll ~mkdir:m i () =
if m then mkdir tmpdir;
Expand Down Expand Up @@ -109,7 +109,7 @@ let polling_tests =
("enoent", `Quick, run (poll ~mkdir:false 0));
("basic", `Quick, run (poll ~mkdir:true 0));
("100s", `Quick, run (random_polls 100));
("1000s", `Quick, run (random_polls 1000));
("1000s", `Slow, run (random_polls 1000));
]

let mode =
Expand Down