Merge pull request #1091 from ocaml/compiler-version-predicates

Extract predicates for compiler versions
This commit is contained in:
Etienne Millon 2018-08-06 14:28:42 +02:00 committed by GitHub
commit 48ece7ffe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 17 deletions

View File

@ -50,7 +50,7 @@ type t =
; natdynlink_supported : bool
; ocaml_config : Ocaml_config.t
; version_string : string
; version : int * int * int
; version : Ocaml_version.t
; stdlib_dir : Path.t
; ccomp_type : string
; c_compiler : string
@ -274,16 +274,16 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
ocaml_config_ok_exn
(Ocaml_config.Vars.of_lines lines >>= Ocaml_config.make))
>>= fun (findlib_path, ocfg) ->
let version = Ocaml_config.version ocfg in
let version = Ocaml_version.of_ocaml_config ocfg in
let env =
(* See comment in ansi_color.ml for setup_env_for_colors. For
OCaml < 4.05, OCAML_COLOR is not supported so we use
OCAMLPARAM. OCaml 4.02 doesn't support 'color' in OCAMLPARAM,
so we just don't force colors with 4.02. *)
(* See comment in ansi_color.ml for setup_env_for_colors.
For versions where OCAML_COLOR is not supported, but 'color' is in
OCAMLPARAM, use the latter.
If 'color' is not supported, we just don't force colors with 4.02. *)
if !Clflags.capture_outputs
&& Lazy.force Colors.stderr_supports_colors
&& version >= (4, 03, 0)
&& version < (4, 05, 0) then
&& Ocaml_version.supports_color_in_ocamlparam version
&& not (Ocaml_version.supports_ocaml_color version) then
let value =
match Env.get env "OCAMLPARAM" with
| None -> "color=always,_"
@ -332,8 +332,8 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
in
let stdlib_dir = Path.of_string (Ocaml_config.standard_library ocfg) in
let natdynlink_supported = Ocaml_config.natdynlink_supported ocfg in
let version = Ocaml_config.version ocfg in
let version_string = Ocaml_config.version_string ocfg in
let version = Ocaml_version.of_ocaml_config ocfg in
let arch_sixtyfour = Ocaml_config.word_size ocfg = 64 in
Fiber.return
{ name

View File

@ -90,7 +90,7 @@ type t =
; ocaml_config : Ocaml_config.t
; version_string : string
; version : int * int * int
; version : Ocaml_version.t
; stdlib_dir : Path.t
; ccomp_type : string
; c_compiler : string

View File

@ -17,7 +17,8 @@ module Gen(P : Install_rules.Params) = struct
let sctx = P.sctx
let ctx = SC.context sctx
let opaque = ctx.profile = "dev" && ctx.version >= (4, 03, 0)
let opaque =
ctx.profile = "dev" && Ocaml_version.supports_opaque_for_mli ctx.version
(* +-----------------------------------------------------------------+
| Library stuff |
@ -143,10 +144,11 @@ module Gen(P : Install_rules.Params) = struct
]));
dst
(* In 4.02, the compiler reads the cmi for module alias even with
[-w -49 -no-alias-deps], so we must sandbox the build of the
(* If the compiler reads the cmi for module alias even with
[-w -49 -no-alias-deps], we must sandbox the build of the
alias module since the modules it references are built after. *)
let alias_module_build_sandbox = ctx.version < (4, 03, 0)
let alias_module_build_sandbox =
Ocaml_version.always_reads_alias_cmi ctx.version
let library_rules (lib : Library.t) ~dir_contents ~dir ~scope
~compile_info ~dir_kind =

View File

@ -95,10 +95,10 @@ let build_cm cctx ?sandbox ?(dynlink=true) ~dep_graphs ~cm_kind (m : Module.t) =
in
let dir, no_keep_locs =
if CC.no_keep_locs cctx && cm_kind = Cmi then begin
if ctx.version < (4, 03, 0) then
(obj_dir, Arg_spec.As [])
if Ocaml_version.supports_no_keep_locs ctx.version then
(ctx.build_dir, Arg_spec.As ["-no-keep-locs"])
else
(ctx.build_dir, As ["-no-keep-locs"])
(obj_dir, As [])
end else
(ctx.build_dir, As [])
in

19
src/ocaml_version.ml Normal file
View File

@ -0,0 +1,19 @@
type t = int * int * int
let of_ocaml_config ocfg =
Ocaml_config.version ocfg
let supports_no_keep_locs version =
version >= (4, 03, 0)
let supports_opaque_for_mli version =
version >= (4, 03, 0)
let always_reads_alias_cmi version =
version < (4, 03, 0)
let supports_color_in_ocamlparam version =
version >= (4, 03, 0)
let supports_ocaml_color version =
version >= (4, 05, 0)

20
src/ocaml_version.mli Normal file
View File

@ -0,0 +1,20 @@
(** Version numbers for ocamlc and ocamlopt *)
type t
val of_ocaml_config : Ocaml_config.t -> t
(** Does this support [-no-keep-locs]? *)
val supports_no_keep_locs : t -> bool
(** Does this support [-opaque] for [.mli] files? *)
val supports_opaque_for_mli : t -> bool
(** Does it read the [.cmi] file of module alias
even when [-no-alias-deps] is passed? *)
val always_reads_alias_cmi : t -> bool
(** Does this support ['color'] in [OCAMLPARAM]? *)
val supports_color_in_ocamlparam : t -> bool
(** Does this support [OCAML_COLOR]? *)
val supports_ocaml_color : t -> bool