Skip to content

Commit

Permalink
merge with dir_contents changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aalekseyev committed Mar 26, 2019
2 parents 22903c6 + 5a1c38a commit 9ffcea9
Show file tree
Hide file tree
Showing 51 changed files with 1,145 additions and 451 deletions.
25 changes: 7 additions & 18 deletions src/build.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module Repr = struct
| Second : ('a, 'b) t -> ('c * 'a, 'c * 'b) t
| Split : ('a, 'b) t * ('c, 'd) t -> ('a * 'c, 'b * 'd) t
| Fanout : ('a, 'b) t * ('a, 'c) t -> ('a, 'b * 'c) t
| Paths : Path.Set.t -> ('a, 'a) t
| Paths_for_rule : Path.Set.t -> ('a, 'a) t
| Paths_glob : Path.t * Path.t Predicate.t -> ('a, Path.Set.t) t
(* The reference gets decided in Build_interpret.deps *)
Expand All @@ -30,8 +29,7 @@ module Repr = struct
| Memo : 'a memo -> (unit, 'a) t
| Catch : ('a, 'b) t * (exn -> 'b) -> ('a, 'b) t
| Lazy_no_targets : ('a, 'b) t Lazy.t -> ('a, 'b) t
| Env_var : string -> ('a, 'a) t
| Universe : ('a, 'a) t
| Deps : Dep.Set.t -> ('a, 'a) t

and 'a memo =
{ name : string
Expand Down Expand Up @@ -112,26 +110,17 @@ let rec all = function

let lazy_no_targets t = Lazy_no_targets t

let path p = Paths (Path.Set.singleton p)
let paths ps = Paths (Path.Set.of_list ps)
let path_set ps = Paths ps
let dep d = Deps (Dep.Set.singleton d)
let path p = Deps (Dep.Set.singleton (Dep.file p))
let paths ps = Deps (Dep.Set.of_files ps)
let path_set ps = Deps (Dep.Set.of_files_set ps)
let paths_matching ~loc:_ ~dir pred = Paths_glob (dir, pred)
let vpath vp = Vpath vp
let dyn_paths t = Dyn_paths (t >>^ Path.Set.of_list)
let dyn_path_set t = Dyn_paths t
let dyn_deps t = Dyn_deps t
let paths_for_rule ps = Paths_for_rule ps
let universe = Universe
let env_var s = Env_var s

let of_deps (type a) (d : Dep.Set.t) : (a, a) t =
let init = arr Fn.id in
Dep.Set.fold d ~init ~f:(fun d acc ->
match d with
| Env v -> (Env_var v &&& acc) >>^ snd
| File p -> (path p &&& acc) >>^ snd
| Glob (dir, pred) -> (Paths_glob (dir, pred) &&& acc) >>^ snd
| Universe -> (universe &&& acc) >>^ snd)
let env_var s = Deps (Dep.Set.singleton (Dep.env s))

let catch t ~on_error = Catch (t, on_error)

Expand Down Expand Up @@ -198,7 +187,7 @@ let get_prog = function
>>> dyn_paths (arr (function Error _ -> [] | Ok x -> [x]))

let prog_and_args ?(dir=Path.root) prog args =
of_deps (Arg_spec.static_deps args) &&& arr (fun x -> x)
Deps (Arg_spec.static_deps args) &&& arr (fun x -> x)
>>^ snd
>>>
(get_prog prog &&&
Expand Down
6 changes: 2 additions & 4 deletions src/build.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ val lazy_no_targets : ('a, 'b) t Lazy.t -> ('a, 'b) t
build arrow. *)
val path : Path.t -> ('a, 'a) t

val universe : ('a, 'a) t
val dep : Dep.t -> ('a, 'a) t

val paths : Path.t list -> ('a, 'a) t
val path_set : Path.Set.t -> ('a, 'a) t
Expand Down Expand Up @@ -193,7 +193,6 @@ module Repr : sig
| Second : ('a, 'b) t -> ('c * 'a, 'c * 'b) t
| Split : ('a, 'b) t * ('c, 'd) t -> ('a * 'c, 'b * 'd) t
| Fanout : ('a, 'b) t * ('a, 'c) t -> ('a, 'b * 'c) t
| Paths : Path.Set.t -> ('a, 'a) t
| Paths_for_rule : Path.Set.t -> ('a, 'a) t
| Paths_glob : Path.t * Path.t Predicate.t -> ('a, Path.Set.t) t
| If_file_exists : Path.t * ('a, 'b) if_file_exists_state ref -> ('a, 'b) t
Expand All @@ -207,8 +206,7 @@ module Repr : sig
| Memo : 'a memo -> (unit, 'a) t
| Catch : ('a, 'b) t * (exn -> 'b) -> ('a, 'b) t
| Lazy_no_targets : ('a, 'b) t Lazy.t -> ('a, 'b) t
| Env_var : string -> ('a, 'a) t
| Universe : ('a, 'a) t
| Deps : Dep.Set.t -> ('a, 'a) t

and 'a memo =
{ name : string
Expand Down
15 changes: 4 additions & 11 deletions src/build_interpret.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ let static_deps t ~all_targets =
| Second t -> loop t acc targets_allowed
| Split (a, b) -> loop a (loop b acc targets_allowed) targets_allowed
| Fanout (a, b) -> loop a (loop b acc targets_allowed) targets_allowed
| Paths fns ->
Static_deps.add_action_paths acc fns
| Deps deps ->
Static_deps.add_action_deps acc deps
| Paths_for_rule fns ->
Static_deps.add_rule_paths acc fns
| Paths_glob (dir, pred) ->
Expand Down Expand Up @@ -66,9 +66,6 @@ let static_deps t ~all_targets =
| Memo m -> loop m.t acc targets_allowed
| Catch (t, _) -> loop t acc targets_allowed
| Lazy_no_targets t -> loop (Lazy.force t) acc false
| Env_var var ->
Static_deps.add_action_env_var acc var
| Universe -> Static_deps.add_action_dep acc Dep.universe
in
loop (Build.repr t) Static_deps.empty true

Expand All @@ -84,10 +81,10 @@ let lib_deps =
| Second t -> loop t acc
| Split (a, b) -> loop a (loop b acc)
| Fanout (a, b) -> loop a (loop b acc)
| Paths _ -> acc
| Paths_for_rule _ -> acc
| Vpath _ -> acc
| Paths_glob _ -> acc
| Deps _ -> acc
| Dyn_paths t -> loop t acc
| Dyn_deps t -> loop t acc
| Contents _ -> acc
Expand All @@ -99,8 +96,6 @@ let lib_deps =
| Memo m -> loop m.t acc
| Catch (t, _) -> loop t acc
| Lazy_no_targets t -> loop (Lazy.force t) acc
| Universe -> acc
| Env_var _ -> acc
in
fun t -> loop (Build.repr t) Lib_name.Map.empty

Expand All @@ -116,10 +111,10 @@ let targets =
| Second t -> loop t acc
| Split (a, b) -> loop a (loop b acc)
| Fanout (a, b) -> loop a (loop b acc)
| Paths _ -> acc
| Paths_for_rule _ -> acc
| Vpath _ -> acc
| Paths_glob _ -> acc
| Deps _ -> acc
| Dyn_paths t -> loop t acc
| Dyn_deps t -> loop t acc
| Contents _ -> acc
Expand All @@ -145,8 +140,6 @@ let targets =
| Memo m -> loop m.t acc
| Catch (t, _) -> loop t acc
| Lazy_no_targets _ -> acc
| Universe -> acc
| Env_var _ -> acc
in
fun t -> loop (Build.repr t) []

Expand Down
Loading

0 comments on commit 9ffcea9

Please sign in to comment.