Skip to content

Commit

Permalink
Rely on #use_command rather than installing a dune.top file
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremie Dimino <[email protected]>
  • Loading branch information
jeremiedimino committed Mar 24, 2020
1 parent 3527f53 commit 622ae66
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 40 deletions.
11 changes: 0 additions & 11 deletions bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@
(files
(dune.exe as dune)))

(install
(section lib_root)
(package dune)
(files
(dune.top as ocaml/dune.top)))

(install
(section toplevel)
(package dune)
(files dune.top))

(deprecated_library_name
(old_public_name dune.configurator)
(new_public_name dune-configurator))
26 changes: 0 additions & 26 deletions bin/dune.top

This file was deleted.

8 changes: 5 additions & 3 deletions test/blackbox-tests/test-cases/toplevel-integration/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Test toplevel-init-file on a tiny project

$ ocaml -stdin <<EOF
> #use "topfind";;
> #use "dune.top";;
> #use "use_output_compat";;
> #use_output "dune toplevel-init-file";;
> Test.Main.hello ();;
> EOF
hello
Expand All @@ -39,10 +40,11 @@ Test toplevel-init-file on a tiny project

$ ocaml -stdin <<EOF
> #use "topfind";;
> #use "dune.top";;
> #use "use_output_compat";;
> #use_output "dune toplevel-init-file";;
> EOF
File "error.ml", line 1, characters 14-32:
1 | let oops () = undefined_function ()
^^^^^^^^^^^^^^^^^^
Error: Unbound value undefined_function
Exception: AbnormalExit ("dune toplevel-init-file", 1).
Command exited with code 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(* -*- tuareg -*- *)

let try_finally ~always f =
match f () with
| x ->
always ();
x
| exception e ->
always ();
raise e

let use_output command =
let fn = Filename.temp_file "ocaml" "_toploop.ml" in
try_finally
~always:(fun () -> try Sys.remove fn with Sys_error _ -> ())
(fun () ->
match
Printf.ksprintf Sys.command "%s > %s" command (Filename.quote fn)
with
| 0 -> ignore (Toploop.use_file Format.std_formatter fn : bool)
| n -> Format.printf "Command exited with code %d.@." n)

let () =
let name = "use_output" in
if not (Hashtbl.mem Toploop.directive_table name) then
Hashtbl.add Toploop.directive_table name
(Toploop.Directive_string use_output)

0 comments on commit 622ae66

Please sign in to comment.