2016-02-18 07:11:59 -08:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Fabrice Le Fessant, EPI Gallium, INRIA Paris-Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2013 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. This file is distributed under the terms of *)
|
|
|
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
|
|
|
(* special exception on linking described in the file LICENSE. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
2013-06-05 09:34:40 -07:00
|
|
|
|
|
|
|
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).
|
|
|
|
*)
|
|
|
|
|
2019-03-11 11:38:16 -07:00
|
|
|
let init_path ?(dir="") () =
|
2013-06-05 09:34:40 -07:00
|
|
|
let dirs =
|
|
|
|
if !Clflags.use_threads then "+threads" :: !Clflags.include_dirs
|
|
|
|
else
|
2016-05-18 05:09:00 -07:00
|
|
|
!Clflags.include_dirs
|
2013-06-05 09:34:40 -07:00
|
|
|
in
|
2017-01-27 07:08:41 -08:00
|
|
|
let dirs =
|
|
|
|
!last_include_dirs @ dirs @ Config.flexdll_dirs @ !first_include_dirs
|
|
|
|
in
|
2013-06-05 09:34:40 -07:00
|
|
|
let exp_dirs =
|
|
|
|
List.map (Misc.expand_directory Config.standard_library) dirs in
|
2018-09-18 06:49:18 -07:00
|
|
|
Load_path.init (dir :: List.rev_append exp_dirs (Clflags.std_include_dir ()));
|
2013-06-05 09:34:40 -07:00
|
|
|
Env.reset_cache ()
|
|
|
|
|
|
|
|
(* Return the initial environment in which compilation proceeds. *)
|
|
|
|
|
|
|
|
(* Note: do not do init_path() in initial_env, this breaks
|
2019-03-18 02:42:23 -07:00
|
|
|
toplevel initialization (PR#8227) *)
|
2013-06-05 09:34:40 -07:00
|
|
|
|
|
|
|
let initial_env () =
|
|
|
|
Ident.reinit();
|
2020-03-05 05:19:48 -08:00
|
|
|
Types.Uid.reinit();
|
2017-01-12 03:56:24 -08:00
|
|
|
let initially_opened_module =
|
|
|
|
if !Clflags.nopervasives then
|
|
|
|
None
|
|
|
|
else
|
|
|
|
Some "Stdlib"
|
|
|
|
in
|
2018-02-02 02:44:23 -08:00
|
|
|
Typemod.initial_env
|
|
|
|
~loc:(Location.in_file "command line")
|
|
|
|
~safe_string:(Config.safe_string || not !Clflags.unsafe_string)
|
2017-01-12 03:56:24 -08:00
|
|
|
~initially_opened_module
|
2018-04-09 10:18:20 -07:00
|
|
|
~open_implicit_modules:(List.rev !Clflags.open_modules)
|
Respect OCAML_COLOR environment variable for deciding whether to use colors
Since 4.03, OCaml supports coloring its messages to standard output and standard
error, depending on the "-color" argument ({always,never,auto}). This commit
adds support for the environment variable "OCAML_COLOR" (which value can as well
be {always,never,auto}).
The command line argument "-color" takes precedence, "OCAML_COLOR" is only
taken into consideration if no "-color" is provided.
The motivation for this is that the user should have control over coloring
OCaml's output messages. OCamlbuild, a widely used build tool executes OCaml
not under a tty (and OCaml does not colorize errors and warnings), which lead
various packages use `color(always)` in their `_tags` files, which breaks with
other (non-interactive) programs (i.e. editor helpers).
Further discussion was done at https://github.com/ocaml/ocamlbuild/issues/87 and
https://github.com/ocaml/ocaml/pull/1098.
2017-03-11 03:38:59 -08:00
|
|
|
|
2018-10-19 13:20:30 -07:00
|
|
|
let set_from_env flag Clflags.{ parse; usage; env_var } =
|
Respect OCAML_COLOR environment variable for deciding whether to use colors
Since 4.03, OCaml supports coloring its messages to standard output and standard
error, depending on the "-color" argument ({always,never,auto}). This commit
adds support for the environment variable "OCAML_COLOR" (which value can as well
be {always,never,auto}).
The command line argument "-color" takes precedence, "OCAML_COLOR" is only
taken into consideration if no "-color" is provided.
The motivation for this is that the user should have control over coloring
OCaml's output messages. OCamlbuild, a widely used build tool executes OCaml
not under a tty (and OCaml does not colorize errors and warnings), which lead
various packages use `color(always)` in their `_tags` files, which breaks with
other (non-interactive) programs (i.e. editor helpers).
Further discussion was done at https://github.com/ocaml/ocamlbuild/issues/87 and
https://github.com/ocaml/ocaml/pull/1098.
2017-03-11 03:38:59 -08:00
|
|
|
try
|
2018-10-19 13:20:30 -07:00
|
|
|
match parse (Sys.getenv env_var) with
|
Respect OCAML_COLOR environment variable for deciding whether to use colors
Since 4.03, OCaml supports coloring its messages to standard output and standard
error, depending on the "-color" argument ({always,never,auto}). This commit
adds support for the environment variable "OCAML_COLOR" (which value can as well
be {always,never,auto}).
The command line argument "-color" takes precedence, "OCAML_COLOR" is only
taken into consideration if no "-color" is provided.
The motivation for this is that the user should have control over coloring
OCaml's output messages. OCamlbuild, a widely used build tool executes OCaml
not under a tty (and OCaml does not colorize errors and warnings), which lead
various packages use `color(always)` in their `_tags` files, which breaks with
other (non-interactive) programs (i.e. editor helpers).
Further discussion was done at https://github.com/ocaml/ocamlbuild/issues/87 and
https://github.com/ocaml/ocaml/pull/1098.
2017-03-11 03:38:59 -08:00
|
|
|
| None ->
|
2018-07-15 12:00:47 -07:00
|
|
|
Location.prerr_warning Location.none
|
2018-10-19 13:20:30 -07:00
|
|
|
(Warnings.Bad_env_variable (env_var, usage))
|
|
|
|
| Some x -> match !flag with
|
|
|
|
| None -> flag := Some x
|
Respect OCAML_COLOR environment variable for deciding whether to use colors
Since 4.03, OCaml supports coloring its messages to standard output and standard
error, depending on the "-color" argument ({always,never,auto}). This commit
adds support for the environment variable "OCAML_COLOR" (which value can as well
be {always,never,auto}).
The command line argument "-color" takes precedence, "OCAML_COLOR" is only
taken into consideration if no "-color" is provided.
The motivation for this is that the user should have control over coloring
OCaml's output messages. OCamlbuild, a widely used build tool executes OCaml
not under a tty (and OCaml does not colorize errors and warnings), which lead
various packages use `color(always)` in their `_tags` files, which breaks with
other (non-interactive) programs (i.e. editor helpers).
Further discussion was done at https://github.com/ocaml/ocamlbuild/issues/87 and
https://github.com/ocaml/ocaml/pull/1098.
2017-03-11 03:38:59 -08:00
|
|
|
| Some _ -> ()
|
|
|
|
with
|
|
|
|
Not_found -> ()
|
2018-07-27 00:51:53 -07:00
|
|
|
|
2018-10-19 13:20:30 -07:00
|
|
|
let read_clflags_from_env () =
|
|
|
|
set_from_env Clflags.color Clflags.color_reader;
|
|
|
|
set_from_env Clflags.error_style Clflags.error_style_reader;
|
|
|
|
()
|
|
|
|
|
2018-12-30 09:02:45 -08:00
|
|
|
let with_ppf_dump ~file_prefix f =
|
2018-07-27 00:51:53 -07:00
|
|
|
let ppf_dump, finally =
|
|
|
|
if not !Clflags.dump_into_file
|
|
|
|
then Format.err_formatter, ignore
|
|
|
|
else
|
2018-12-30 09:02:45 -08:00
|
|
|
let ch = open_out (file_prefix ^ ".dump") in
|
2018-07-27 00:51:53 -07:00
|
|
|
let ppf = Format.formatter_of_out_channel ch in
|
|
|
|
ppf,
|
|
|
|
(fun () ->
|
|
|
|
Format.pp_print_flush ppf ();
|
|
|
|
close_out ch)
|
|
|
|
in
|
|
|
|
Misc.try_finally (fun () -> f ppf_dump) ~always:finally
|