diff options
author | David Allsopp <david.allsopp@metastack.com> | 2022-03-01 20:54:22 +0000 |
---|---|---|
committer | David Allsopp <david.allsopp@metastack.com> | 2022-03-01 20:54:22 +0000 |
commit | a577d4df12b5cc4dee8867f898121007fb36c472 (patch) | |
tree | 79fe6a4bf85c01b97f0d0ba8ca4f5b6a19021041 /toplevel | |
parent | 074c2d15aeada786d6122eb400f34aa488bbde69 (diff) | |
download | ocaml-a577d4df12b5cc4dee8867f898121007fb36c472.tar.gz |
Factor out reading OCAMLTOP_INCLUDE_PATH
Diffstat (limited to 'toplevel')
-rw-r--r-- | toplevel/byte/topmain.ml | 9 | ||||
-rw-r--r-- | toplevel/native/topmain.ml | 9 | ||||
-rw-r--r-- | toplevel/topcommon.ml | 7 | ||||
-rw-r--r-- | toplevel/topcommon.mli | 5 |
4 files changed, 14 insertions, 16 deletions
diff --git a/toplevel/byte/topmain.ml b/toplevel/byte/topmain.ml index 15a4000f98..e590c2f639 100644 --- a/toplevel/byte/topmain.ml +++ b/toplevel/byte/topmain.ml @@ -200,17 +200,10 @@ module Options = Main_args.Make_bytetop_options (struct let _eval s = input_argument (Toploop.String s) end) -let () = - let extra_paths = - match Sys.getenv "OCAMLTOP_INCLUDE_PATH" with - | exception Not_found -> [] - | s -> Misc.split_path_contents s - in - Clflags.include_dirs := List.rev_append extra_paths !Clflags.include_dirs - let main () = let ppf = Format.err_formatter in let program = "ocaml" in + Topcommon.update_search_path_from_env (); Compenv.readenv ppf Before_args; Clflags.add_arguments __LOC__ Options.list; Compenv.parse_arguments ~current argv file_argument program; diff --git a/toplevel/native/topmain.ml b/toplevel/native/topmain.ml index fc647359a5..15f25b22c7 100644 --- a/toplevel/native/topmain.ml +++ b/toplevel/native/topmain.ml @@ -92,18 +92,11 @@ module Options = Main_args.Make_opttop_options (struct end) -let () = - let extra_paths = - match Sys.getenv "OCAMLTOP_INCLUDE_PATH" with - | exception Not_found -> [] - | s -> Misc.split_path_contents s - in - Clflags.include_dirs := List.rev_append extra_paths !Clflags.include_dirs - let main () = let ppf = Format.err_formatter in Clflags.native_code := true; let program = "ocamlnat" in + Topcommon.update_search_path_from_env (); Compenv.readenv ppf Before_args; Clflags.add_arguments __LOC__ Options.list; Compenv.parse_arguments ~current argv file_argument program; diff --git a/toplevel/topcommon.ml b/toplevel/topcommon.ml index f8a2d7f8a3..3adf4534d3 100644 --- a/toplevel/topcommon.ml +++ b/toplevel/topcommon.ml @@ -277,6 +277,13 @@ let set_paths () = Load_path.init load_path; Dll.add_path load_path +let update_search_path_from_env () = + let extra_paths = + let env = Sys.getenv_opt "OCAMLTOP_INCLUDE_PATH" in + Option.fold ~none:[] ~some:Misc.split_path_contents env + in + Clflags.include_dirs := List.rev_append extra_paths !Clflags.include_dirs + let initialize_toplevel_env () = toplevel_env := Compmisc.initial_env() diff --git a/toplevel/topcommon.mli b/toplevel/topcommon.mli index 0f32ed0aca..d75a944562 100644 --- a/toplevel/topcommon.mli +++ b/toplevel/topcommon.mli @@ -31,6 +31,11 @@ open Format val set_paths : unit -> unit +(* Add directories listed in OCAMLTOP_INCLUDE_PATH to the end of the search + path *) + +val update_search_path_from_env : unit -> unit + (* Management and helpers for the execution *) val toplevel_env : Env.t ref |