Use OCAML_COLOR and stop using OCAMLPARAM when possible
This commit is contained in:
parent
a573643b1e
commit
76db4d5641
|
@ -150,14 +150,18 @@ let strip_colors_for_stderr s =
|
||||||
else
|
else
|
||||||
strip s
|
strip s
|
||||||
|
|
||||||
(* We redirect the output of all commands, so by default the compiler will disable
|
(* We redirect the output of all commands, so by default the various tools will disable
|
||||||
colors. Since we support colors in the output of commands, we force it via OCAMLPARAM
|
colors. Since we support colors in the output of commands, we force it via specific
|
||||||
if stderr supports colors. *)
|
environment variables if stderr supports colors. *)
|
||||||
let setup_env_for_opam_colors = lazy(
|
let setup_env_for_colors = lazy(
|
||||||
if Lazy.force stderr_supports_colors then begin
|
if Lazy.force stderr_supports_colors then begin
|
||||||
match Sys.getenv "OPAMCOLOR" with
|
let set var value =
|
||||||
| exception Not_found -> Unix.putenv "OPAMCOLOR" "always"
|
match Sys.getenv with
|
||||||
| _ -> ()
|
| exception Not_found -> Unix.putenv var value
|
||||||
|
| _ -> ()
|
||||||
|
in
|
||||||
|
set "OPAMCOLOR" "always";
|
||||||
|
set "OCAML_COLOR" "always";
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ val colorize : key:string -> string -> string
|
||||||
|
|
||||||
val strip : string -> string
|
val strip : string -> string
|
||||||
val stderr_supports_colors : bool Lazy.t
|
val stderr_supports_colors : bool Lazy.t
|
||||||
val setup_env_for_opam_colors : unit Lazy.t
|
val setup_env_for_colors : unit Lazy.t
|
||||||
|
|
||||||
(** Strip colors in [not (Lazy.force stderr_supports_colors)] *)
|
(** Strip colors in [not (Lazy.force stderr_supports_colors)] *)
|
||||||
val strip_colors_for_stderr : string -> string
|
val strip_colors_for_stderr : string -> string
|
||||||
|
|
|
@ -264,11 +264,13 @@ let create ~(kind : Kind.t) ~path ~base_env ~env_extra ~name ~merlin ~use_findli
|
||||||
let natdynlink_supported = Path.exists (Path.relative stdlib_dir "dynlink.cmxa") in
|
let natdynlink_supported = Path.exists (Path.relative stdlib_dir "dynlink.cmxa") in
|
||||||
let version = get "version" in
|
let version = get "version" in
|
||||||
let env,env_extra =
|
let env,env_extra =
|
||||||
(* We redirect the output of all commands, so by default the compiler will disable
|
(* See comment in ansi_color.ml for setup_env_for_colors. For OCaml < 4.05,
|
||||||
colors. Since we support colors in the output of commands, we force it via OCAMLPARAM
|
OCAML_COLOR is not supported so we use OCAMLPARAM. OCaml 4.02 doesn't support
|
||||||
if stderr supports colors. *)
|
'color' in OCAMLPARAM, so we just don't force colors with 4.02. *)
|
||||||
let ocaml_version = Scanf.sscanf version "%u.%u.%u" (fun a b c -> a, b, c) in
|
let ocaml_version = Scanf.sscanf version "%u.%u" (fun a b -> a, b) in
|
||||||
if Lazy.force Ansi_color.stderr_supports_colors && ocaml_version > (4, 02, 3) then
|
if Lazy.force Ansi_color.stderr_supports_colors
|
||||||
|
&& ocaml_version > (4, 02)
|
||||||
|
&& ocaml_version < (4, 05) then
|
||||||
let value =
|
let value =
|
||||||
match get_env env "OCAMLPARAM" with
|
match get_env env "OCAMLPARAM" with
|
||||||
| None -> "color=always,_"
|
| None -> "color=always,_"
|
||||||
|
@ -369,7 +371,7 @@ let create ~(kind : Kind.t) ~path ~base_env ~env_extra ~name ~merlin ~use_findli
|
||||||
let opam_config_var t var = opam_config_var ~env:t.env ~cache:t.opam_var_cache var
|
let opam_config_var t var = opam_config_var ~env:t.env ~cache:t.opam_var_cache var
|
||||||
|
|
||||||
let initial_env = lazy (
|
let initial_env = lazy (
|
||||||
Lazy.force Ansi_color.setup_env_for_opam_colors;
|
Lazy.force Ansi_color.setup_env_for_colors;
|
||||||
Unix.environment ())
|
Unix.environment ())
|
||||||
|
|
||||||
let default ?(merlin=true) ?(use_findlib=true) () =
|
let default ?(merlin=true) ?(use_findlib=true) () =
|
||||||
|
|
|
@ -620,7 +620,7 @@ module Scheduler = struct
|
||||||
go_rec cwd log t
|
go_rec cwd log t
|
||||||
|
|
||||||
let go ?(log=Log.no_log) t =
|
let go ?(log=Log.no_log) t =
|
||||||
Lazy.force Ansi_color.setup_env_for_opam_colors;
|
Lazy.force Ansi_color.setup_env_for_colors;
|
||||||
Log.info log ("Workspace root: " ^ !Clflags.workspace_root);
|
Log.info log ("Workspace root: " ^ !Clflags.workspace_root);
|
||||||
let cwd = Sys.getcwd () in
|
let cwd = Sys.getcwd () in
|
||||||
go_rec cwd log t
|
go_rec cwd log t
|
||||||
|
|
Loading…
Reference in New Issue