From b7184e017e016ffaca38244d02bbb252a5e005e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Hinderer?= Date: Mon, 19 Feb 2018 08:23:12 +0100 Subject: [PATCH] ocamltest: complete and clarify support for runtime flags --- ocamltest/ocaml_backends.ml | 4 ++++ ocamltest/ocaml_backends.mli | 4 ++++ ocamltest/ocaml_directories.ml | 6 +++++ ocamltest/ocaml_directories.mli | 2 ++ ocamltest/ocaml_flags.ml | 42 ++++++++++++++++----------------- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/ocamltest/ocaml_backends.ml b/ocamltest/ocaml_backends.ml index 552220636..71e75a49e 100644 --- a/ocamltest/ocaml_backends.ml +++ b/ocamltest/ocaml_backends.ml @@ -17,6 +17,10 @@ type t = Native | Bytecode +let is_bytecode t = t=Bytecode + +let is_native t = t=Native + let string_of_backend = function | Native -> "native" | Bytecode -> "bytecode" diff --git a/ocamltest/ocaml_backends.mli b/ocamltest/ocaml_backends.mli index 8b8354303..5cc48e858 100644 --- a/ocamltest/ocaml_backends.mli +++ b/ocamltest/ocaml_backends.mli @@ -17,6 +17,10 @@ type t = Native | Bytecode +val is_bytecode : t -> bool + +val is_native : t -> bool + val string_of_backend : t -> string val make_backend_function : 'a -> 'a -> t -> 'a diff --git a/ocamltest/ocaml_directories.ml b/ocamltest/ocaml_directories.ml index 064fd57cb..f33880075 100644 --- a/ocamltest/ocaml_directories.ml +++ b/ocamltest/ocaml_directories.ml @@ -29,3 +29,9 @@ let toplevel ocamlsrcdir = let runtime ocamlsrcdir = Filename.make_path [ocamlsrcdir; "byterun"] + +let runtime_library backend ocamlsrcdir = + let backend_lib_dir = match backend with + | Ocaml_backends.Native -> "asmrun" + | Ocaml_backends.Bytecode -> "byterun" in + Filename.make_path [ocamlsrcdir; backend_lib_dir] diff --git a/ocamltest/ocaml_directories.mli b/ocamltest/ocaml_directories.mli index 2d25d64f5..c7bb5b2df 100644 --- a/ocamltest/ocaml_directories.mli +++ b/ocamltest/ocaml_directories.mli @@ -22,3 +22,5 @@ val stdlib : string -> string val toplevel : string -> string val runtime : string -> string + +val runtime_library : Ocaml_backends.t -> string -> string diff --git a/ocamltest/ocaml_flags.ml b/ocamltest/ocaml_flags.ml index bff8756d1..a9266bbc3 100644 --- a/ocamltest/ocaml_flags.ml +++ b/ocamltest/ocaml_flags.ml @@ -26,25 +26,23 @@ let c_includes ocamlsrcdir = let dir = Ocaml_directories.runtime ocamlsrcdir in "-ccopt -I" ^ dir -let runtime_flags ocamlsrcdir backend c_files = match backend with - | Ocaml_backends.Native -> "" - | Ocaml_backends.Bytecode -> - if c_files then begin (* custm mode *) - let runtime_variant = Ocaml_files.runtime_variant() in - let variant_flag = match runtime_variant with - | Ocaml_files.Normal -> "" - | Ocaml_files.Debug -> " -runtime-variant d" - | Ocaml_files.Instrumented -> " -runtime-variant i" in - "-custom" ^ variant_flag ^ " -I " ^ - (Ocaml_directories.runtime ocamlsrcdir) - (* when using the debug or instrumented runtimes, we need to include - the byterun directory so that libcamlrund and libcamlruni - can be found. This is not necessary with the normal runtime - because libcamlrun is copied to the stdlib directory which - will be included anyway - *) - end else begin (* non-custom mode *) - let ocamlrun = Ocaml_files.ocamlrun ocamlsrcdir in - "-use-runtime " ^ ocamlrun - end - \ No newline at end of file +let runtime_variant_flags () = match Ocaml_files.runtime_variant() with + | Ocaml_files.Normal -> "" + | Ocaml_files.Debug -> " -runtime-variant d" + | Ocaml_files.Instrumented -> " -runtime-variant i" + +let runtime_flags ocamlsrcdir backend c_files = + let runtime_library_flags = "-I " ^ + (Ocaml_directories.runtime_library backend ocamlsrcdir) in + let rt_flags = match backend with + | Ocaml_backends.Native -> runtime_variant_flags () + | Ocaml_backends.Bytecode -> + begin + if c_files then begin (* custom mode *) + "-custom " ^ (runtime_variant_flags ()) + end else begin (* non-custom mode *) + "-use-runtime " ^ (Ocaml_files.ocamlrun ocamlsrcdir) + end + end in + rt_flags ^ " " ^ runtime_library_flags + \ No newline at end of file