Introduce a bindings variable for actions
We need to know the bindings statically whenever they overwrite existing vars Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
17d4a7c3df
commit
015b317f43
|
@ -194,6 +194,7 @@ module Gen(P : Install_rules.Params) = struct
|
|||
(snd rule.action)
|
||||
~loc:(fst rule.action)
|
||||
~dir
|
||||
~bindings:(Pform.Map.of_bindings rule.deps)
|
||||
~dep_kind:Required
|
||||
~targets
|
||||
~scope)
|
||||
|
@ -950,6 +951,7 @@ module Gen(P : Install_rules.Params) = struct
|
|||
~loc
|
||||
~dir
|
||||
~dep_kind:Required
|
||||
~bindings:(Pform.Map.of_bindings alias_conf.deps)
|
||||
~targets:Alias
|
||||
~scope)
|
||||
|
||||
|
|
|
@ -220,6 +220,7 @@ include Sub_system.Register_end_point(
|
|||
(List.filter_map backends ~f:(fun (backend : Backend.t) ->
|
||||
Option.map backend.info.generate_runner ~f:(fun (loc, action) ->
|
||||
SC.Action.run sctx action ~loc
|
||||
~bindings:Pform.Map.empty
|
||||
~extra_vars ~dir ~dep_kind:Required ~targets:Alias ~scope)))
|
||||
>>^ (fun actions ->
|
||||
Action.with_stdout_to target
|
||||
|
|
|
@ -239,6 +239,8 @@ module Bindings = struct
|
|||
|
||||
type 'a t = 'a one list
|
||||
|
||||
let fold t ~f ~init = List.fold_left ~f:(fun acc x -> f x acc) ~init t
|
||||
|
||||
let to_list =
|
||||
List.concat_map ~f:(function
|
||||
| Unnamed x -> [x]
|
||||
|
|
|
@ -90,6 +90,8 @@ module Bindings : sig
|
|||
|
||||
val find : 'a t -> string -> 'a list option
|
||||
|
||||
val fold : 'a t -> f:('a one -> 'acc -> 'acc) -> init:'acc -> 'acc
|
||||
|
||||
val empty : 'a t
|
||||
|
||||
val to_list : 'a t -> 'a list
|
||||
|
|
13
src/pform.ml
13
src/pform.ml
|
@ -7,6 +7,7 @@ module Var = struct
|
|||
| First_dep
|
||||
| Deps
|
||||
| Targets
|
||||
| Named_local
|
||||
|
||||
let to_value_no_deps_or_targets t ~scope =
|
||||
match t with
|
||||
|
@ -14,6 +15,7 @@ module Var = struct
|
|||
| Project_root -> Some [Value.Dir (Scope.root scope)]
|
||||
| First_dep
|
||||
| Deps
|
||||
| Named_local
|
||||
| Targets -> None
|
||||
end
|
||||
|
||||
|
@ -141,6 +143,8 @@ module Map = struct
|
|||
|
||||
let static_vars = String.Map.of_list_exn static_vars
|
||||
|
||||
let superpose = String.Map.superpose
|
||||
|
||||
let rec expand t ~syntax_version ~var =
|
||||
let name = String_with_vars.Var.name var in
|
||||
Option.bind (String.Map.find t name) ~f:(fun v ->
|
||||
|
@ -176,4 +180,13 @@ module Map = struct
|
|||
else
|
||||
Syntax.Error.deleted_in (String_with_vars.Var.loc var)
|
||||
Stanza.syntax syntax_version ~what:(what var) ?repl)
|
||||
|
||||
let empty = String.Map.empty
|
||||
|
||||
let of_bindings =
|
||||
Jbuild.Bindings.fold ~f:(fun x acc ->
|
||||
match x with
|
||||
| Unnamed _ -> acc
|
||||
| Named (s, _) -> String.Map.add acc s (No_info Var.Named_local)
|
||||
) ~init:empty
|
||||
end
|
||||
|
|
|
@ -5,6 +5,7 @@ module Var : sig
|
|||
| First_dep
|
||||
| Deps
|
||||
| Targets
|
||||
| Named_local
|
||||
|
||||
val to_value_no_deps_or_targets : t -> scope:Scope.t -> Value.t list option
|
||||
end
|
||||
|
@ -41,9 +42,15 @@ module Map : sig
|
|||
|
||||
val static_vars : Var.t t
|
||||
|
||||
val superpose : 'a t -> 'a t -> 'a t
|
||||
|
||||
val of_bindings : 'a Jbuild.Bindings.t -> Var.t t
|
||||
|
||||
val expand
|
||||
: 'a t
|
||||
-> syntax_version:Syntax.Version.t
|
||||
-> var:String_with_vars.Var.t
|
||||
-> 'a option
|
||||
|
||||
val empty : 'a t
|
||||
end with type 'a var := 'a t
|
||||
|
|
|
@ -462,6 +462,7 @@ let lint_module sctx ~dir ~dep_kind ~lint ~lib_name ~scope ~dir_kind =
|
|||
~loc
|
||||
~dir
|
||||
~dep_kind
|
||||
~bindings:Pform.Map.empty
|
||||
~targets:(Static [])
|
||||
~scope)))
|
||||
| Pps { loc; pps; flags } ->
|
||||
|
@ -542,6 +543,7 @@ let make sctx ~dir ~dep_kind ~lint ~preprocess
|
|||
~loc
|
||||
~dir
|
||||
~dep_kind
|
||||
~bindings:Pform.Map.empty
|
||||
~targets:(Static [dst])
|
||||
~scope))
|
||||
|> setup_reason_rules sctx ~dir in
|
||||
|
|
|
@ -807,9 +807,10 @@ module Action = struct
|
|||
end
|
||||
end)
|
||||
|
||||
let run sctx ~loc ?(extra_vars=String.Map.empty)
|
||||
let run sctx ~loc ?(extra_vars=String.Map.empty) ~bindings
|
||||
t ~dir ~dep_kind ~targets:targets_written_by_user ~scope
|
||||
: (Path.t Bindings.t, Action.t) Build.t =
|
||||
ignore bindings;
|
||||
let map_exe = map_exe sctx in
|
||||
if targets_written_by_user = Alias then begin
|
||||
match Action.Infer.unexpanded_targets t with
|
||||
|
|
|
@ -240,6 +240,7 @@ module Action : sig
|
|||
: t
|
||||
-> loc:Loc.t
|
||||
-> ?extra_vars:Value.t list String.Map.t
|
||||
-> bindings:Pform.Var.t Pform.Map.t
|
||||
-> Action.Unexpanded.t
|
||||
-> dir:Path.t
|
||||
-> dep_kind:Build.lib_dep_kind
|
||||
|
|
Loading…
Reference in New Issue