@@ -130,13 +130,11 @@ let group_by_targets db =
130130 ~f: (List. sort ~compare: (fun (x , _ ) (y , _ ) -> Path.Build. compare x y))
131131;;
132132
133- let do_promote db files_to_promote =
134- let by_targets = group_by_targets db in
135- let promote_one dst srcs =
136- match srcs with
137- | [] -> assert false
138- | (src , staging ) :: others ->
139- (* We used to remove promoted files from the digest cache, to force Dune
133+ let promote_one dst srcs =
134+ match srcs with
135+ | [] -> assert false
136+ | (src , staging ) :: others ->
137+ (* We used to remove promoted files from the digest cache, to force Dune
140138 to redigest them on the next run. We did this because on OSX [mtime] is
141139 not precise enough and if a file is modified and promoted quickly, it
142140 looked like it hadn't changed even though it might have.
@@ -149,38 +147,48 @@ let do_promote db files_to_promote =
149147 not promote into the build directory anyway), and source digests should
150148 be correctly invalidated via [fs_memo]. If that doesn't happen, we
151149 should fix [fs_memo] instead of manually resetting the caches here. *)
152- File. promote { src; staging; dst };
153- List. iter others ~f: (fun (path , _staging ) ->
154- Console. print
155- [ Pp. textf " -> ignored %s." (Path. to_string_maybe_quoted (Path. build path))
156- ; Pp. space
157- ])
150+ File. promote { src; staging; dst };
151+ List. iter others ~f: (fun (path , _staging ) ->
152+ Console. print
153+ [ Pp. textf " -> ignored %s." (Path. to_string_maybe_quoted (Path. build path))
154+ ; Pp. space
155+ ])
156+ ;;
157+
158+ let do_promote_all db = group_by_targets db |> Path.Source.Map. iteri ~f: promote_one
159+
160+ let do_promote_these db files =
161+ let by_targets = group_by_targets db in
162+ let by_targets, missing =
163+ let files = Path.Source.Set. of_list files in
164+ Path.Source.Set. fold files ~init: (by_targets, [] ) ~f: (fun fn (map , missing ) ->
165+ match Path.Source.Map. find map fn with
166+ | None -> map, fn :: missing
167+ | Some srcs ->
168+ promote_one fn srcs;
169+ Path.Source.Map. remove map fn, missing)
158170 in
159- match files_to_promote with
171+ let remaining =
172+ Path.Source.Map. to_list by_targets
173+ |> List. concat_map ~f: (fun (dst , srcs ) ->
174+ List. map srcs ~f: (fun (src , staging ) -> { File. src; staging; dst }))
175+ in
176+ let sorted_missing = List. rev missing in
177+ remaining, sorted_missing
178+ ;;
179+
180+ let do_promote db = function
160181 | Dune_rpc_private.Files_to_promote. All ->
161- Path.Source.Map. iteri by_targets ~f: promote_one ;
182+ do_promote_all db ;
162183 [] , []
163- | These files ->
164- let by_targets, missing =
165- let files = Path.Source.Set. of_list files in
166- Path.Source.Set. fold files ~init: (by_targets, [] ) ~f: (fun fn (map , missing ) ->
167- match Path.Source.Map. find map fn with
168- | None -> map, fn :: missing
169- | Some srcs ->
170- promote_one fn srcs;
171- Path.Source.Map. remove map fn, missing)
172- in
173- ( Path.Source.Map. to_list by_targets
174- |> List. concat_map ~f: (fun (dst , srcs ) ->
175- List. map srcs ~f: (fun (src , staging ) -> { File. src; staging; dst }))
176- , missing )
184+ | These files -> do_promote_these db files
177185;;
178186
179187let finalize () =
180188 let db =
181189 match ! Dune_engine.Clflags. promote with
182190 | Some Automatically ->
183- let _is_necessarily_empty = do_promote ! File. db All in
191+ do_promote_all ! File. db;
184192 []
185193 | Some Never | None -> ! File. db
186194 in
@@ -206,7 +214,7 @@ let diff_for_file (file : File.t) =
206214(* * [partition_db files_to_promote db] splits [files_to_promote] into two lists
207215 - The files present in [db] as actual [File.t]s.
208216 - The files absent from [db] as [Path]s. *)
209- let partition_db files_to_promote db =
217+ let partition_db db files_to_promote =
210218 match files_to_promote with
211219 | Dune_rpc_private.Files_to_promote. All -> db, []
212220 | These paths ->
@@ -217,9 +225,9 @@ let partition_db files_to_promote db =
217225 | None -> Right path)
218226;;
219227
220- let sort_for_display files_to_promote =
228+ let sort_for_display db files_to_promote =
221229 let open Fiber.O in
222- let files, missing = load_db () |> partition_db files_to_promote in
230+ let files, missing = partition_db db files_to_promote in
223231 let + diff_opts =
224232 Fiber. parallel_map files ~f: (fun file ->
225233 let + diff_opt = diff_for_file file in
@@ -236,17 +244,21 @@ let sort_for_display files_to_promote =
236244 sorted_diffs, sorted_missing
237245;;
238246
239- let display_diffs ~on_missing files_to_promote =
247+ let missing ~db files_to_promote =
248+ let open Fiber.O in
249+ let + _diffs, missing = sort_for_display db files_to_promote in
250+ missing
251+ ;;
252+
253+ let display_diffs ~db files_to_promote =
240254 let open Fiber.O in
241- let + diffs, missing = sort_for_display files_to_promote in
242- List. iter missing ~f: on_missing;
255+ let + diffs, _missing = sort_for_display db files_to_promote in
243256 List. iter diffs ~f: (fun (_file , diff ) -> Print_diff.Diff. print diff)
244257;;
245258
246- let display_files ~on_missing files_to_promote =
259+ let display_files ~db files_to_promote =
247260 let open Fiber.O in
248- let + diffs, missing = sort_for_display files_to_promote in
249- List. iter missing ~f: on_missing;
261+ let + diffs, _missing = sort_for_display db files_to_promote in
250262 List. iter diffs ~f: (fun (file , _diff ) ->
251263 Console. printf " %s" (File. source file |> Path.Source. to_string))
252264;;
0 commit comments