Allow setting ENV vars in findlib.conf per toolchain

This is useful for configuring PKG CONFIG for cross compilation
This commit is contained in:
Rudi Grinberg 2018-05-01 00:13:50 +07:00
parent 630e42f490
commit 3e9bc8c0c3
5 changed files with 27 additions and 4 deletions

View File

@ -315,6 +315,10 @@ let create ~(kind : Kind.t) ~path ~env ~name ~merlin ~targets () =
| Some host ->
Env.get host.env "PATH"
)
|> Env.extend_env (
Option.value ~default:Env.empty
(Option.map findlib_config ~f:Findlib.Config.env)
)
in
let stdlib_dir = Path.of_string (Ocaml_config.standard_library ocfg) in
let natdynlink_supported = Ocaml_config.natdynlink_supported ocfg in

View File

@ -22,6 +22,8 @@ let make vars =
; unix = None
}
let empty = make Map.empty
let get t k = Map.find t.vars k
let to_unix t =
@ -73,3 +75,6 @@ let diff x y =
let update t ~var ~f =
make (Map.update t.vars var ~f)
let of_string_map m =
make (String.Map.foldi ~init:Map.empty ~f:(fun k v acc -> Map.add acc k v) m)

View File

@ -9,6 +9,8 @@ type t
module Map : Map.S with type key = Var.t
val empty : t
(** The environment when the process started *)
val initial : t
@ -28,3 +30,4 @@ val update : t -> var:string -> f:(string option -> string option) -> t
val sexp_of_t : t -> Sexp.t
val of_string_map : string String.Map.t -> t

View File

@ -45,22 +45,24 @@ module Rules = struct
; add_rules : Rule.t list
}
let interpret t ~preds =
let interpret' t ~preds =
let rec find_set_rule = function
| [] -> ""
| [] -> None
| rule :: rules ->
if Rule.matches rule ~preds then
rule.value
Some rule.value
else
find_set_rule rules
in
let v = find_set_rule t.set_rules in
List.fold_left t.add_rules ~init:v ~f:(fun v rule ->
if Rule.matches rule ~preds then
v ^ " " ^ rule.value
Some ((Option.value ~default:"" v) ^ " " ^ rule.value)
else
v)
let interpret t ~preds = Option.value ~default:"" (interpret' t ~preds)
let of_meta_rules (rules : Meta.Simplified.Rules.t) =
let add_rules = List.map rules.add_rules ~f:Rule.make in
let set_rules =
@ -106,6 +108,13 @@ module Config = struct
let get { vars; preds } var =
Vars.get vars var preds
let env t =
let preds = Ps.add t.preds (P.make "env") in
String.Map.filter_map ~f:(fun rules ->
Rules.interpret' rules ~preds
) t.vars
|> Env.of_string_map
end
module Package = struct

View File

@ -62,4 +62,6 @@ module Config : sig
type t
val load : Path.t -> toolchain:string -> context:string -> t
val get : t -> string -> string option
val env : t -> Env.t
end