Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let sandbox_action dap =
Lwt_io.fprintf output "%s\n%s\n%s\n" data (String.concat ", " listing) static)
;;

let detached_action dap state ~cancel =
let detached_sandbox_action dap state ~cancel =
let open Lwt.Syntax in
let* () =
Lwt_io.with_file ~mode:Output (Filename.concat state "pid") (fun output ->
Expand Down Expand Up @@ -108,6 +108,28 @@ let absolute_path path =
if Filename.is_relative path then Filename.concat (Sys.getcwd ()) path else path
;;

let detached_action dap =
let open Lwt.Syntax in
let* () =
Lwt_io.with_file ~mode:Output "parent-pid" (fun output ->
Lwt_io.fprintf output "%d" (Unix.getpid ()))
in
let rec wait_started () =
if Sys.file_exists "started"
then Lwt.return_unit
else
let* () = Lwt_unix.sleep 0.01 in
wait_started ()
in
let* () =
Lwt.choose [ Lwt.map ignore (read_file dap ~path:"slow-input"); wait_started () ]
in
let* () =
Lwt_io.with_file ~mode:Output "detached" (fun output -> Lwt_io.write output "done")
in
Lwt_io.printl "ran"
;;

let change_dir dir =
if not (Sys.file_exists dir) then Unix.mkdir dir 0o755;
Sys.chdir dir
Expand Down Expand Up @@ -178,11 +200,12 @@ let action dap =
| [| _ |] -> ordinary_action dap ~path:"some_dependency"
| [| _; "read"; path |] -> ordinary_action dap ~path
| [| _; "sandbox" |] -> sandbox_action dap
| [| _; "detached"; state |] -> detached_action dap state ~cancel:false
| [| _; "cancelled"; state |] -> detached_action dap state ~cancel:true
| [| _; "detached"; state |] -> detached_sandbox_action dap state ~cancel:false
| [| _; "cancelled"; state |] -> detached_sandbox_action dap state ~cancel:true
| [| _; "hold"; connection; release |] -> held_action dap ~connection ~release
| [| _; "initialize" |] -> Lwt.return_unit
| [| _; "exit"; code |] -> exit (int_of_string code)
| [| _; "detached" |] -> detached_action dap
| _ -> invalid_arg "invalid arguments"
;;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
A request can outlive the plugin process. The dependency waits for its caller to
exit, so it cannot be recorded before the plugin finishes.

$ cat > dune-project <<'EOF'
> (lang dune 2.0)
> (using action-plugin 0.1)
> EOF
$ cp bin/foo.exe .
$ printf first > control
$ cat > dune <<'EOF'
> (rule
> (target slow-input)
> (deps control)
> (action
> (run sh -c "touch started; while kill -0 $(cat parent-pid 2>/dev/null) 2>/dev/null; do sleep 0.01; done; cat control > slow-input")))
> (rule
> (target detached)
> (action (dynamic-run ./foo.exe detached)))
> EOF
$ timeout 5 dune build -j 2 detached
ran

Accepted requests are drained before the rule is cached, even if their client
has disconnected. Their dependencies continue to invalidate the rule.

$ printf second > control
$ timeout 5 dune build -j 2 detached
ran
$ printf third > control
$ timeout 5 dune build -j 2 detached
ran
Loading