From 0ca157f8400fdb848b434363e99d8d65d9463dec Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 9 Jul 2018 00:50:42 +0700 Subject: [PATCH] Fix expansion of %{ocaml-config:..} Signed-off-by: Rudi Grinberg --- src/pform.ml | 15 +++------------ src/pform.mli | 1 + src/super_context.ml | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/pform.ml b/src/pform.ml index f975473b..58e1858b 100644 --- a/src/pform.ml +++ b/src/pform.ml @@ -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 diff --git a/src/pform.mli b/src/pform.mli index d36d3624..357a3a16 100644 --- a/src/pform.mli +++ b/src/pform.mli @@ -22,6 +22,7 @@ module Macro : sig | Read_strings | Read_lines | Path_no_dep + | Ocaml_config end type 'a t = diff --git a/src/super_context.ml b/src/super_context.ml index 21b3fe09..46c9c865 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -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