Fix expansion of %{ocaml-config:..}

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-09 00:50:42 +07:00 committed by Jérémie Dimino
parent 629b3d07ee
commit 0ca157f840
3 changed files with 20 additions and 12 deletions

View File

@ -30,6 +30,7 @@ module Macro = struct
| Read_strings
| Read_lines
| Path_no_dep
| Ocaml_config
end
type 'a t =
@ -77,6 +78,7 @@ module Map = struct
; "findlib", renamed_in ~version:(1, 0) ~new_name:"lib"
; "path-no-dep", deleted_in ~version:(1, 0) Path_no_dep
; "ocaml-config", macro Ocaml_config
]
|> String.Map.of_list_exn
@ -126,18 +128,7 @@ module Map = struct
; "profile" , string context.profile
]
in
let ocaml_config =
List.map (Ocaml_config.to_list context.ocaml_config) ~f:(fun (k, v) ->
("ocaml-config:" ^ k,
match (v : Ocaml_config.Value.t) with
| Bool x -> string (string_of_bool x)
| Int x -> string (string_of_int x)
| String x -> string x
| Words x -> strings x
| Prog_and_args x -> strings (x.prog :: x.args)))
in
[ ocaml_config
; static_vars
[ static_vars
; lowercased
; uppercased
; vars

View File

@ -22,6 +22,7 @@ module Macro : sig
| Read_strings
| Read_lines
| Path_no_dep
| Ocaml_config
end
type 'a t =

View File

@ -47,6 +47,7 @@ type t =
; cxx_flags : string list
; vars : Pform.Var.t Pform.Map.t
; macros : Pform.Macro.t Pform.Map.t
; ocaml_config : Value.t list String.Map.t
; chdir : (Action.t, Action.t) Build.t
; host : t option
; libs_by_package : (Package.t * Lib.Set.t) Package.Name.Map.t
@ -290,6 +291,19 @@ let create
~f:(fun s -> not (String.is_prefix s ~prefix:"-std="))
in
let vars = Pform.Map.create_vars ~context ~cxx_flags in
let ocaml_config =
let string s = [Value.String s] in
Ocaml_config.to_list context.ocaml_config
|> List.map ~f:(fun (k, v) ->
( k
, match (v : Ocaml_config.Value.t) with
| Bool x -> string (string_of_bool x)
| Int x -> string (string_of_int x)
| String x -> string x
| Words x -> Value.L.strings x
| Prog_and_args x -> Value.L.strings (x.prog :: x.args)))
|> String.Map.of_list_exn
in
let t =
{ context
; host
@ -305,6 +319,7 @@ let create
; cxx_flags
; vars
; macros = Pform.Map.macros
; ocaml_config
; chdir = Build.arr (fun (action : Action.t) ->
match action with
| Chdir _ -> action
@ -597,6 +612,7 @@ module Action = struct
let key = String_with_vars.Var.full_name var in
begin match expand_macro sctx ~syntax_version ~var with
| Some Pform.Macro.Exe -> Some (path_exp (map_exe (Path.relative dir s)))
| Some Ocaml_config -> String.Map.find sctx.ocaml_config s
| Some Dep -> Some (path_exp (Path.relative dir s))
| Some Bin -> begin
let sctx = host sctx in