Simplify inference
This commit is contained in:
parent
acd1e3e571
commit
81e6ebd09b
|
@ -553,12 +553,7 @@ module Infer = struct
|
||||||
open Outcome
|
open Outcome
|
||||||
|
|
||||||
let ( +@ ) acc fn = { acc with targets = S.add fn acc.targets }
|
let ( +@ ) acc fn = { acc with targets = S.add fn acc.targets }
|
||||||
let ( +< ) acc fn =
|
let ( +< ) acc fn = { acc with deps = S.add fn acc.deps }
|
||||||
if S.mem fn acc.targets then
|
|
||||||
acc
|
|
||||||
else
|
|
||||||
{ acc with deps = S.add fn acc.deps }
|
|
||||||
let ( -@ ) acc fn = { acc with targets = S.remove fn acc.targets }
|
|
||||||
|
|
||||||
let rec infer acc t =
|
let rec infer acc t =
|
||||||
match t with
|
match t with
|
||||||
|
@ -568,7 +563,7 @@ module Infer = struct
|
||||||
| Cat fn -> acc +< fn
|
| Cat fn -> acc +< fn
|
||||||
| Create_file fn -> acc +@ fn
|
| Create_file fn -> acc +@ fn
|
||||||
| Update_file (fn, _) -> acc +@ fn
|
| Update_file (fn, _) -> acc +@ fn
|
||||||
| Rename (src, dst) -> acc +< src +@ dst -@ src
|
| Rename (src, dst) -> acc +< src +@ dst
|
||||||
| Copy (src, dst)
|
| Copy (src, dst)
|
||||||
| Copy_and_add_line_directive (src, dst)
|
| Copy_and_add_line_directive (src, dst)
|
||||||
| Symlink (src, dst) -> acc +< src +@ dst
|
| Symlink (src, dst) -> acc +< src +@ dst
|
||||||
|
@ -578,13 +573,17 @@ module Infer = struct
|
||||||
| Progn l -> List.fold_left l ~init:acc ~f:infer
|
| Progn l -> List.fold_left l ~init:acc ~f:infer
|
||||||
| Echo _
|
| Echo _
|
||||||
| System _
|
| System _
|
||||||
| Bash _ -> acc
|
| Bash _
|
||||||
| Remove_tree dir ->
|
| Remove_tree _
|
||||||
{ acc with targets = S.filter acc.targets ~f:(fun fn ->
|
|
||||||
not (Path.is_descendant fn ~of_:dir))
|
|
||||||
}
|
|
||||||
| Mkdir _ -> acc
|
| Mkdir _ -> acc
|
||||||
|
|
||||||
let infer t =
|
let infer t =
|
||||||
infer { deps = S.empty; targets = S.empty } t
|
let { deps; targets } = infer { deps = S.empty; targets = S.empty } t in
|
||||||
|
(* A file can be inferred as both a dependency and a target, for instance:
|
||||||
|
|
||||||
|
{[
|
||||||
|
(progn (copy a b) (copy b c))
|
||||||
|
]}
|
||||||
|
*)
|
||||||
|
{ deps = S.diff deps targets; targets }
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,7 +34,11 @@ val updated_files : t -> Path.Set.t
|
||||||
(** Return the list of directories the action chdirs to *)
|
(** Return the list of directories the action chdirs to *)
|
||||||
val chdirs : t -> Path.Set.t
|
val chdirs : t -> Path.Set.t
|
||||||
|
|
||||||
(** Infer dependencies and targets *)
|
(** Infer dependencies and targets.
|
||||||
|
|
||||||
|
This currently doesn't support well (rename ...) and (remove-tree ...). However these
|
||||||
|
are not exposed in the DSL.
|
||||||
|
*)
|
||||||
module Infer : sig
|
module Infer : sig
|
||||||
module Outcome : sig
|
module Outcome : sig
|
||||||
type t =
|
type t =
|
||||||
|
|
Loading…
Reference in New Issue