Add Alias.add_{stamp,action}_dep

These functions will be useful to construct alias elsewhere
This commit is contained in:
Rudi Grinberg 2018-01-10 02:11:50 +08:00
parent bfbfc0bf30
commit 6d2152e7b1
3 changed files with 38 additions and 14 deletions

View File

@ -184,3 +184,19 @@ let rules store =
(Path.Set.elements deps))))
in
rule :: acc)
let add_stamp_dep (store: Store.t) (t : t) ~data =
let digest = Digest.string (Sexp.to_string data) in
let digest_path = file_with_digest_suffix t ~digest in
add_deps store t [digest_path];
digest_path
let add_action_dep (store: Store.t) (t : t) ~action ~action_deps =
let data =
let deps = Sexp.To_sexp.list Jbuild.Dep_conf.sexp_of_t action_deps in
let action =
match action with
| None -> Sexp.Atom "none"
| Some a -> List [Atom "some"; Action.Unexpanded.sexp_of_t a] in
Sexp.List [deps ; action] in
add_stamp_dep store t ~data

View File

@ -70,3 +70,21 @@ end
val add_deps : Store.t -> t -> Path.t list -> unit
val rules : Store.t -> Build_interpret.Rule.t list
(** Create an alias dependency for an action and its inputs represented by
[~data]. The path returned is the file that should be represented by the
file the action will create following execution.*)
val add_stamp_dep
: Store.t
-> t
-> data:Sexp.t
-> Path.t
(** Like [add_stamp_dep] but an action (if present) and the dependencies can be
passed in directly. *)
val add_action_dep
: Store.t
-> t
-> action:Action.Unexpanded.t option
-> action_deps:Jbuild.Dep_conf.t list
-> Path.t

View File

@ -570,21 +570,11 @@ module Gen(P : Params) = struct
~scope)
let alias_rules (alias_conf : Alias_conf.t) ~dir ~scope =
let digest =
let deps =
Sexp.To_sexp.list Dep_conf.sexp_of_t alias_conf.deps in
let action =
match alias_conf.action with
| None -> Sexp.Atom "none"
| Some a -> List [Atom "some" ; Action.Unexpanded.sexp_of_t a]
in
Sexp.List [deps ; action]
|> Sexp.to_string
|> Digest.string
in
let alias = Alias.make alias_conf.name ~dir in
let digest_path = Alias.file_with_digest_suffix alias ~digest in
Alias.add_deps (SC.aliases sctx) alias [digest_path];
let digest_path =
Alias.add_action_dep (SC.aliases sctx) alias
~action:alias_conf.action
~action_deps:alias_conf.deps in
let deps = SC.Deps.interpret sctx ~scope ~dir alias_conf.deps in
SC.add_rule sctx
~locks:(interpret_locks ~dir ~scope alias_conf.locks)