Don't scan the tree a second time for files_recursively_in
This commit is contained in:
parent
a04b0c4dcc
commit
e7b543e7cb
14
src/build.ml
14
src/build.ml
|
@ -109,21 +109,13 @@ let fail ?targets x =
|
||||||
| None -> Fail x
|
| None -> Fail x
|
||||||
| Some l -> Targets l >>> Fail x
|
| Some l -> Targets l >>> Fail x
|
||||||
|
|
||||||
let files_recursively_in ~dir =
|
let files_recursively_in ~dir ~file_tree =
|
||||||
let ctx_dir, src_dir =
|
let prefix_with, dir =
|
||||||
match Path.extract_build_context_dir dir with
|
match Path.extract_build_context_dir dir with
|
||||||
| None -> (Path.root, dir)
|
| None -> (Path.root, dir)
|
||||||
| Some (ctx_dir, src_dir) -> (ctx_dir, src_dir)
|
| Some (ctx_dir, src_dir) -> (ctx_dir, src_dir)
|
||||||
in
|
in
|
||||||
let rec loop dir acc =
|
path_set (File_tree.files_recursively_in file_tree dir ~prefix_with)
|
||||||
List.fold_left (Path.readdir dir) ~init:acc ~f:(fun acc fn ->
|
|
||||||
let path = Path.relative dir fn in
|
|
||||||
if Path.is_directory path then
|
|
||||||
loop path acc
|
|
||||||
else
|
|
||||||
Pset.add (Path.append ctx_dir path) acc)
|
|
||||||
in
|
|
||||||
path_set (loop src_dir Pset.empty)
|
|
||||||
|
|
||||||
let store_vfile spec = Store_vfile spec
|
let store_vfile spec = Store_vfile spec
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ val path : Path.t -> ('a, 'a) t
|
||||||
val paths : Path.t list -> ('a, 'a) t
|
val paths : Path.t list -> ('a, 'a) t
|
||||||
val path_set : Path.Set.t -> ('a, 'a) t
|
val path_set : Path.Set.t -> ('a, 'a) t
|
||||||
val paths_glob : dir:Path.t -> Re.re -> ('a, 'a) t
|
val paths_glob : dir:Path.t -> Re.re -> ('a, 'a) t
|
||||||
val files_recursively_in : dir:Path.t -> ('a, 'a) t
|
val files_recursively_in : dir:Path.t -> file_tree:File_tree.t -> ('a, 'a) t
|
||||||
val vpath : 'a Vspec.t -> (unit, 'a) t
|
val vpath : 'a Vspec.t -> (unit, 'a) t
|
||||||
|
|
||||||
val dyn_paths : ('a, Path.t list) t -> ('a, 'a) t
|
val dyn_paths : ('a, Path.t list) t -> ('a, 'a) t
|
||||||
|
|
|
@ -74,3 +74,12 @@ let file_exists t path fn =
|
||||||
let exists t path =
|
let exists t path =
|
||||||
Path.Map.mem path t.dirs ||
|
Path.Map.mem path t.dirs ||
|
||||||
file_exists t (Path.parent path) (Path.basename path)
|
file_exists t (Path.parent path) (Path.basename path)
|
||||||
|
|
||||||
|
let files_recursively_in t ?(prefix_with=Path.root) path =
|
||||||
|
match find_dir t path with
|
||||||
|
| None -> Path.Set.empty
|
||||||
|
| Some dir ->
|
||||||
|
Dir.fold dir ~init:Path.Set.empty ~f:(fun dir acc ->
|
||||||
|
let path = Path.append prefix_with (Dir.path dir) in
|
||||||
|
String_set.fold (Dir.files dir) ~init:acc ~f:(fun fn acc ->
|
||||||
|
Path.Set.add (Path.relative path fn) acc))
|
||||||
|
|
|
@ -21,3 +21,5 @@ val find_dir : t -> Path.t -> Dir.t option
|
||||||
|
|
||||||
val exists : t -> Path.t -> bool
|
val exists : t -> Path.t -> bool
|
||||||
val file_exists : t -> Path.t -> string -> bool
|
val file_exists : t -> Path.t -> string -> bool
|
||||||
|
|
||||||
|
val files_recursively_in : t -> ?prefix_with:Path.t -> Path.t -> Path.Set.t
|
||||||
|
|
|
@ -425,7 +425,7 @@ module Gen(P : Params) = struct
|
||||||
end
|
end
|
||||||
| Files_recursively_in s ->
|
| Files_recursively_in s ->
|
||||||
let path = Path.relative dir (expand_vars ~dir s) in
|
let path = Path.relative dir (expand_vars ~dir s) in
|
||||||
Build.files_recursively_in ~dir:path
|
Build.files_recursively_in ~dir:path ~file_tree:P.file_tree
|
||||||
|
|
||||||
let dep_of_list ~dir ts =
|
let dep_of_list ~dir ts =
|
||||||
let rec loop acc = function
|
let rec loop acc = function
|
||||||
|
|
Loading…
Reference in New Issue