@@ -424,60 +424,44 @@ let copy_lock_dir ~target ~lock_dir ~deps ~files =
424424 ~dirs: (Path.Build.Set. singleton target))
425425;;
426426
427- let files dir =
428- let rec recurse dir =
429- match Path.Untracked. readdir_unsorted_with_kinds dir with
430- | Ok entries ->
431- entries
432- |> List. fold_left
433- ~init: (Path.Set. empty, Path.Set. empty)
434- ~f: (fun (files , empty_directories ) (entry , kind ) ->
435- let path = Path. relative dir entry in
436- match (kind : Unix.file_kind ) with
437- | S_REG ->
438- let files = Path.Set. add files path in
439- files, empty_directories
440- | S_DIR ->
441- let files', empty_directories' = recurse path in
442- (match Path.Set. is_empty files', Path.Set. is_empty empty_directories' with
443- | true , true ->
444- let empty_directories = Path.Set. add empty_directories path in
445- files, empty_directories
446- | _ , _ ->
447- let files = Path.Set. union files files' in
448- let empty_directories =
449- Path.Set. union empty_directories empty_directories'
450- in
451- files, empty_directories)
452- | otherwise ->
453- Code_error. raise
454- " unsupported kind of file in folder"
455- [ " path" , Path. to_dyn path; " kind" , File_kind. to_dyn otherwise ])
456- | Error (ENOENT, _ , _ ) -> Path.Set. empty, Path.Set. empty
427+ let scan_lock_directory =
428+ let rec scan dir =
429+ let open Memo.O in
430+ Fs_memo. dir_contents (Path. as_outside_build_dir_exn dir)
431+ >> = function
432+ | Error (ENOENT, _ , _ ) -> Memo. return Path.Set. empty
457433 | Error unix_error ->
458434 User_error. raise
459- [ Pp. textf
460- " Failed to read lock dir files of %s:"
461- (Path. to_string_maybe_quoted dir)
462- ; Pp. text (Unix_error.Detailed. to_string_hum unix_error)
435+ [ Pp. textf " Failed to read directory %s:" (Path. to_string_maybe_quoted dir)
436+ ; Unix_error.Detailed. pp unix_error
463437 ]
438+ | Ok entries ->
439+ Fs_cache.Dir_contents. to_list entries
440+ |> Memo. parallel_map ~f: (fun (entry , kind ) ->
441+ let path = Path. relative dir entry in
442+ match (kind : File_kind.t ) with
443+ | S_REG -> Memo. return (Path.Set. singleton path)
444+ | S_DIR -> scan path
445+ | kind ->
446+ User_error. raise
447+ [ Pp. textf
448+ " Lock directory contains file %S with unsupported kind %S"
449+ (Path. to_string_maybe_quoted path)
450+ (File_kind. to_string kind)
451+ ])
452+ >> | Path.Set. union_all
464453 in
465- let files, empty_directories = recurse dir in
466- Dep.Set. of_source_files ~files ~empty_directories , files
454+ fun lock_dir_path ->
455+ let + files = scan lock_dir_path in
456+ Dep.Set. of_source_files ~files ~empty_directories: Path.Set. empty, files
467457;;
468458
469- let setup_copy_rules ~dir :target ~assume_src_exists ~lock_dir =
470- let + () = Memo. return () in
471- let deps, files = files lock_dir in
459+ let setup_copy_rules ~dir :target ~lock_dir =
460+ let + deps, files = scan_lock_directory lock_dir in
472461 let directory_targets, rules =
473462 match Path.Set. is_empty files with
474463 | true -> Path.Build.Map. empty, Rules. empty
475464 | false ->
476- let deps =
477- match assume_src_exists with
478- | false -> deps
479- | true -> Dep.Set. empty
480- in
481465 let directory_targets = Path.Build.Map. singleton target Loc. none in
482466 let { Action_builder.With_targets. build; targets } =
483467 copy_lock_dir ~target ~lock_dir ~deps ~files
@@ -499,7 +483,7 @@ let setup_lock_rules_with_source (workspace : Workspace.t) ~dir ~lock_dir =
499483 match source with
500484 | `Source_tree lock_dir ->
501485 let dir = Path.Build. append_source dir lock_dir in
502- setup_copy_rules ~assume_src_exists: false ~ dir ~lock_dir: (Path. source lock_dir)
486+ setup_copy_rules ~dir ~lock_dir: (Path. source lock_dir)
503487 | `Generated -> Memo. return (setup_lock_rules ~dir ~lock_dir )
504488;;
505489
@@ -508,9 +492,7 @@ let setup_dev_tool_lock_rules ~dir dev_tool =
508492 let dev_tool_name = Dune_lang.Package_name. to_string package_name in
509493 let dir = Path.Build. relative dir dev_tool_name in
510494 let lock_dir = dev_tool |> Lock_dir. dev_tool_external_lock_dir |> Path. external_ in
511- (* dev tool lock files are created in _build outside of the build system
512- so we have to tell the build system not to try to create them *)
513- setup_copy_rules ~dir ~assume_src_exists: true ~lock_dir
495+ setup_copy_rules ~dir ~lock_dir
514496;;
515497
516498let setup_rules ~components ~dir =
0 commit comments