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)
|
(snd rule.action)
|
||||||
~loc:(fst rule.action)
|
~loc:(fst rule.action)
|
||||||
~dir
|
~dir
|
||||||
|
~bindings:(Pform.Map.of_bindings rule.deps)
|
||||||
~dep_kind:Required
|
~dep_kind:Required
|
||||||
~targets
|
~targets
|
||||||
~scope)
|
~scope)
|
||||||
|
@ -950,6 +951,7 @@ module Gen(P : Install_rules.Params) = struct
|
||||||
~loc
|
~loc
|
||||||
~dir
|
~dir
|
||||||
~dep_kind:Required
|
~dep_kind:Required
|
||||||
|
~bindings:(Pform.Map.of_bindings alias_conf.deps)
|
||||||
~targets:Alias
|
~targets:Alias
|
||||||
~scope)
|
~scope)
|
||||||
|
|
||||||
|
|
|
@ -220,6 +220,7 @@ include Sub_system.Register_end_point(
|
||||||
(List.filter_map backends ~f:(fun (backend : Backend.t) ->
|
(List.filter_map backends ~f:(fun (backend : Backend.t) ->
|
||||||
Option.map backend.info.generate_runner ~f:(fun (loc, action) ->
|
Option.map backend.info.generate_runner ~f:(fun (loc, action) ->
|
||||||
SC.Action.run sctx action ~loc
|
SC.Action.run sctx action ~loc
|
||||||
|
~bindings:Pform.Map.empty
|
||||||
~extra_vars ~dir ~dep_kind:Required ~targets:Alias ~scope)))
|
~extra_vars ~dir ~dep_kind:Required ~targets:Alias ~scope)))
|
||||||
>>^ (fun actions ->
|
>>^ (fun actions ->
|
||||||
Action.with_stdout_to target
|
Action.with_stdout_to target
|
||||||
|
|
|
@ -239,6 +239,8 @@ module Bindings = struct
|
||||||
|
|
||||||
type 'a t = 'a one list
|
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 =
|
let to_list =
|
||||||
List.concat_map ~f:(function
|
List.concat_map ~f:(function
|
||||||
| Unnamed x -> [x]
|
| Unnamed x -> [x]
|
||||||
|
|
|
@ -90,6 +90,8 @@ module Bindings : sig
|
||||||
|
|
||||||
val find : 'a t -> string -> 'a list option
|
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 empty : 'a t
|
||||||
|
|
||||||
val to_list : 'a t -> 'a list
|
val to_list : 'a t -> 'a list
|
||||||
|
|
13
src/pform.ml
13
src/pform.ml
|
@ -7,6 +7,7 @@ module Var = struct
|
||||||
| First_dep
|
| First_dep
|
||||||
| Deps
|
| Deps
|
||||||
| Targets
|
| Targets
|
||||||
|
| Named_local
|
||||||
|
|
||||||
let to_value_no_deps_or_targets t ~scope =
|
let to_value_no_deps_or_targets t ~scope =
|
||||||
match t with
|
match t with
|
||||||
|
@ -14,6 +15,7 @@ module Var = struct
|
||||||
| Project_root -> Some [Value.Dir (Scope.root scope)]
|
| Project_root -> Some [Value.Dir (Scope.root scope)]
|
||||||
| First_dep
|
| First_dep
|
||||||
| Deps
|
| Deps
|
||||||
|
| Named_local
|
||||||
| Targets -> None
|
| Targets -> None
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -141,6 +143,8 @@ module Map = struct
|
||||||
|
|
||||||
let static_vars = String.Map.of_list_exn static_vars
|
let static_vars = String.Map.of_list_exn static_vars
|
||||||
|
|
||||||
|
let superpose = String.Map.superpose
|
||||||
|
|
||||||
let rec expand t ~syntax_version ~var =
|
let rec expand t ~syntax_version ~var =
|
||||||
let name = String_with_vars.Var.name var in
|
let name = String_with_vars.Var.name var in
|
||||||
Option.bind (String.Map.find t name) ~f:(fun v ->
|
Option.bind (String.Map.find t name) ~f:(fun v ->
|
||||||
|
@ -176,4 +180,13 @@ module Map = struct
|
||||||
else
|
else
|
||||||
Syntax.Error.deleted_in (String_with_vars.Var.loc var)
|
Syntax.Error.deleted_in (String_with_vars.Var.loc var)
|
||||||
Stanza.syntax syntax_version ~what:(what var) ?repl)
|
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
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ module Var : sig
|
||||||
| First_dep
|
| First_dep
|
||||||
| Deps
|
| Deps
|
||||||
| Targets
|
| Targets
|
||||||
|
| Named_local
|
||||||
|
|
||||||
val to_value_no_deps_or_targets : t -> scope:Scope.t -> Value.t list option
|
val to_value_no_deps_or_targets : t -> scope:Scope.t -> Value.t list option
|
||||||
end
|
end
|
||||||
|
@ -41,9 +42,15 @@ module Map : sig
|
||||||
|
|
||||||
val static_vars : Var.t t
|
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
|
val expand
|
||||||
: 'a t
|
: 'a t
|
||||||
-> syntax_version:Syntax.Version.t
|
-> syntax_version:Syntax.Version.t
|
||||||
-> var:String_with_vars.Var.t
|
-> var:String_with_vars.Var.t
|
||||||
-> 'a option
|
-> 'a option
|
||||||
|
|
||||||
|
val empty : 'a t
|
||||||
end with type 'a var := '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
|
~loc
|
||||||
~dir
|
~dir
|
||||||
~dep_kind
|
~dep_kind
|
||||||
|
~bindings:Pform.Map.empty
|
||||||
~targets:(Static [])
|
~targets:(Static [])
|
||||||
~scope)))
|
~scope)))
|
||||||
| Pps { loc; pps; flags } ->
|
| Pps { loc; pps; flags } ->
|
||||||
|
@ -542,6 +543,7 @@ let make sctx ~dir ~dep_kind ~lint ~preprocess
|
||||||
~loc
|
~loc
|
||||||
~dir
|
~dir
|
||||||
~dep_kind
|
~dep_kind
|
||||||
|
~bindings:Pform.Map.empty
|
||||||
~targets:(Static [dst])
|
~targets:(Static [dst])
|
||||||
~scope))
|
~scope))
|
||||||
|> setup_reason_rules sctx ~dir in
|
|> setup_reason_rules sctx ~dir in
|
||||||
|
|
|
@ -807,9 +807,10 @@ module Action = struct
|
||||||
end
|
end
|
||||||
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
|
t ~dir ~dep_kind ~targets:targets_written_by_user ~scope
|
||||||
: (Path.t Bindings.t, Action.t) Build.t =
|
: (Path.t Bindings.t, Action.t) Build.t =
|
||||||
|
ignore bindings;
|
||||||
let map_exe = map_exe sctx in
|
let map_exe = map_exe sctx in
|
||||||
if targets_written_by_user = Alias then begin
|
if targets_written_by_user = Alias then begin
|
||||||
match Action.Infer.unexpanded_targets t with
|
match Action.Infer.unexpanded_targets t with
|
||||||
|
|
|
@ -240,6 +240,7 @@ module Action : sig
|
||||||
: t
|
: t
|
||||||
-> loc:Loc.t
|
-> loc:Loc.t
|
||||||
-> ?extra_vars:Value.t list String.Map.t
|
-> ?extra_vars:Value.t list String.Map.t
|
||||||
|
-> bindings:Pform.Var.t Pform.Map.t
|
||||||
-> Action.Unexpanded.t
|
-> Action.Unexpanded.t
|
||||||
-> dir:Path.t
|
-> dir:Path.t
|
||||||
-> dep_kind:Build.lib_dep_kind
|
-> dep_kind:Build.lib_dep_kind
|
||||||
|
|
Loading…
Reference in New Issue