2013-06-05 09:34:40 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
2013-07-09 06:21:45 -07:00
|
|
|
(* Fabrice Le Fessant, EPI Gallium, INRIA Paris-Rocquencourt *)
|
2013-06-05 09:34:40 -07:00
|
|
|
(* *)
|
2013-07-09 06:21:45 -07:00
|
|
|
(* Copyright 2013 Institut National de Recherche en Informatique et *)
|
2013-06-05 09:34:40 -07:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
open Compenv
|
|
|
|
|
|
|
|
(* Initialize the search path.
|
2015-01-16 14:45:06 -08:00
|
|
|
[dir] is always searched first (default: the current directory),
|
2013-06-05 09:34:40 -07:00
|
|
|
then the directories specified with the -I option (in command-line order),
|
|
|
|
then the standard library directory (unless the -nostdlib option is given).
|
|
|
|
*)
|
|
|
|
|
2015-01-16 14:45:06 -08:00
|
|
|
let init_path ?(dir="") native =
|
2013-06-05 09:34:40 -07:00
|
|
|
let dirs =
|
|
|
|
if !Clflags.use_threads then "+threads" :: !Clflags.include_dirs
|
|
|
|
else if !Clflags.use_vmthreads && not native then
|
|
|
|
"+vmthreads" :: !Clflags.include_dirs
|
|
|
|
else
|
|
|
|
!last_include_dirs @
|
|
|
|
!Clflags.include_dirs @
|
|
|
|
!first_include_dirs
|
|
|
|
in
|
|
|
|
let exp_dirs =
|
|
|
|
List.map (Misc.expand_directory Config.standard_library) dirs in
|
2015-01-16 14:45:06 -08:00
|
|
|
Config.load_path := dir ::
|
2013-06-05 09:34:40 -07:00
|
|
|
List.rev_append exp_dirs (Clflags.std_include_dir ());
|
|
|
|
Env.reset_cache ()
|
|
|
|
|
|
|
|
(* Return the initial environment in which compilation proceeds. *)
|
|
|
|
|
|
|
|
(* Note: do not do init_path() in initial_env, this breaks
|
|
|
|
toplevel initialization (PR#1775) *)
|
|
|
|
|
|
|
|
let open_implicit_module m env =
|
2014-05-12 05:02:26 -07:00
|
|
|
let open Asttypes in
|
|
|
|
let lid = {loc = Location.in_file "command line";
|
|
|
|
txt = Longident.Lident m } in
|
|
|
|
snd (Typemod.type_open_ Override env lid.loc lid)
|
2013-06-05 09:34:40 -07:00
|
|
|
|
|
|
|
let initial_env () =
|
|
|
|
Ident.reinit();
|
2014-04-29 04:56:17 -07:00
|
|
|
let initial =
|
|
|
|
if !Clflags.unsafe_string then Env.initial_unsafe_string
|
|
|
|
else Env.initial_safe_string
|
|
|
|
in
|
2013-06-05 09:34:40 -07:00
|
|
|
let env =
|
2014-04-29 04:56:17 -07:00
|
|
|
if !Clflags.nopervasives then initial else
|
|
|
|
open_implicit_module "Pervasives" initial
|
2013-06-05 09:34:40 -07:00
|
|
|
in
|
|
|
|
List.fold_left (fun env m ->
|
|
|
|
open_implicit_module m env
|
2014-08-07 02:46:34 -07:00
|
|
|
) env (!implicit_modules @ List.rev !Clflags.open_modules)
|