Skip to content

Commit

Permalink
Self destruct ocamlscript executables
Browse files Browse the repository at this point in the history
Changing a module that the script depends on does not cause recompilation of
the OCamlscript script. This is a known issue with OCamlscript[1] and this
patch works around this by unlinking the auto-generated binary after it has
finished executing its main Lwt thread.

[1]: ocaml-community/ocamlscript#2

Signed-off-by: Si Beaumont <[email protected]>
  • Loading branch information
simonjbeaumont committed Sep 3, 2015
1 parent d93d67b commit 97ee386
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
16 changes: 16 additions & 0 deletions tests/test_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,19 @@ let get_control_domain state host =
(fun (vm_ref, vm_rec) ->
vm_rec.API.vM_resident_on=host && vm_rec.API.vM_is_control_domain)
vms |> fst |> Lwt.return

let run_and_self_destruct (t : 'a Lwt.t) : 'a =
let t' =
Lwt.finalize (fun () -> t) (fun () ->
let name = Sys.argv.(0) in
let ocamlscipt_exe =
if Filename.check_suffix name "exe" then name else name ^ ".exe" in
if (try Unix.(access ocamlscipt_exe [ F_OK ]); true with _ -> false)
then
Lwt_io.printlf "Unlinking ocamlscript compilation: %s" ocamlscipt_exe
>>= fun () ->
Lwt_unix.unlink ocamlscipt_exe
else return ()
)
in
Lwt_main.run t'
6 changes: 1 addition & 5 deletions tests/test_quicktest
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ let _ =
Printf.printf "Quicktest has run!\n%!";
Lwt.return ()
in
Lwt_main.run th;
run_and_self_destruct th;

(* Local Variables: *)
(* mode: tuareg *)
(* End: *)




6 changes: 1 addition & 5 deletions tests/test_thin_lvhd
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,8 @@ let _ =
>>= fun () ->
Lwt.return ()
in
Lwt_main.run th;
run_and_self_destruct th;

(* Local Variables: *)
(* mode: tuareg *)
(* End: *)




0 comments on commit 97ee386

Please sign in to comment.