Extend (:include ) form to OCaml flags

flags, ocaml_flags and ocamlopt_flags now support the (:include ) form
of the ordered set language.
This commit is contained in:
David Allsopp 2017-06-15 12:02:19 +02:00 committed by Jérémie Dimino
parent 712981d847
commit cebbb219e7
9 changed files with 59 additions and 45 deletions

View File

@ -854,6 +854,7 @@ flags using the following fields:
- ``(ocamlopt_flags <flags>)`` to specify flags passed to ``ocamlopt`` only
For all these fields, ``<flags>`` is specified in the `Ordered set language`_.
These fields all support ``(:include ...)`` forms.
The default value for ``(flags ...)`` includes some ``-w`` options to set
warnings. The exact set depends on whether ``--dev`` is passed to Jbuilder. As a

View File

@ -87,7 +87,7 @@ module Gen(P : Params) = struct
fun x -> x
in
SC.add_rule sctx
(Build.fanout
(Build.fanout3
(dep_graph >>>
Build.arr (fun dep_graph ->
Ocamldep.names_to_top_closed_cm_files
@ -97,21 +97,22 @@ module Gen(P : Params) = struct
~mode
(String_map.keys modules)))
(SC.expand_and_eval_set ~dir lib.c_library_flags ~standard:[])
(Ocaml_flags.get flags mode)
>>>
Build.run ~context:ctx (Dep compiler)
~extra_targets:(
match mode with
| Byte -> []
| Native -> [lib_archive lib ~dir ~ext:ctx.ext_lib])
[ Ocaml_flags.get flags mode
[ Dyn (fun (_, _, flags) -> As flags)
; A "-a"; A "-o"; Target target
; As stubs_flags
; Dyn (fun (_, cclibs) -> Arg_spec.quote_args "-cclib" (map_cclibs cclibs))
; Dyn (fun (_, cclibs, _) -> Arg_spec.quote_args "-cclib" (map_cclibs cclibs))
; As (List.map lib.library_flags ~f:(SC.expand_vars sctx ~scope ~dir))
; As (match lib.kind with
| Normal -> []
| Ppx_deriver | Ppx_rewriter -> ["-linkall"])
; Dyn (fun (cm_files, _) -> Deps cm_files)
; Dyn (fun (cm_files, _, _) -> Deps cm_files)
]))
let build_c_file (lib : Library.t) ~dir ~requires ~h_files c_name =
@ -178,7 +179,7 @@ module Gen(P : Params) = struct
let library_rules (lib : Library.t) ~dir ~all_modules ~files ~scope =
let dep_kind = if lib.optional then Build.Optional else Required in
let flags = Ocaml_flags.make lib.buildable in
let flags = Ocaml_flags.make lib.buildable ~dir in
let modules =
parse_modules ~dir ~all_modules ~modules_written_by_user:lib.buildable.modules
in
@ -373,9 +374,11 @@ module Gen(P : Params) = struct
let src = lib_archive lib ~dir ~ext:(Mode.compiled_lib_ext Native) in
let dst = lib_archive lib ~dir ~ext:".cmxs" in
let build =
Ocaml_flags.get flags Native
>>>
Build.run ~context:ctx
(Dep ocamlopt)
[ Ocaml_flags.get flags Native
[ Dyn (fun flags -> As flags)
; A "-shared"; A "-linkall"
; A "-I"; Path dir
; A "-o"; Target dst
@ -436,14 +439,17 @@ module Gen(P : Params) = struct
[String.capitalize_ascii name]))
in
SC.add_rule sctx
(libs_and_cm >>>
(libs_and_cm
&&&
(Ocaml_flags.get flags mode)
>>>
Build.run ~context:ctx
(Dep compiler)
[ Ocaml_flags.get flags mode
[ Dyn (fun (_, flags) -> As flags)
; A "-o"; Target exe
; As link_flags
; Dyn (fun (libs, _) -> Lib.link_flags libs ~mode)
; Dyn (fun (_, cm_files) -> Deps cm_files)
; Dyn (fun ((libs, _), _) -> Lib.link_flags libs ~mode)
; Dyn (fun ((_, cm_files), _) -> Deps cm_files)
]);
if mode = Mode.Byte then
let rules = Js_of_ocaml_rules.build_exe sctx ~dir ~js_of_ocaml ~src:exe in
@ -451,7 +457,7 @@ module Gen(P : Params) = struct
let executables_rules (exes : Executables.t) ~dir ~all_modules ~scope =
let dep_kind = Build.Required in
let flags = Ocaml_flags.make exes.buildable in
let flags = Ocaml_flags.make exes.buildable ~dir in
let modules =
parse_modules ~dir ~all_modules ~modules_written_by_user:exes.buildable.modules
in

View File

@ -444,9 +444,9 @@ module Buildable = struct
; libraries : Lib_dep.t list
; preprocess : Preprocess_map.t
; preprocessor_deps : Dep_conf.t list
; flags : Ordered_set_lang.t
; ocamlc_flags : Ordered_set_lang.t
; ocamlopt_flags : Ordered_set_lang.t
; flags : Ordered_set_lang.Unexpanded.t
; ocamlc_flags : Ordered_set_lang.Unexpanded.t
; ocamlopt_flags : Ordered_set_lang.Unexpanded.t
; js_of_ocaml : Js_of_ocaml.t
}
@ -464,9 +464,9 @@ module Buildable = struct
>>= fun modules ->
field "libraries" Lib_deps.t ~default:[]
>>= fun libraries ->
field_osl "flags" >>= fun flags ->
field_osl "ocamlc_flags" >>= fun ocamlc_flags ->
field_osl "ocamlopt_flags" >>= fun ocamlopt_flags ->
field_oslu "flags" >>= fun flags ->
field_oslu "ocamlc_flags" >>= fun ocamlc_flags ->
field_oslu "ocamlopt_flags" >>= fun ocamlopt_flags ->
field "js_of_ocaml" (Js_of_ocaml.t) ~default:Js_of_ocaml.default >>= fun js_of_ocaml ->
return
{ preprocess

View File

@ -100,9 +100,9 @@ module Buildable : sig
; libraries : Lib_dep.t list
; preprocess : Preprocess_map.t
; preprocessor_deps : Dep_conf.t list
; flags : Ordered_set_lang.t
; ocamlc_flags : Ordered_set_lang.t
; ocamlopt_flags : Ordered_set_lang.t
; flags : Ordered_set_lang.Unexpanded.t
; ocamlc_flags : Ordered_set_lang.Unexpanded.t
; ocamlopt_flags : Ordered_set_lang.Unexpanded.t
; js_of_ocaml : Js_of_ocaml.t
}

View File

@ -6,7 +6,7 @@ module SC = Super_context
type t =
{ requires : (unit, Lib.t list) Build.t
; flags : string list
; flags : (unit, string list) Build.t
; preprocess : Jbuild.Preprocess.t
; libname : string option
}
@ -38,8 +38,8 @@ let dot_merlin sctx ~dir ({ requires; flags; _ } as t) =
>>>
Build.update_file (Path.relative dir ".merlin-exists") "");
SC.add_rule sctx (
requires
>>^ (fun libs ->
requires &&& flags
>>^ (fun (libs, flags) ->
let ppx_flags = ppx_flags sctx ~dir ~src_dir:remaindir t in
let internals, externals =
List.fold_left libs ~init:([], []) ~f:(fun (internals, externals) ->
@ -87,7 +87,7 @@ let merge_two a b =
(Build.fanout a.requires b.requires
>>^ fun (x, y) ->
Lib.remove_dups_preserve_order (x @ y))
; flags = a.flags @ b.flags
; flags = a.flags &&& b.flags >>^ (fun (a, b) -> a @ b)
; preprocess =
if a.preprocess = b.preprocess then
a.preprocess

View File

@ -2,7 +2,7 @@
type t =
{ requires : (unit, Lib.t list) Build.t
; flags : string list
; flags : (unit, string list) Build.t
; preprocess : Jbuild.Preprocess.t
; libname : string option
}

View File

@ -61,12 +61,13 @@ let build_cm sctx ?sandbox ~dynlink ~flags ~cm_kind ~(dep_graph:Ocamldep.dep_gra
SC.add_rule sctx ?sandbox
(Build.paths extra_deps >>>
other_cm_files >>>
requires >>>
requires &&&
Ocaml_flags.get_for_cm flags ~cm_kind >>>
Build.run ~context:ctx (Dep compiler)
~extra_targets
[ Ocaml_flags.get_for_cm flags ~cm_kind
[ Dyn (fun (_, ocaml_flags) -> As ocaml_flags)
; cmt_args
; Dyn Lib.include_flags
; Dyn (fun (libs, _) -> Lib.include_flags libs)
; As extra_args
; if dynlink || cm_kind <> Cmx then As [] else A "-nodynlink"
; A "-no-alias-deps"

View File

@ -1,4 +1,5 @@
open Import
open Build.O
let default_ocamlc_flags = Utils.g
let default_ocamlopt_flags = Utils.g
@ -32,33 +33,38 @@ let default_flags () =
[ "-w"; !Clflags.warnings ]
type t =
{ common : string list
; specific : string list Mode.Dict.t
{ common : (unit, string list) Build.t
; specific : (unit, string list) Build.t Mode.Dict.t
}
let make { Jbuild.Buildable. flags; ocamlc_flags; ocamlopt_flags; _ } =
let eval = Ordered_set_lang.eval_with_standard in
{ common = eval flags ~standard:(default_flags ())
let make { Jbuild.Buildable. flags; ocamlc_flags; ocamlopt_flags; _ } ~dir =
let eval = Super_context.expand_and_eval_set ~dir in
{ common = Build.memoize "common flags" (eval flags ~standard:(default_flags ()))
; specific =
{ byte = eval ocamlc_flags ~standard:(default_ocamlc_flags ())
; native = eval ocamlopt_flags ~standard:(default_ocamlopt_flags ())
{ byte = Build.memoize "ocamlc flags" (eval ocamlc_flags ~standard:(default_ocamlc_flags ()))
; native = Build.memoize "ocamlopt flags" (eval ocamlopt_flags ~standard:(default_ocamlopt_flags ()))
}
}
let get t mode = Arg_spec.As (t.common @ Mode.Dict.get t.specific mode)
let get t mode =
t.common
&&&
(Mode.Dict.get t.specific mode)
>>^ fun (common, specific) ->
common @ specific
let get_for_cm t ~cm_kind = get t (Mode.of_cm_kind cm_kind)
let default () =
{ common = default_flags ()
{ common = Build.return (default_flags ())
; specific =
{ byte = default_ocamlc_flags ()
; native = default_ocamlopt_flags ()
{ byte = Build.return (default_ocamlc_flags ())
; native = Build.return (default_ocamlopt_flags ())
}
}
let append_common t flags = {t with common = t.common @ flags}
let append_common t flags = {t with common = t.common >>^ fun l -> l @ flags}
let prepend_common flags t = {t with common = flags @ t.common}
let prepend_common flags t = {t with common = t.common >>^ fun l -> flags @ l}
let common t = t.common

View File

@ -2,14 +2,14 @@
type t
val make : Jbuild.Buildable.t -> t
val make : Jbuild.Buildable.t -> dir:Path.t -> t
val default : unit -> t
val get : t -> Mode.t -> _ Arg_spec.t
val get_for_cm : t -> cm_kind:Cm_kind.t -> _ Arg_spec.t
val get : t -> Mode.t -> (unit, string list) Build.t
val get_for_cm : t -> cm_kind:Cm_kind.t -> (unit, string list) Build.t
val append_common : t -> string list -> t
val prepend_common : string list -> t -> t
val common : t -> string list
val common : t -> (unit, string list) Build.t