Skip to content

Commit

Permalink
Merge pull request #1091 from ocaml/compiler-version-predicates
Browse files Browse the repository at this point in the history
Extract predicates for compiler versions
  • Loading branch information
emillon authored Aug 6, 2018
2 parents 7c597d8 + 4bacf48 commit 48ece7f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,_"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions src/module_compilation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/ocaml_version.ml
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions src/ocaml_version.mli
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 48ece7f

Please sign in to comment.