Add Which_program to know whether we are dune or jbuilder

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
Jeremie Dimino 2018-06-27 18:21:02 +01:00 committed by Jérémie Dimino
parent 9585c8f79d
commit 16d34f4a07
19 changed files with 75 additions and 14 deletions

View File

@ -90,7 +90,7 @@ case "$TARGET" in
echo -en "travis_fold:end:dune.bootstrap\r"
./boot.exe --subst
echo -en "travis_fold:start:dune.boot\r"
./boot.exe --dev
./boot.exe
echo -en "travis_fold:end:dune.boot\r"
if [ $WITH_OPAM -eq 1 ] ; then
_build/install/default/bin/dune runtest && \

View File

@ -1,5 +1,5 @@
INSTALL_ARGS := $(if $(PREFIX),--prefix $(PREFIX),)
BIN := ./_build/default/bin/main.exe
BIN := ./_build/default/bin/main_dune.exe
-include Makefile.dev

View File

@ -1,11 +1,20 @@
(library
(name main)
(modules (main))
(libraries unix dune cmdliner))
(executable
(name main)
(name main_dune)
(public_name dune)
(package dune)
(libraries unix dune cmdliner)
(modules (main_dune))
(libraries which_program_dune main)
(preprocess no_preprocessing))
(install
(section bin)
(package dune)
(files (main.exe as jbuilder)))
(executable
(name main_jbuilder)
(public_name jbuilder)
(package dune)
(modules (main_jbuilder))
(libraries which_program_jbuilder main)
(preprocess no_preprocessing))

View File

@ -1538,7 +1538,7 @@ let default =
]
)
let () =
let main () =
Colors.setup_err_formatter_colors ();
try
match Term.eval_choice default all ~catch:false with

View File

@ -1 +1 @@
(* empty *)
val main : unit -> unit

1
bin/main_dune.ml Normal file
View File

@ -0,0 +1 @@
let () = Main.main ()

1
bin/main_dune.mli Normal file
View File

@ -0,0 +1 @@
(* empty *)

1
bin/main_jbuilder.ml Normal file
View File

@ -0,0 +1 @@
let () = Main.main ()

1
bin/main_jbuilder.mli Normal file
View File

@ -0,0 +1 @@
(* empty *)

View File

@ -29,7 +29,8 @@ end
(* Directories with library names *)
let dirs =
[ "src/stdune/caml" , Some "Caml"
[ "src/which_program" , Some "Which_program"
; "src/stdune/caml" , Some "Caml"
; "src/stdune" , Some "Stdune"
; "src/fiber" , Some "Fiber"
; "src/xdg" , Some "Xdg"

14
src/which_program/dune Normal file
View File

@ -0,0 +1,14 @@
(library
(name which_program)
(public_name dune.which-program)
(synopsis "[Internal] Standard library of Dune")
(wrapped false)
(flags (:standard (:include no-keep-locs)))
(modules_without_implementation which_program))
; To avoid issues on Windows and OSX
(rule (with-stdout-to which_program_dummy.ml (echo "")))
(rule
(with-stdout-to no-keep-locs
(run %{OCAML} %{path:gen-no-keep-locs} %{ocaml_version})))

View File

@ -0,0 +1,7 @@
(library
(name which_program_dune)
(public_name dune.which-program.dune)
(wrapped false)
(flags (:standard (:include ../no-keep-locs))))
(rule (copy# ../which_program.mli which_program.mli))

View File

@ -0,0 +1,2 @@
type t = Dune | Jbuilder
let t = Dune

View File

@ -0,0 +1,8 @@
(* -*- tuared -*- *)
let () =
let ver = Scanf.sscanf Sys.argv.(1) "%u.%u" (fun a b -> a, b) in
if ver >= (4, 03) then
print_endline "(-no-keep-locs)"
else
print_endline "()"

View File

@ -0,0 +1,7 @@
(library
(name which_program_jbuilder)
(public_name dune.which-program.jbuilder)
(wrapped false)
(flags (:standard (:include ../no-keep-locs))))
(rule (copy# ../which_program.mli which_program.mli))

View File

@ -0,0 +1,2 @@
type t = Dune | Jbuilder
let t = Jbuilder

View File

@ -0,0 +1,2 @@
type t = Dune | Jbuilder
let t = Dune

View File

@ -0,0 +1,5 @@
(** Whether we are 'dune' or 'jbuilder' *)
type t = Dune | Jbuilder
val t : t

View File

@ -12,11 +12,11 @@
ocamlopt test$ext_dll
$ dune build @runtest
dynamic alias runtest
OK: ./dynamic.exe ./test$ext_dll
static alias runtest
OK: ./static.bc
dynamic alias runtest
OK: ./dynamic.exe ./test.bc.so
static alias runtest
OK: ./static.exe
dynamic alias runtest
OK: ./dynamic.exe ./test$ext_dll
OK: ./dynamic.exe ./test.bc.so