Skip to content

Commit 93970fd

Browse files
WIP dev tool file dir
Signed-off-by: Marek Kubica <[email protected]>
1 parent 4110548 commit 93970fd

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/dune_rules/lock_rules.ml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,60 @@ let copy_lock_dir ~target ~lock_dir ~deps ~files =
1818
let suffix = Path.drop_prefix_exn src ~prefix:(Path.source lock_dir) in
1919
let dst = Path.Build.append_local target suffix in
2020
let parent = Path.Build.parent_exn dst in
21+
Printf.eprintf "%s -> %s\n" (Path.to_string src) (Path.Build.to_string dst);
2122
Action.progn [ Action.mkdir parent; Action.copy src dst ])
2223
|> Action.concurrent
2324
|> Action.Full.make
2425
|> Action_builder.return)
2526
|> action_builder_with_dir_targets ~directory_targets:[ target ]
2627
;;
2728

29+
let files dir =
30+
let rec recurse dir =
31+
match Path.Untracked.readdir_unsorted_with_kinds dir with
32+
| Ok entries ->
33+
entries
34+
|> List.fold_left
35+
~init:(Path.Set.empty, Path.Set.empty)
36+
~f:(fun (files, empty_directories) (entry, kind) ->
37+
let path = Path.relative dir entry in
38+
match (kind : Unix.file_kind) with
39+
| S_REG ->
40+
let files = Path.Set.add files path in
41+
files, empty_directories
42+
| S_DIR ->
43+
let files', empty_directories' = recurse path in
44+
(match Path.Set.is_empty files', Path.Set.is_empty empty_directories' with
45+
| true, true ->
46+
let empty_directories = Path.Set.add empty_directories path in
47+
files, empty_directories
48+
| _, _ ->
49+
let files = Path.Set.union files files' in
50+
let empty_directories =
51+
Path.Set.union empty_directories empty_directories'
52+
in
53+
files, empty_directories)
54+
| _otherwise -> failwith "unsupported content")
55+
| Error (ENOENT, _, _) -> Path.Set.empty, Path.Set.empty
56+
| Error unix_error ->
57+
User_error.raise
58+
[ Pp.text "Failed to read dev-tool lock dir files"
59+
; Pp.text (Unix_error.Detailed.to_string_hum unix_error)
60+
]
61+
in
62+
let files, empty_directories = recurse dir in
63+
Dep.Set.of_source_files ~files ~empty_directories, files
64+
;;
65+
2866
let setup_copy_rules ~dir:target ~lock_dir =
29-
let+ deps, files = Source_deps.files (Path.source lock_dir) in
67+
Printf.eprintf "Setting up copy rules for %s\n" (Path.Source.to_string lock_dir);
68+
let+ () = Memo.return () in
69+
let deps, files = files (Path.source lock_dir) in
3070
let directory_targets, rules =
3171
match Path.Set.is_empty files with
3272
| true -> Path.Build.Map.empty, Rules.empty
3373
| false ->
74+
Printf.eprintf "Files: %s\n" (Dyn.to_string (Path.Set.to_dyn files));
3475
let directory_targets = Path.Build.Map.singleton target Loc.none in
3576
let { Action_builder.With_targets.build; targets } =
3677
copy_lock_dir ~target ~lock_dir ~deps ~files

src/dune_rules/pkg_rules.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,13 +1541,13 @@ end = struct
15411541
Code_error.raise
15421542
"Unexpected files_dir path"
15431543
[ "components", (Dyn.list Dyn.string) otherwise ])
1544-
| In_build_dir b -> (
1545-
match Path.Build.explode b with
1546-
| [".dev-tools.locks"; dev_tool; files_dir] ->
1544+
| In_build_dir b ->
1545+
(match Path.Build.explode b with
1546+
| [ ".dev-tools.locks"; dev_tool; files_dir ] ->
15471547
Path.Build.L.relative
15481548
Private_context.t.build_dir
15491549
[ "default"; ".dev-tool-locks"; dev_tool; files_dir ]
1550-
| _otherwise -> b))
1550+
| _otherwise -> b))
15511551
in
15521552
let id = Pkg.Id.gen () in
15531553
let write_paths =

0 commit comments

Comments
 (0)