Merge pull request #798 from rgrinberg/remove-alias

Remove aliases of Path.{Set,Map}
This commit is contained in:
Rudi Grinberg 2018-05-24 17:38:19 +07:00 committed by GitHub
commit 1dd9262ecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 146 additions and 157 deletions

View File

@ -953,11 +953,10 @@ let sandbox t ~sandboxed ~deps ~targets =
] ]
module Infer = struct module Infer = struct
module S = Path.Set
module Outcome = struct module Outcome = struct
type t = type t =
{ deps : S.t { deps : Path.Set.t
; targets : S.t ; targets : Path.Set.t
} }
end end
open Outcome open Outcome
@ -1036,43 +1035,43 @@ module Infer = struct
{ deps = Pset.diff deps targets; targets } { deps = Pset.diff deps targets; targets }
end [@@inline always] end [@@inline always]
include Make(Ast)(S)(Outcome)(struct include Make(Ast)(Path.Set)(Outcome)(struct
let ( +@ ) acc fn = { acc with targets = S.add acc.targets fn } let ( +@ ) acc fn = { acc with targets = Path.Set.add acc.targets fn }
let ( +< ) acc fn = { acc with deps = S.add acc.deps fn } let ( +< ) acc fn = { acc with deps = Path.Set.add acc.deps fn }
let ( +<! ) acc prog = let ( +<! ) acc prog =
match prog with match prog with
| Ok p -> acc +< p | Ok p -> acc +< p
| Error _ -> acc | Error _ -> acc
end) end)
module Partial = Make(Unexpanded.Partial.Past)(S)(Outcome)(struct module Partial = Make(Unexpanded.Partial.Past)(Path.Set)(Outcome)(struct
let ( +@ ) acc fn = let ( +@ ) acc fn =
match fn with match fn with
| Left fn -> { acc with targets = S.add acc.targets fn } | Left fn -> { acc with targets = Path.Set.add acc.targets fn }
| Right _ -> acc | Right _ -> acc
let ( +< ) acc fn = let ( +< ) acc fn =
match fn with match fn with
| Left fn -> { acc with deps = S.add acc.deps fn } | Left fn -> { acc with deps = Path.Set.add acc.deps fn }
| Right _ -> acc | Right _ -> acc
let ( +<! ) acc fn = let ( +<! ) acc fn =
match (fn : Unexpanded.Partial.program) with match (fn : Unexpanded.Partial.program) with
| Left (This fn) -> { acc with deps = S.add acc.deps fn } | Left (This fn) -> { acc with deps = Path.Set.add acc.deps fn }
| Left (Search _) | Right _ -> acc | Left (Search _) | Right _ -> acc
end) end)
module Partial_with_all_targets = Make(Unexpanded.Partial.Past)(S)(Outcome)(struct module Partial_with_all_targets = Make(Unexpanded.Partial.Past)(Path.Set)(Outcome)(struct
let ( +@ ) acc fn = let ( +@ ) acc fn =
match fn with match fn with
| Left fn -> { acc with targets = S.add acc.targets fn } | Left fn -> { acc with targets = Path.Set.add acc.targets fn }
| Right sw -> | Right sw ->
Loc.fail (SW.loc sw) "Cannot determine this target statically." Loc.fail (SW.loc sw) "Cannot determine this target statically."
let ( +< ) acc fn = let ( +< ) acc fn =
match fn with match fn with
| Left fn -> { acc with deps = S.add acc.deps fn } | Left fn -> { acc with deps = Path.Set.add acc.deps fn }
| Right _ -> acc | Right _ -> acc
let ( +<! ) acc fn = let ( +<! ) acc fn =
match (fn : Unexpanded.Partial.program) with match (fn : Unexpanded.Partial.program) with
| Left (This fn) -> { acc with deps = S.add acc.deps fn } | Left (This fn) -> { acc with deps = Path.Set.add acc.deps fn }
| Left (Search _) | Right _ -> acc | Left (Search _) | Right _ -> acc
end) end)

View File

@ -1,7 +1,5 @@
open Import open Import
module Pset = Path.Set
type 'a t = type 'a t =
| A of string | A of string
| As of string list | As of string list
@ -19,9 +17,9 @@ type 'a t =
let rec add_deps ts set = let rec add_deps ts set =
List.fold_left ts ~init:set ~f:(fun set t -> List.fold_left ts ~init:set ~f:(fun set t ->
match t with match t with
| Dep fn -> Pset.add set fn | Dep fn -> Path.Set.add set fn
| Deps fns | Deps fns
| Hidden_deps fns -> Pset.union set (Pset.of_list fns) | Hidden_deps fns -> Path.Set.union set (Path.Set.of_list fns)
| S ts | S ts
| Concat (_, ts) -> add_deps ts set | Concat (_, ts) -> add_deps ts set
| _ -> set) | _ -> set)
@ -56,7 +54,7 @@ let expand ~dir ts x =
| Target _ | Hidden_targets _ -> die "Target not allowed under Dyn" | Target _ | Hidden_targets _ -> die "Target not allowed under Dyn"
| Dyn _ -> assert false | Dyn _ -> assert false
| Hidden_deps l -> | Hidden_deps l ->
dyn_deps := Pset.union !dyn_deps (Pset.of_list l); dyn_deps := Path.Set.union !dyn_deps (Path.Set.of_list l);
[] []
in in
let rec loop = function let rec loop = function

View File

@ -1,7 +1,5 @@
open Import open Import
module Pset = Path.Set
module Vspec = struct module Vspec = struct
type 'a t = T : Path.t * 'a Vfile_kind.t -> 'a t type 'a t = T : Path.t * 'a Vfile_kind.t -> 'a t
end end
@ -26,7 +24,7 @@ module Repr = struct
| Second : ('a, 'b) t -> ('c * 'a, 'c * 'b) t | Second : ('a, 'b) t -> ('c * 'a, 'c * 'b) t
| Split : ('a, 'b) t * ('c, 'd) t -> ('a * 'c, 'b * 'd) t | Split : ('a, 'b) t * ('c, 'd) t -> ('a * 'c, 'b * 'd) t
| Fanout : ('a, 'b) t * ('a, 'c) t -> ('a, 'b * 'c) t | Fanout : ('a, 'b) t * ('a, 'c) t -> ('a, 'b * 'c) t
| Paths : Pset.t -> ('a, 'a) t | Paths : Path.Set.t -> ('a, 'a) t
| Paths_for_rule : Path.Set.t -> ('a, 'a) t | Paths_for_rule : Path.Set.t -> ('a, 'a) t
| Paths_glob : glob_state ref -> ('a, Path.t list) t | Paths_glob : glob_state ref -> ('a, Path.t list) t
(* The reference gets decided in Build_interpret.deps *) (* The reference gets decided in Build_interpret.deps *)
@ -134,8 +132,8 @@ let rec all = function
>>> >>>
arr (fun (x, y) -> x :: y) arr (fun (x, y) -> x :: y)
let path p = Paths (Pset.singleton p) let path p = Paths (Path.Set.singleton p)
let paths ps = Paths (Pset.of_list ps) let paths ps = Paths (Path.Set.of_list ps)
let path_set ps = Paths ps let path_set ps = Paths ps
let paths_glob ~loc ~dir re = Paths_glob (ref (G_unevaluated (loc, dir, re))) let paths_glob ~loc ~dir re = Paths_glob (ref (G_unevaluated (loc, dir, re)))
let vpath vp = Vpath vp let vpath vp = Vpath vp
@ -206,7 +204,7 @@ let get_prog = function
>>> dyn_paths (arr (function Error _ -> [] | Ok x -> [x])) >>> dyn_paths (arr (function Error _ -> [] | Ok x -> [x]))
let prog_and_args ?(dir=Path.root) prog args = let prog_and_args ?(dir=Path.root) prog args =
Paths (Arg_spec.add_deps args Pset.empty) Paths (Arg_spec.add_deps args Path.Set.empty)
>>> >>>
(get_prog prog &&& (get_prog prog &&&
(arr (Arg_spec.expand ~dir args) (arr (Arg_spec.expand ~dir args)

View File

@ -1,8 +1,6 @@
open Import open Import
open Build.Repr open Build.Repr
module Pset = Path.Set
module Pmap = Path.Map
module Vspec = Build.Vspec module Vspec = Build.Vspec
module Target = struct module Target = struct
@ -15,8 +13,8 @@ module Target = struct
| Vfile (Vspec.T (p, _)) -> p | Vfile (Vspec.T (p, _)) -> p
let paths ts = let paths ts =
List.fold_left ts ~init:Pset.empty ~f:(fun acc t -> List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t ->
Pset.add acc (path t)) Path.Set.add acc (path t))
end end
module Static_deps = struct module Static_deps = struct
@ -62,20 +60,20 @@ let static_deps t ~all_targets ~file_tree =
| Second t -> loop t acc | Second t -> loop t acc
| Split (a, b) -> loop a (loop b acc) | Split (a, b) -> loop a (loop b acc)
| Fanout (a, b) -> loop a (loop b acc) | Fanout (a, b) -> loop a (loop b acc)
| Paths fns -> { acc with action_deps = Pset.union fns acc.action_deps } | Paths fns -> { acc with action_deps = Path.Set.union fns acc.action_deps }
| Paths_for_rule fns -> | Paths_for_rule fns ->
{ acc with rule_deps = Pset.union fns acc.rule_deps } { acc with rule_deps = Path.Set.union fns acc.rule_deps }
| Paths_glob state -> begin | Paths_glob state -> begin
match !state with match !state with
| G_evaluated l -> | G_evaluated l ->
{ acc with action_deps = Pset.union acc.action_deps (Pset.of_list l) } { acc with action_deps = Path.Set.union acc.action_deps (Path.Set.of_list l) }
| G_unevaluated (loc, dir, re) -> | G_unevaluated (loc, dir, re) ->
let targets = all_targets ~dir in let targets = all_targets ~dir in
let result = let result =
Pset.filter targets ~f:(fun path -> Path.Set.filter targets ~f:(fun path ->
Re.execp re (Path.basename path)) Re.execp re (Path.basename path))
in in
if Pset.is_empty result then begin if Path.Set.is_empty result then begin
match inspect_path file_tree dir with match inspect_path file_tree dir with
| None -> | None ->
Loc.warn loc "Directory %s doesn't exist." Loc.warn loc "Directory %s doesn't exist."
@ -89,8 +87,8 @@ let static_deps t ~all_targets ~file_tree =
(* diml: we should probably warn in this case as well *) (* diml: we should probably warn in this case as well *)
() ()
end; end;
state := G_evaluated (Pset.to_list result); state := G_evaluated (Path.Set.to_list result);
let action_deps = Pset.union result acc.action_deps in let action_deps = Path.Set.union result acc.action_deps in
{ acc with action_deps } { acc with action_deps }
end end
| If_file_exists (p, state) -> begin | If_file_exists (p, state) -> begin
@ -99,7 +97,7 @@ let static_deps t ~all_targets ~file_tree =
| Undecided (then_, else_) -> | Undecided (then_, else_) ->
let dir = Path.parent_exn p in let dir = Path.parent_exn p in
let targets = all_targets ~dir in let targets = all_targets ~dir in
if Pset.mem targets p then begin if Path.Set.mem targets p then begin
state := Decided (true, then_); state := Decided (true, then_);
loop then_ acc loop then_ acc
end else begin end else begin
@ -108,15 +106,15 @@ let static_deps t ~all_targets ~file_tree =
end end
end end
| Dyn_paths t -> loop t acc | Dyn_paths t -> loop t acc
| Vpath (Vspec.T (p, _)) -> { acc with rule_deps = Pset.add acc.rule_deps p } | Vpath (Vspec.T (p, _)) -> { acc with rule_deps = Path.Set.add acc.rule_deps p }
| Contents p -> { acc with rule_deps = Pset.add acc.rule_deps p } | Contents p -> { acc with rule_deps = Path.Set.add acc.rule_deps p }
| Lines_of p -> { acc with rule_deps = Pset.add acc.rule_deps p } | Lines_of p -> { acc with rule_deps = Path.Set.add acc.rule_deps p }
| Record_lib_deps _ -> acc | Record_lib_deps _ -> acc
| Fail _ -> acc | Fail _ -> acc
| Memo m -> loop m.t acc | Memo m -> loop m.t acc
| Catch (t, _) -> loop t acc | Catch (t, _) -> loop t acc
in in
loop (Build.repr t) { rule_deps = Pset.empty; action_deps = Pset.empty } loop (Build.repr t) { rule_deps = Path.Set.empty; action_deps = Path.Set.empty }
let lib_deps = let lib_deps =
let rec loop : type a b. (a, b) t -> Build.lib_deps -> Build.lib_deps let rec loop : type a b. (a, b) t -> Build.lib_deps -> Build.lib_deps

View File

@ -1,8 +1,6 @@
open Import open Import
open Fiber.O open Fiber.O
module Pset = Path.Set
module Pmap = Path.Map
module Vspec = Build.Vspec module Vspec = Build.Vspec
(* Where we store stamp files for aliases *) (* Where we store stamp files for aliases *)
@ -26,11 +24,11 @@ module Promoted_to_delete = struct
[] []
let dump () = let dump () =
let db = Pset.union (Pset.of_list !db) (Pset.of_list (load ())) in let db = Path.Set.union (Path.Set.of_list !db) (Path.Set.of_list (load ())) in
if Path.build_dir_exists () then if Path.build_dir_exists () then
Io.write_file fn Io.write_file fn
(String.concat ~sep:"" (String.concat ~sep:""
(List.map (Pset.to_list db) ~f:(fun p -> (List.map (Path.Set.to_list db) ~f:(fun p ->
Sexp.to_string (Path.sexp_of_t p) ^ "\n"))) Sexp.to_string (Path.sexp_of_t p) ^ "\n")))
end end
@ -42,21 +40,21 @@ module Dependency_path = struct
{ (* Reason why this rule was visited *) { (* Reason why this rule was visited *)
requested_file : Path.t requested_file : Path.t
; (* All targets of the rule *) ; (* All targets of the rule *)
targets : Pset.t targets : Path.Set.t
} }
type t = type t =
{ dependency_path : rule_info list { dependency_path : rule_info list
; (* Union of all [targets] fields in [dependency_path]. Depending on any of these ; (* Union of all [targets] fields in [dependency_path]. Depending on any of these
means that there is a cycle. *) means that there is a cycle. *)
targets_seen : Pset.t targets_seen : Path.Set.t
} }
let var = Fiber.Var.create () let var = Fiber.Var.create ()
let empty = let empty =
{ dependency_path = [] { dependency_path = []
; targets_seen = Pset.empty ; targets_seen = Path.Set.empty
} }
let dependency_cycle last dep_path = let dependency_cycle last dep_path =
@ -64,7 +62,7 @@ module Dependency_path = struct
match dep_path with match dep_path with
| [] -> assert false | [] -> assert false
| { requested_file; targets } :: dep_path -> | { requested_file; targets } :: dep_path ->
if Pset.mem targets last then if Path.Set.mem targets last then
last :: acc last :: acc
else else
build_loop (requested_file :: acc) dep_path build_loop (requested_file :: acc) dep_path
@ -77,14 +75,14 @@ module Dependency_path = struct
let push requested_file ~targets ~f = let push requested_file ~targets ~f =
Fiber.Var.get var >>= fun x -> Fiber.Var.get var >>= fun x ->
let t = Option.value x ~default:empty in let t = Option.value x ~default:empty in
if Pset.mem t.targets_seen requested_file then if Path.Set.mem t.targets_seen requested_file then
dependency_cycle requested_file t.dependency_path; dependency_cycle requested_file t.dependency_path;
let dependency_path = let dependency_path =
{ requested_file; targets } :: t.dependency_path { requested_file; targets } :: t.dependency_path
in in
let t = let t =
{ dependency_path { dependency_path
; targets_seen = Pset.union targets t.targets_seen ; targets_seen = Path.Set.union targets t.targets_seen
} }
in in
let on_error exn = let on_error exn =
@ -94,10 +92,10 @@ module Dependency_path = struct
end end
module Exec_status = struct module Exec_status = struct
type rule_evaluation = (Action.t * Pset.t) Fiber.Future.t type rule_evaluation = (Action.t * Path.Set.t) Fiber.Future.t
type rule_execution = unit Fiber.Future.t type rule_execution = unit Fiber.Future.t
type eval_rule = unit -> (Action.t * Pset.t) Fiber.t type eval_rule = unit -> (Action.t * Path.Set.t) Fiber.t
type exec_rule = rule_evaluation -> unit Fiber.t type exec_rule = rule_evaluation -> unit Fiber.t
module Evaluating_rule = struct module Evaluating_rule = struct
@ -166,9 +164,9 @@ module Internal_rule = struct
type t = type t =
{ id : Id.t { id : Id.t
; rule_deps : Pset.t ; rule_deps : Path.Set.t
; static_deps : Pset.t ; static_deps : Path.Set.t
; targets : Pset.t ; targets : Path.Set.t
; context : Context.t option ; context : Context.t option
; build : (unit, Action.t) Build.t ; build : (unit, Action.t) Build.t
; mode : Jbuild.Rule.Mode.t ; mode : Jbuild.Rule.Mode.t
@ -333,8 +331,8 @@ module Dir_status = struct
type alias = type alias =
{ mutable deps : Pset.t { mutable deps : Path.Set.t
; mutable dyn_deps : (unit, Pset.t) Build.t ; mutable dyn_deps : (unit, Path.Set.t) Build.t
; mutable actions : alias_action list ; mutable actions : alias_action list
} }
@ -346,7 +344,7 @@ module Dir_status = struct
type t = type t =
| Collecting_rules of rules_collector | Collecting_rules of rules_collector
| Loaded of Pset.t (* set of targets in the directory *) | Loaded of Path.Set.t (* set of targets in the directory *)
| Forward of Path.t (* Load this directory first *) | Forward of Path.t (* Load this directory first *)
| Failed_to_load | Failed_to_load
end end
@ -391,7 +389,7 @@ type t =
} }
let string_of_paths set = let string_of_paths set =
Pset.to_list set Path.Set.to_list set
|> List.map ~f:(fun p -> sprintf "- %s" |> List.map ~f:(fun p -> sprintf "- %s"
(Path.to_string_maybe_quoted (Path.to_string_maybe_quoted
(Path.drop_optional_build_context p))) (Path.drop_optional_build_context p)))
@ -407,19 +405,19 @@ let get_dir_status t ~dir =
Dir_status.Loaded (File_tree.files_of t.file_tree dir) Dir_status.Loaded (File_tree.files_of t.file_tree dir)
else if dir = Path.build_dir then else if dir = Path.build_dir then
(* Not allowed to look here *) (* Not allowed to look here *)
Dir_status.Loaded Pset.empty Dir_status.Loaded Path.Set.empty
else if not (Path.is_local dir) then else if not (Path.is_local dir) then
Dir_status.Loaded Dir_status.Loaded
(match Path.readdir dir with (match Path.readdir dir with
| exception _ -> Path.Set.empty | exception _ -> Path.Set.empty
| files -> | files ->
Pset.of_list (List.map files ~f:(Path.relative dir))) Path.Set.of_list (List.map files ~f:(Path.relative dir)))
else begin else begin
let (ctx, sub_dir) = Option.value_exn (Path.extract_build_context dir) in let (ctx, sub_dir) = Option.value_exn (Path.extract_build_context dir) in
if ctx = ".aliases" then if ctx = ".aliases" then
Forward (Path.(append build_dir) sub_dir) Forward (Path.(append build_dir) sub_dir)
else if ctx <> "install" && not (String.Map.mem t.contexts ctx) then else if ctx <> "install" && not (String.Map.mem t.contexts ctx) then
Dir_status.Loaded Pset.empty Dir_status.Loaded Path.Set.empty
else else
Collecting_rules Collecting_rules
{ rules = [] { rules = []
@ -457,7 +455,7 @@ module Build_exec = struct
let exec bs t x = let exec bs t x =
let rec exec let rec exec
: type a b. Pset.t ref -> (a, b) t -> a -> b = fun dyn_deps t x -> : type a b. Path.Set.t ref -> (a, b) t -> a -> b = fun dyn_deps t x ->
match t with match t with
| Arr f -> f x | Arr f -> f x
| Targets _ -> x | Targets _ -> x
@ -492,7 +490,7 @@ module Build_exec = struct
Option.value_exn file.data Option.value_exn file.data
| Dyn_paths t -> | Dyn_paths t ->
let fns = exec dyn_deps t x in let fns = exec dyn_deps t x in
dyn_deps := Pset.union !dyn_deps fns; dyn_deps := Path.Set.union !dyn_deps fns;
x x
| Record_lib_deps _ -> x | Record_lib_deps _ -> x
| Fail { fail } -> fail () | Fail { fail } -> fail ()
@ -507,23 +505,23 @@ module Build_exec = struct
| Memo m -> | Memo m ->
match m.state with match m.state with
| Evaluated (x, deps) -> | Evaluated (x, deps) ->
dyn_deps := Pset.union !dyn_deps deps; dyn_deps := Path.Set.union !dyn_deps deps;
x x
| Evaluating -> | Evaluating ->
die "Dependency cycle evaluating memoized build arrow %s" m.name die "Dependency cycle evaluating memoized build arrow %s" m.name
| Unevaluated -> | Unevaluated ->
m.state <- Evaluating; m.state <- Evaluating;
let dyn_deps' = ref Pset.empty in let dyn_deps' = ref Path.Set.empty in
match exec dyn_deps' m.t x with match exec dyn_deps' m.t x with
| x -> | x ->
m.state <- Evaluated (x, !dyn_deps'); m.state <- Evaluated (x, !dyn_deps');
dyn_deps := Pset.union !dyn_deps !dyn_deps'; dyn_deps := Path.Set.union !dyn_deps !dyn_deps';
x x
| exception exn -> | exception exn ->
m.state <- Unevaluated; m.state <- Unevaluated;
reraise exn reraise exn
in in
let dyn_deps = ref Pset.empty in let dyn_deps = ref Path.Set.empty in
let result = exec dyn_deps (Build.repr t) x in let result = exec dyn_deps (Build.repr t) x in
(result, !dyn_deps) (result, !dyn_deps)
end end
@ -580,29 +578,29 @@ let create_file_specs t targets rule ~copy_source =
(* This contains the targets of the actions that are being executed. On exit, we need to (* This contains the targets of the actions that are being executed. On exit, we need to
delete them as they might contain garbage *) delete them as they might contain garbage *)
let pending_targets = ref Pset.empty let pending_targets = ref Path.Set.empty
let () = let () =
at_exit (fun () -> at_exit (fun () ->
let fns = !pending_targets in let fns = !pending_targets in
pending_targets := Pset.empty; pending_targets := Path.Set.empty;
Pset.iter fns ~f:Path.unlink_no_err) Path.Set.iter fns ~f:Path.unlink_no_err)
let clear_targets_digests_after_rule_execution targets = let clear_targets_digests_after_rule_execution targets =
let missing = let missing =
List.fold_left targets ~init:Pset.empty ~f:(fun acc fn -> List.fold_left targets ~init:Path.Set.empty ~f:(fun acc fn ->
match Unix.lstat (Path.to_string fn) with match Unix.lstat (Path.to_string fn) with
| exception _ -> Pset.add acc fn | exception _ -> Path.Set.add acc fn
| (_ : Unix.stats) -> | (_ : Unix.stats) ->
Utils.Cached_digest.remove fn; Utils.Cached_digest.remove fn;
acc) acc)
in in
if not (Pset.is_empty missing) then if not (Path.Set.is_empty missing) then
die "@{<error>Error@}: Rule failed to generate the following targets:\n%s" die "@{<error>Error@}: Rule failed to generate the following targets:\n%s"
(string_of_paths missing) (string_of_paths missing)
let make_local_dirs t paths = let make_local_dirs t paths =
Pset.iter paths ~f:(fun path -> Path.Set.iter paths ~f:(fun path ->
match Path.kind path with match Path.kind path with
| Local path -> | Local path ->
if not (Path.Local.Set.mem t.local_mkdirs path) then begin if not (Path.Local.Set.mem t.local_mkdirs path) then begin
@ -612,7 +610,7 @@ let make_local_dirs t paths =
| _ -> ()) | _ -> ())
let make_local_parent_dirs t paths ~map_path = let make_local_parent_dirs t paths ~map_path =
Pset.iter paths ~f:(fun path -> Path.Set.iter paths ~f:(fun path ->
match Path.kind (map_path path) with match Path.kind (map_path path) with
| Local path when not (Path.Local.is_root path) -> | Local path when not (Path.Local.is_root path) ->
let parent = Path.Local.parent path in let parent = Path.Local.parent path in
@ -650,7 +648,7 @@ let remove_old_artifacts t ~dir ~subdirs_to_keep =
| All -> () | All -> ()
| These set -> | These set ->
if String.Set.mem set fn || if String.Set.mem set fn ||
Pset.mem t.build_dirs_to_keep path then Path.Set.mem t.build_dirs_to_keep path then
() ()
else else
Path.rm_rf path Path.rm_rf path
@ -709,14 +707,14 @@ let rec compile_rule t ?(copy_source=false) pre_rule =
wait_for_deps t static_deps) wait_for_deps t static_deps)
(fun () -> (fun () ->
Fiber.Future.wait rule_evaluation >>= fun (action, dyn_deps) -> Fiber.Future.wait rule_evaluation >>= fun (action, dyn_deps) ->
wait_for_deps t (Pset.diff dyn_deps static_deps) wait_for_deps t (Path.Set.diff dyn_deps static_deps)
>>| fun () -> >>| fun () ->
(action, dyn_deps)) (action, dyn_deps))
>>= fun (action, dyn_deps) -> >>= fun (action, dyn_deps) ->
make_local_parent_dirs t targets ~map_path:(fun x -> x); make_local_parent_dirs t targets ~map_path:(fun x -> x);
let all_deps = Pset.union static_deps dyn_deps in let all_deps = Path.Set.union static_deps dyn_deps in
let all_deps_as_list = Pset.to_list all_deps in let all_deps_as_list = Path.Set.to_list all_deps in
let targets_as_list = Pset.to_list targets in let targets_as_list = Path.Set.to_list targets in
let hash = let hash =
let trace = let trace =
(List.map all_deps_as_list ~f:(fun fn -> (List.map all_deps_as_list ~f:(fun fn ->
@ -756,7 +754,7 @@ let rec compile_rule t ?(copy_source=false) pre_rule =
begin begin
if deps_or_rule_changed || targets_missing || force then begin if deps_or_rule_changed || targets_missing || force then begin
List.iter targets_as_list ~f:Path.unlink_no_err; List.iter targets_as_list ~f:Path.unlink_no_err;
pending_targets := Pset.union targets !pending_targets; pending_targets := Path.Set.union targets !pending_targets;
let action = let action =
match sandbox_dir with match sandbox_dir with
| Some sandbox_dir -> | Some sandbox_dir ->
@ -781,7 +779,7 @@ let rec compile_rule t ?(copy_source=false) pre_rule =
Action.exec ~context ~targets action) >>| fun () -> Action.exec ~context ~targets action) >>| fun () ->
Option.iter sandbox_dir ~f:Path.rm_rf; Option.iter sandbox_dir ~f:Path.rm_rf;
(* All went well, these targets are no longer pending *) (* All went well, these targets are no longer pending *)
pending_targets := Pset.diff !pending_targets targets; pending_targets := Path.Set.diff !pending_targets targets;
clear_targets_digests_after_rule_execution targets_as_list clear_targets_digests_after_rule_execution targets_as_list
end else end else
Fiber.return () Fiber.return ()
@ -790,7 +788,7 @@ let rec compile_rule t ?(copy_source=false) pre_rule =
match mode with match mode with
| Standard | Fallback | Not_a_rule_stanza | Ignore_source_files -> () | Standard | Fallback | Not_a_rule_stanza | Ignore_source_files -> ()
| Promote | Promote_but_delete_on_clean -> | Promote | Promote_but_delete_on_clean ->
Pset.iter targets ~f:(fun path -> Path.Set.iter targets ~f:(fun path ->
let in_source_tree = Option.value_exn (Path.drop_build_context path) in let in_source_tree = Option.value_exn (Path.drop_build_context path) in
if not (Path.exists in_source_tree) || if not (Path.exists in_source_tree) ||
(Utils.Cached_digest.file path <> (Utils.Cached_digest.file path <>
@ -819,7 +817,7 @@ let rec compile_rule t ?(copy_source=false) pre_rule =
create_file_specs t target_specs rule ~copy_source create_file_specs t target_specs rule ~copy_source
and setup_copy_rules t ~ctx_dir ~non_target_source_files = and setup_copy_rules t ~ctx_dir ~non_target_source_files =
Pset.iter non_target_source_files ~f:(fun path -> Path.Set.iter non_target_source_files ~f:(fun path ->
let ctx_path = Path.append ctx_dir path in let ctx_path = Path.append ctx_dir path in
let build = Build.copy ~src:path ~dst:ctx_path in let build = Build.copy ~src:path ~dst:ctx_path in
(* We temporarily allow overrides while setting up copy rules from (* We temporarily allow overrides while setting up copy rules from
@ -830,7 +828,7 @@ and setup_copy_rules t ~ctx_dir ~non_target_source_files =
should allow it on a case-by-case basis though. *) should allow it on a case-by-case basis though. *)
compile_rule t (Pre_rule.make build ~context:None) ~copy_source:true) compile_rule t (Pre_rule.make build ~context:None) ~copy_source:true)
and load_dir t ~dir = ignore (load_dir_and_get_targets t ~dir : Pset.t) and load_dir t ~dir = ignore (load_dir_and_get_targets t ~dir : Path.Set.t)
and targets_of t ~dir = load_dir_and_get_targets t ~dir and targets_of t ~dir = load_dir_and_get_targets t ~dir
and load_dir_and_get_targets t ~dir = and load_dir_and_get_targets t ~dir =
@ -894,7 +892,7 @@ and load_dir_step2_exn t ~dir ~collector ~lazy_generators =
let alias_dir = Path.append (Path.relative alias_dir context_name) sub_dir in let alias_dir = Path.append (Path.relative alias_dir context_name) sub_dir in
let alias_rules, alias_stamp_files = let alias_rules, alias_stamp_files =
let open Build.O in let open Build.O in
String.Map.foldi collector.aliases ~init:([], Pset.empty) String.Map.foldi collector.aliases ~init:([], Path.Set.empty)
~f:(fun name { Dir_status. deps; dyn_deps; actions } (rules, alias_stamp_files) -> ~f:(fun name { Dir_status. deps; dyn_deps; actions } (rules, alias_stamp_files) ->
let base_path = Path.relative alias_dir name in let base_path = Path.relative alias_dir name in
let rules, deps = let rules, deps =
@ -909,7 +907,7 @@ and load_dir_step2_exn t ~dir ~collector ~lazy_generators =
Pre_rule.make ~locks ~context:(Some context) Pre_rule.make ~locks ~context:(Some context)
(Build.progn [ action; Build.create_file path ]) (Build.progn [ action; Build.create_file path ])
in in
(rule :: rules, Pset.add deps path)) (rule :: rules, Path.Set.add deps path))
in in
let path = Path.extend_basename base_path ~suffix:Alias0.suffix in let path = Path.extend_basename base_path ~suffix:Alias0.suffix in
(Pre_rule.make (Pre_rule.make
@ -918,30 +916,30 @@ and load_dir_step2_exn t ~dir ~collector ~lazy_generators =
dyn_deps >>> dyn_deps >>>
Build.dyn_path_set (Build.arr (fun x -> x)) Build.dyn_path_set (Build.arr (fun x -> x))
>>^ (fun dyn_deps -> >>^ (fun dyn_deps ->
let deps = Pset.union deps dyn_deps in let deps = Path.Set.union deps dyn_deps in
Action.with_stdout_to path Action.with_stdout_to path
(Action.digest_files (Pset.to_list deps))) (Action.digest_files (Path.Set.to_list deps)))
>>> >>>
Build.action_dyn () ~targets:[path]) Build.action_dyn () ~targets:[path])
:: rules, :: rules,
Pset.add alias_stamp_files path)) Path.Set.add alias_stamp_files path))
in in
Hashtbl.replace t.dirs ~key:alias_dir ~data:(Loaded alias_stamp_files); Hashtbl.replace t.dirs ~key:alias_dir ~data:(Loaded alias_stamp_files);
(* Compute the set of targets and the set of source files that must not be copied *) (* Compute the set of targets and the set of source files that must not be copied *)
let user_rule_targets, source_files_to_ignore = let user_rule_targets, source_files_to_ignore =
List.fold_left rules ~init:(Pset.empty, Pset.empty) List.fold_left rules ~init:(Path.Set.empty, Path.Set.empty)
~f:(fun (acc_targets, acc_ignored) { Pre_rule.targets; mode; _ } -> ~f:(fun (acc_targets, acc_ignored) { Pre_rule.targets; mode; _ } ->
let targets = Build_interpret.Target.paths targets in let targets = Build_interpret.Target.paths targets in
(Pset.union targets acc_targets, (Path.Set.union targets acc_targets,
match mode with match mode with
| Promote | Promote_but_delete_on_clean | Ignore_source_files -> | Promote | Promote_but_delete_on_clean | Ignore_source_files ->
Pset.union targets acc_ignored Path.Set.union targets acc_ignored
| _ -> | _ ->
acc_ignored)) acc_ignored))
in in
let source_files_to_ignore = let source_files_to_ignore =
Pset.map source_files_to_ignore ~f:(fun p -> Path.Set.map source_files_to_ignore ~f:(fun p ->
Option.value_exn (Path.drop_build_context p)) Option.value_exn (Path.drop_build_context p))
in in
@ -957,18 +955,18 @@ and load_dir_step2_exn t ~dir ~collector ~lazy_generators =
assert (String.Map.mem t.contexts ctx_name); assert (String.Map.mem t.contexts ctx_name);
let files, subdirs = let files, subdirs =
match File_tree.find_dir t.file_tree sub_dir with match File_tree.find_dir t.file_tree sub_dir with
| None -> (Pset.empty, String.Set.empty) | None -> (Path.Set.empty, String.Set.empty)
| Some dir -> | Some dir ->
(File_tree.Dir.file_paths dir, (File_tree.Dir.file_paths dir,
File_tree.Dir.sub_dir_names dir) File_tree.Dir.sub_dir_names dir)
in in
let files = Pset.diff files source_files_to_ignore in let files = Path.Set.diff files source_files_to_ignore in
if Pset.is_empty files then if Path.Set.is_empty files then
(user_rule_targets, None, subdirs) (user_rule_targets, None, subdirs)
else else
let ctx_path = Path.(relative build_dir) context_name in let ctx_path = Path.(relative build_dir) context_name in
(Pset.union user_rule_targets (Path.Set.union user_rule_targets
(Pset.map files ~f:(Path.append ctx_path)), (Path.Set.map files ~f:(Path.append ctx_path)),
Some (ctx_path, files), Some (ctx_path, files),
subdirs) subdirs)
in in
@ -992,9 +990,9 @@ and load_dir_step2_exn t ~dir ~collector ~lazy_generators =
| Not_a_rule_stanza | Ignore_source_files -> true | Not_a_rule_stanza | Ignore_source_files -> true
| Fallback -> | Fallback ->
let source_files_for_targtes = let source_files_for_targtes =
List.fold_left rule.targets ~init:Pset.empty List.fold_left rule.targets ~init:Path.Set.empty
~f:(fun acc target -> ~f:(fun acc target ->
Pset.add acc Path.Set.add acc
(Build_interpret.Target.path target (Build_interpret.Target.path target
|> Path.drop_build_context |> Path.drop_build_context
(* All targets are in [dir] and we know it (* All targets are in [dir] and we know it
@ -1003,19 +1001,19 @@ and load_dir_step2_exn t ~dir ~collector ~lazy_generators =
call can't fail. *) call can't fail. *)
|> Option.value_exn)) |> Option.value_exn))
in in
if Pset.is_subset source_files_for_targtes ~of_:to_copy then if Path.Set.is_subset source_files_for_targtes ~of_:to_copy then
(* All targets are present *) (* All targets are present *)
false false
else begin else begin
if Pset.is_empty (Pset.inter source_files_for_targtes to_copy) then if Path.Set.is_empty (Path.Set.inter source_files_for_targtes to_copy) then
(* No target is present *) (* No target is present *)
true true
else begin else begin
let absent_targets = let absent_targets =
Pset.diff source_files_for_targtes to_copy Path.Set.diff source_files_for_targtes to_copy
in in
let present_targets = let present_targets =
Pset.diff source_files_for_targtes absent_targets Path.Set.diff source_files_for_targtes absent_targets
in in
Loc.fail Loc.fail
(rule_loc (rule_loc
@ -1098,7 +1096,7 @@ and wait_for_file_found fn (File_spec.T file) =
Fiber.Future.wait rule_execution) Fiber.Future.wait rule_execution)
and wait_for_deps t deps = and wait_for_deps t deps =
Fiber.parallel_iter (Pset.to_list deps) ~f:(wait_for_file t) Fiber.parallel_iter (Path.Set.to_list deps) ~f:(wait_for_file t)
let stamp_file_for_files_of t ~dir ~ext = let stamp_file_for_files_of t ~dir ~ext =
let files_of_dir = let files_of_dir =
@ -1142,8 +1140,8 @@ module Trace = struct
let dump (trace : t) = let dump (trace : t) =
let sexp = let sexp =
Sexp.List ( Sexp.List (
Hashtbl.foldi trace ~init:Pmap.empty ~f:(fun key data acc -> Hashtbl.foldi trace ~init:Path.Map.empty ~f:(fun key data acc ->
Pmap.add acc key data) Path.Map.add acc key data)
|> Path.Map.to_list |> Path.Map.to_list
|> List.map ~f:(fun (path, hash) -> |> List.map ~f:(fun (path, hash) ->
Sexp.List [ Path.sexp_of_t path; Sexp.List [ Path.sexp_of_t path;
@ -1199,7 +1197,7 @@ let create ~contexts ~file_tree ~hook =
; file_tree ; file_tree
; gen_rules = String.Map.map contexts ~f:(fun _ ~dir:_ -> ; gen_rules = String.Map.map contexts ~f:(fun _ ~dir:_ ->
die "gen_rules called too early") die "gen_rules called too early")
; build_dirs_to_keep = Pset.empty ; build_dirs_to_keep = Path.Set.empty
; files_of = Hashtbl.create 1024 ; files_of = Hashtbl.create 1024
; prefix = None ; prefix = None
; hook ; hook
@ -1217,7 +1215,7 @@ let eval_request t ~request ~process_target =
in in
let process_targets ts = let process_targets ts =
Fiber.parallel_iter (Pset.to_list ts) ~f:process_target Fiber.parallel_iter (Path.Set.to_list ts) ~f:process_target
in in
Fiber.fork_and_join_unit Fiber.fork_and_join_unit
@ -1226,7 +1224,7 @@ let eval_request t ~request ~process_target =
wait_for_deps t rule_deps wait_for_deps t rule_deps
>>= fun () -> >>= fun () ->
let result, dyn_deps = Build_exec.exec t request () in let result, dyn_deps = Build_exec.exec t request () in
process_targets (Pset.diff dyn_deps static_deps) process_targets (Path.Set.diff dyn_deps static_deps)
>>| fun () -> >>| fun () ->
result) result)
@ -1241,7 +1239,7 @@ let update_universe t =
else else
0 0
in in
make_local_dirs t (Pset.singleton Path.build_dir); make_local_dirs t (Path.Set.singleton Path.build_dir);
Io.write_file universe_file (Sexp.to_string (Sexp.To_sexp.int n)) Io.write_file universe_file (Sexp.to_string (Sexp.To_sexp.int n))
let do_build t ~request = let do_build t ~request =
@ -1267,8 +1265,8 @@ let rules_for_targets t targets =
~key:(fun (r : Internal_rule.t) -> r.id) ~key:(fun (r : Internal_rule.t) -> r.id)
~deps:(fun (r : Internal_rule.t) -> ~deps:(fun (r : Internal_rule.t) ->
rules_for_files t rules_for_files t
(Pset.to_list (Path.Set.to_list
(Pset.union (Path.Set.union
r.static_deps r.static_deps
r.rule_deps))) r.rule_deps)))
with with
@ -1277,7 +1275,7 @@ let rules_for_targets t targets =
die "dependency cycle detected:\n %s" die "dependency cycle detected:\n %s"
(List.map cycle ~f:(fun rule -> (List.map cycle ~f:(fun rule ->
Path.to_string (Option.value_exn Path.to_string (Option.value_exn
(Pset.choose rule.Internal_rule.targets))) (Path.Set.choose rule.Internal_rule.targets)))
|> String.concat ~sep:"\n-> ") |> String.concat ~sep:"\n-> ")
let static_deps_of_request t request = let static_deps_of_request t request =
@ -1287,22 +1285,22 @@ let static_deps_of_request t request =
} = Build_interpret.static_deps request ~all_targets:(targets_of t) } = Build_interpret.static_deps request ~all_targets:(targets_of t)
~file_tree:t.file_tree ~file_tree:t.file_tree
in in
Pset.to_list (Pset.union rule_deps action_deps) Path.Set.to_list (Path.Set.union rule_deps action_deps)
let all_lib_deps t ~request = let all_lib_deps t ~request =
let targets = static_deps_of_request t request in let targets = static_deps_of_request t request in
List.fold_left (rules_for_targets t targets) ~init:Pmap.empty List.fold_left (rules_for_targets t targets) ~init:Path.Map.empty
~f:(fun acc (rule : Internal_rule.t) -> ~f:(fun acc (rule : Internal_rule.t) ->
let deps = Build_interpret.lib_deps rule.build in let deps = Build_interpret.lib_deps rule.build in
if String.Map.is_empty deps then if String.Map.is_empty deps then
acc acc
else else
let deps = let deps =
match Pmap.find acc rule.dir with match Path.Map.find acc rule.dir with
| None -> deps | None -> deps
| Some deps' -> Build.merge_lib_deps deps deps' | Some deps' -> Build.merge_lib_deps deps deps'
in in
Pmap.add acc rule.dir deps) Path.Map.add acc rule.dir deps)
let all_lib_deps_by_context t ~request = let all_lib_deps_by_context t ~request =
let targets = static_deps_of_request t request in let targets = static_deps_of_request t request in
@ -1339,7 +1337,7 @@ module Rule_set = Set.Make(Rule)
let rules_for_files rules paths = let rules_for_files rules paths =
List.fold_left paths ~init:Rule_set.empty ~f:(fun acc path -> List.fold_left paths ~init:Rule_set.empty ~f:(fun acc path ->
match Pmap.find rules path with match Path.Map.find rules path with
| None -> acc | None -> acc
| Some rule -> Rule_set.add acc rule) | Some rule -> Rule_set.add acc rule)
|> Rule_set.to_list |> Rule_set.to_list
@ -1379,7 +1377,7 @@ let build_rules_internal ?(recursive=false) t ~request =
>>| fun (action, dyn_deps) -> >>| fun (action, dyn_deps) ->
{ Rule. { Rule.
id = ir.id id = ir.id
; deps = Pset.union ir.static_deps dyn_deps ; deps = Path.Set.union ir.static_deps dyn_deps
; targets = ir.targets ; targets = ir.targets
; context = ir.context ; context = ir.context
; action = action ; action = action
@ -1390,33 +1388,33 @@ let build_rules_internal ?(recursive=false) t ~request =
Fiber.return () Fiber.return ()
else else
Fiber.Future.wait rule >>= fun rule -> Fiber.Future.wait rule >>= fun rule ->
Fiber.parallel_iter (Pset.to_list rule.deps) ~f:loop Fiber.parallel_iter (Path.Set.to_list rule.deps) ~f:loop
end end
in in
let targets = ref Pset.empty in let targets = ref Path.Set.empty in
eval_request t ~request ~process_target:(fun fn -> eval_request t ~request ~process_target:(fun fn ->
targets := Pset.add !targets fn; targets := Path.Set.add !targets fn;
loop fn) loop fn)
>>= fun () -> >>= fun () ->
Fiber.all (List.map !rules ~f:Fiber.Future.wait) Fiber.all (List.map !rules ~f:Fiber.Future.wait)
>>| fun rules -> >>| fun rules ->
let rules = let rules =
List.fold_left rules ~init:Pmap.empty ~f:(fun acc (r : Rule.t) -> List.fold_left rules ~init:Path.Map.empty ~f:(fun acc (r : Rule.t) ->
Pset.fold r.targets ~init:acc ~f:(fun fn acc -> Path.Set.fold r.targets ~init:acc ~f:(fun fn acc ->
Pmap.add acc fn r)) Path.Map.add acc fn r))
in in
match match
Rule.Id.Top_closure.top_closure Rule.Id.Top_closure.top_closure
(rules_for_files rules (Pset.to_list !targets)) (rules_for_files rules (Path.Set.to_list !targets))
~key:(fun (r : Rule.t) -> r.id) ~key:(fun (r : Rule.t) -> r.id)
~deps:(fun (r : Rule.t) -> ~deps:(fun (r : Rule.t) ->
rules_for_files rules (Pset.to_list r.deps)) rules_for_files rules (Path.Set.to_list r.deps))
with with
| Ok l -> l | Ok l -> l
| Error cycle -> | Error cycle ->
die "dependency cycle detected:\n %s" die "dependency cycle detected:\n %s"
(List.map cycle ~f:(fun rule -> (List.map cycle ~f:(fun rule ->
Path.to_string (Option.value_exn (Pset.choose rule.Rule.targets))) Path.to_string (Option.value_exn (Path.Set.choose rule.Rule.targets)))
|> String.concat ~sep:"\n-> ") |> String.concat ~sep:"\n-> ")
let build_rules ?recursive t ~request = let build_rules ?recursive t ~request =
@ -1454,22 +1452,22 @@ let package_deps t pkg files =
Option.value_exn (Fiber.Future.peek rule_evaluation) Option.value_exn (Fiber.Future.peek rule_evaluation)
| Not_started _ -> assert false | Not_started _ -> assert false
in in
Pset.fold (Pset.union ir.static_deps dyn_deps) ~init:acc ~f:loop Path.Set.fold (Path.Set.union ir.static_deps dyn_deps) ~init:acc ~f:loop
end end
in in
let open Build.O in let open Build.O in
Build.paths_for_rule files >>^ fun () -> Build.paths_for_rule files >>^ fun () ->
(* We know that at this point of execution, all the relevant ivars (* We know that at this point of execution, all the relevant ivars
have been filled *) have been filled *)
Pset.fold files ~init:Package.Name.Set.empty ~f:loop_deps Path.Set.fold files ~init:Package.Name.Set.empty ~f:loop_deps
(* +-----------------------------------------------------------------+ (* +-----------------------------------------------------------------+
| Adding rules to the system | | Adding rules to the system |
+-----------------------------------------------------------------+ *) +-----------------------------------------------------------------+ *)
let rec add_build_dir_to_keep t ~dir = let rec add_build_dir_to_keep t ~dir =
if not (Pset.mem t.build_dirs_to_keep dir) then begin if not (Path.Set.mem t.build_dirs_to_keep dir) then begin
t.build_dirs_to_keep <- Pset.add t.build_dirs_to_keep dir; t.build_dirs_to_keep <- Path.Set.add t.build_dirs_to_keep dir;
Option.iter (Path.parent dir) ~f:(fun dir -> Option.iter (Path.parent dir) ~f:(fun dir ->
if not (Path.is_root dir) then if not (Path.is_root dir) then
add_build_dir_to_keep t ~dir) add_build_dir_to_keep t ~dir)
@ -1537,7 +1535,7 @@ let on_load_dir t ~dir ~f =
p.lazy_generators <- f :: lazy_generators p.lazy_generators <- f :: lazy_generators
let eval_glob t ~dir re = let eval_glob t ~dir re =
let targets = targets_of t ~dir |> Pset.to_list |> List.map ~f:Path.basename in let targets = targets_of t ~dir |> Path.Set.to_list |> List.map ~f:Path.basename in
let files = let files =
match File_tree.find_dir t.file_tree dir with match File_tree.find_dir t.file_tree dir with
| None -> targets | None -> targets
@ -1556,8 +1554,8 @@ module Alias = struct
| None -> | None ->
let x = let x =
{ Dir_status. { Dir_status.
deps = Pset.empty deps = Path.Set.empty
; dyn_deps = Build.return Pset.empty ; dyn_deps = Build.return Path.Set.empty
; actions = [] ; actions = []
} }
in in
@ -1567,14 +1565,14 @@ module Alias = struct
let add_deps build_system t ?dyn_deps deps = let add_deps build_system t ?dyn_deps deps =
let def = get_alias_def build_system t in let def = get_alias_def build_system t in
def.deps <- Pset.union def.deps deps; def.deps <- Path.Set.union def.deps deps;
match dyn_deps with match dyn_deps with
| None -> () | None -> ()
| Some build -> | Some build ->
let open Build.O in let open Build.O in
def.dyn_deps <- def.dyn_deps <-
Build.fanout def.dyn_deps build >>^ fun (a, b) -> Build.fanout def.dyn_deps build >>^ fun (a, b) ->
Pset.union a b Path.Set.union a b
let add_action build_system t ~context ?(locks=[]) ~stamp action = let add_action build_system t ~context ?(locks=[]) ~stamp action =
let def = get_alias_def build_system t in let def = get_alias_def build_system t in
@ -1586,4 +1584,4 @@ module Alias = struct
end end
let is_target t file = let is_target t file =
Pset.mem (targets_of t ~dir:(Path.parent_exn file)) file Path.Set.mem (targets_of t ~dir:(Path.parent_exn file)) file

View File

@ -2,7 +2,6 @@ open Import
open Jbuild open Jbuild
module A = Action module A = Action
module Pset = Path.Set
module Alias = Build_system.Alias module Alias = Build_system.Alias
module Dir_with_jbuild = struct module Dir_with_jbuild = struct
@ -492,7 +491,7 @@ module Deps = struct
let path = Path.relative ~error_loc:(String_with_vars.loc s) let path = Path.relative ~error_loc:(String_with_vars.loc s)
dir (expand_vars t ~scope ~dir s) in dir (expand_vars t ~scope ~dir s) in
Build.files_recursively_in ~dir:path ~file_tree:t.file_tree Build.files_recursively_in ~dir:path ~file_tree:t.file_tree
>>^ Pset.to_list >>^ Path.Set.to_list
| Package p -> | Package p ->
let pkg = Package.Name.of_string (expand_vars t ~scope ~dir p) in let pkg = Package.Name.of_string (expand_vars t ~scope ~dir p) in
Alias.dep (Alias.package_install ~context:t.context ~pkg) Alias.dep (Alias.package_install ~context:t.context ~pkg)
@ -564,7 +563,7 @@ module Action = struct
; (* All "name" for ${lib:name:...}/${lib-available:name} forms *) ; (* All "name" for ${lib:name:...}/${lib-available:name} forms *)
mutable lib_deps : Build.lib_deps mutable lib_deps : Build.lib_deps
; (* Static deps from ${...} variables. For instance ${exe:...} *) ; (* Static deps from ${...} variables. For instance ${exe:...} *)
mutable sdeps : Pset.t mutable sdeps : Path.Set.t
; (* Dynamic deps from ${...} variables. For instance ${read:...} *) ; (* Dynamic deps from ${...} variables. For instance ${read:...} *)
mutable ddeps : (unit, Action.Var_expansion.t) Build.t String.Map.t mutable ddeps : (unit, Action.Var_expansion.t) Build.t String.Map.t
} }
@ -604,7 +603,7 @@ module Action = struct
let acc = let acc =
{ failures = [] { failures = []
; lib_deps = String.Map.empty ; lib_deps = String.Map.empty
; sdeps = Pset.empty ; sdeps = Path.Set.empty
; ddeps = String.Map.empty ; ddeps = String.Map.empty
} }
in in
@ -722,7 +721,7 @@ module Action = struct
let exp = expand loc key var x in let exp = expand loc key var x in
(match exp with (match exp with
| Some (Paths (ps, _)) -> | Some (Paths (ps, _)) ->
acc.sdeps <- Pset.union (Pset.of_list ps) acc.sdeps acc.sdeps <- Path.Set.union (Path.Set.of_list ps) acc.sdeps
| _ -> ()); | _ -> ());
exp) exp)
in in
@ -768,7 +767,7 @@ module Action = struct
match targets_written_by_user with match targets_written_by_user with
| Infer -> Action.Infer.partial t ~all_targets:true | Infer -> Action.Infer.partial t ~all_targets:true
| Static targets_written_by_user -> | Static targets_written_by_user ->
let targets_written_by_user = Pset.of_list targets_written_by_user in let targets_written_by_user = Path.Set.of_list targets_written_by_user in
let { Action.Infer.Outcome. deps; targets } = let { Action.Infer.Outcome. deps; targets } =
Action.Infer.partial t ~all_targets:false Action.Infer.partial t ~all_targets:false
in in
@ -780,23 +779,23 @@ module Action = struct
so that it can report better errors. so that it can report better errors.
{[ {[
let missing = Pset.diff targets targets_written_by_user in let missing = Path.Set.diff targets targets_written_by_user in
if not (Pset.is_empty missing) then if not (Path.Set.is_empty missing) then
Loc.warn (Loc.in_file (Utils.jbuild_name_in ~dir)) Loc.warn (Loc.in_file (Utils.jbuild_name_in ~dir))
"Missing targets in user action:\n%s" "Missing targets in user action:\n%s"
(List.map (Pset.elements missing) ~f:(fun target -> (List.map (Path.Set.elements missing) ~f:(fun target ->
sprintf "- %s" (Utils.describe_target target)) sprintf "- %s" (Utils.describe_target target))
|> String.concat ~sep:"\n"); |> String.concat ~sep:"\n");
]} ]}
*) *)
{ deps; targets = Pset.union targets targets_written_by_user } { deps; targets = Path.Set.union targets targets_written_by_user }
| Alias -> | Alias ->
let { Action.Infer.Outcome. deps; targets = _ } = let { Action.Infer.Outcome. deps; targets = _ } =
Action.Infer.partial t ~all_targets:false Action.Infer.partial t ~all_targets:false
in in
{ deps; targets = Pset.empty } { deps; targets = Path.Set.empty }
in in
let targets = Pset.to_list targets in let targets = Path.Set.to_list targets in
List.iter targets ~f:(fun target -> List.iter targets ~f:(fun target ->
if Path.parent_exn target <> dir then if Path.parent_exn target <> dir then
Loc.fail loc Loc.fail loc

View File

@ -184,11 +184,10 @@ module Cached_digest = struct
let db_file = Path.relative Path.build_dir ".digest-db" let db_file = Path.relative Path.build_dir ".digest-db"
let dump () = let dump () =
let module Pmap = Path.Map in
let sexp = let sexp =
Sexp.List ( Sexp.List (
Hashtbl.foldi cache ~init:Pmap.empty ~f:(fun key data acc -> Hashtbl.foldi cache ~init:Path.Map.empty ~f:(fun key data acc ->
Pmap.add acc key data) Path.Map.add acc key data)
|> Path.Map.to_list |> Path.Map.to_list
|> List.map ~f:(fun (path, file) -> |> List.map ~f:(fun (path, file) ->
Sexp.List [ Quoted_string (Path.to_string path) Sexp.List [ Quoted_string (Path.to_string path)