Skip to content

Commit 6c0d846

Browse files
authored
Merge pull request #4840 from rescript-lang/cmt_clean
staled output clean in a single place
2 parents 0784d69 + d67b81a commit 6c0d846

File tree

5 files changed

+13
-149
lines changed

5 files changed

+13
-149
lines changed

darwin/ninja.exe

48 Bytes
Binary file not shown.

jscomp/bsb/bsb_ninja_gen.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ let output_ninja_and_namespace_map
245245
(Ext_list.map_append bs_dependencies
246246
(Ext_list.map bs_dev_dependencies finger_file) finger_file))
247247
oc ;
248+
(match gentype_config with
249+
| None -> ()
250+
| Some x -> output_string oc ("cleaner = " ^ x.path ^ "\n"));
248251
output_static_resources static_resources rules.copy_resources oc ;
249252
(** Generate build statement for each file *)
250253
Ext_list.iter bs_file_groups

jscomp/bsb/bsb_parse_sources.ml

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -174,83 +174,12 @@ let extract_predicate (m : json_map) : string -> bool =
174174
assume [not toplevel && not (Bsb_dir_index.is_lib_dir dir_index)]
175175
is already checked, so we don't need check it again
176176
*)
177-
let try_unlink s =
178-
try Unix.unlink s
179-
with _ ->
180-
Bsb_log.info "@{<info>Failed to remove %s}@." s
181-
182-
let bs_cmt_post_process_cmd =
183-
lazy (try Sys.getenv "BS_CMT_POST_PROCESS_CMD" with _ -> "")
184-
185-
type suffix_kind =
186-
| Cmi of int | Cmt of int | Cmj of int | Cmti of int
187-
| Not_any
188-
189-
let classify_suffix (x : string) : suffix_kind =
190-
let i =
191-
Ext_string.ends_with_index x Literals.suffix_cmi in
192-
if i >=0 then Cmi i
193-
else
194-
let i =
195-
Ext_string.ends_with_index x Literals.suffix_cmj in
196-
if i >= 0 then Cmj i
197-
else
198-
let i =
199-
Ext_string.ends_with_index x Literals.suffix_cmt in
200-
if i >= 0 then Cmt i
201-
else
202-
let i =
203-
Ext_string.ends_with_index x Literals.suffix_cmti in
204-
if i >= 0 then Cmti i
205-
else Not_any
177+
178+
206179

207180
(** This is the only place where we do some removal during scanning,
208181
configurabl
209182
*)
210-
let prune_staled_bs_js_files
211-
(context : cxt)
212-
(cur_sources : _ Map_string.t )
213-
: unit =
214-
(* Doesn't need to use Bsb_global_backend.lib_artifacts_dir because this is only for JS. *)
215-
let lib_parent =
216-
Filename.concat (Filename.concat context.root Bsb_config.lib_bs)
217-
context.cwd in
218-
if Sys.file_exists lib_parent then
219-
(* walk through dangling *.cm[t,i,j] files *)
220-
let artifacts = Sys.readdir lib_parent in
221-
Ext_array.iter artifacts (fun x ->
222-
let kind = classify_suffix x in
223-
match kind with
224-
| Not_any -> ()
225-
| Cmi i | Cmt i | Cmj i | Cmti i ->
226-
let j =
227-
if context.namespace = None then i
228-
else
229-
Ext_string.rindex_neg x '-'
230-
in
231-
if j >= 0 then
232-
let cmp = Ext_string.capitalize_sub x j in
233-
if not (Map_string.mem cur_sources cmp) then
234-
begin (* prune action *)
235-
let filepath = Filename.concat lib_parent x in
236-
(match kind with
237-
| Cmt _ ->
238-
let lazy cmd = bs_cmt_post_process_cmd in
239-
240-
if cmd <> "" then
241-
(try ignore (
242-
Sys.command (
243-
cmd ^
244-
" -cmt-rm " ^ filepath)
245-
: int ) with _ -> ())
246-
| _ -> ());
247-
try_unlink filepath
248-
end
249-
else () (* assert false *)
250-
)
251-
252-
253-
254183

255184

256185
(********************************************************************)
@@ -331,7 +260,7 @@ let rec
331260
| Some s, _ -> parse_sources cxt s
332261
in
333262
(** Do some clean up *)
334-
prune_staled_bs_js_files cxt sources ;
263+
(* prune_staled_bs_js_files cxt sources ; *)
335264
Bsb_file_groups.cons
336265
~file_group:{ dir ;
337266
sources = sources;

lib/4.06.1/bsb.ml

Lines changed: 6 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10701,83 +10701,12 @@ let extract_predicate (m : json_map) : string -> bool =
1070110701
assume [not toplevel && not (Bsb_dir_index.is_lib_dir dir_index)]
1070210702
is already checked, so we don't need check it again
1070310703
*)
10704-
let try_unlink s =
10705-
try Unix.unlink s
10706-
with _ ->
10707-
Bsb_log.info "@{<info>Failed to remove %s}@." s
10708-
10709-
let bs_cmt_post_process_cmd =
10710-
lazy (try Sys.getenv "BS_CMT_POST_PROCESS_CMD" with _ -> "")
10711-
10712-
type suffix_kind =
10713-
| Cmi of int | Cmt of int | Cmj of int | Cmti of int
10714-
| Not_any
10715-
10716-
let classify_suffix (x : string) : suffix_kind =
10717-
let i =
10718-
Ext_string.ends_with_index x Literals.suffix_cmi in
10719-
if i >=0 then Cmi i
10720-
else
10721-
let i =
10722-
Ext_string.ends_with_index x Literals.suffix_cmj in
10723-
if i >= 0 then Cmj i
10724-
else
10725-
let i =
10726-
Ext_string.ends_with_index x Literals.suffix_cmt in
10727-
if i >= 0 then Cmt i
10728-
else
10729-
let i =
10730-
Ext_string.ends_with_index x Literals.suffix_cmti in
10731-
if i >= 0 then Cmti i
10732-
else Not_any
10704+
10705+
1073310706

1073410707
(** This is the only place where we do some removal during scanning,
1073510708
configurabl
1073610709
*)
10737-
let prune_staled_bs_js_files
10738-
(context : cxt)
10739-
(cur_sources : _ Map_string.t )
10740-
: unit =
10741-
(* Doesn't need to use Bsb_global_backend.lib_artifacts_dir because this is only for JS. *)
10742-
let lib_parent =
10743-
Filename.concat (Filename.concat context.root Bsb_config.lib_bs)
10744-
context.cwd in
10745-
if Sys.file_exists lib_parent then
10746-
(* walk through dangling *.cm[t,i,j] files *)
10747-
let artifacts = Sys.readdir lib_parent in
10748-
Ext_array.iter artifacts (fun x ->
10749-
let kind = classify_suffix x in
10750-
match kind with
10751-
| Not_any -> ()
10752-
| Cmi i | Cmt i | Cmj i | Cmti i ->
10753-
let j =
10754-
if context.namespace = None then i
10755-
else
10756-
Ext_string.rindex_neg x '-'
10757-
in
10758-
if j >= 0 then
10759-
let cmp = Ext_string.capitalize_sub x j in
10760-
if not (Map_string.mem cur_sources cmp) then
10761-
begin (* prune action *)
10762-
let filepath = Filename.concat lib_parent x in
10763-
(match kind with
10764-
| Cmt _ ->
10765-
let lazy cmd = bs_cmt_post_process_cmd in
10766-
10767-
if cmd <> "" then
10768-
(try ignore (
10769-
Sys.command (
10770-
cmd ^
10771-
" -cmt-rm " ^ filepath)
10772-
: int ) with _ -> ())
10773-
| _ -> ());
10774-
try_unlink filepath
10775-
end
10776-
else () (* assert false *)
10777-
)
10778-
10779-
10780-
1078110710

1078210711

1078310712
(********************************************************************)
@@ -10858,7 +10787,7 @@ let rec
1085810787
| Some s, _ -> parse_sources cxt s
1085910788
in
1086010789
(** Do some clean up *)
10861-
prune_staled_bs_js_files cxt sources ;
10790+
(* prune_staled_bs_js_files cxt sources ; *)
1086210791
Bsb_file_groups.cons
1086310792
~file_group:{ dir ;
1086410793
sources = sources;
@@ -13819,6 +13748,9 @@ let output_ninja_and_namespace_map
1381913748
(Ext_list.map_append bs_dependencies
1382013749
(Ext_list.map bs_dev_dependencies finger_file) finger_file))
1382113750
oc ;
13751+
(match gentype_config with
13752+
| None -> ()
13753+
| Some x -> output_string oc ("cleaner = " ^ x.path ^ "\n"));
1382213754
output_static_resources static_resources rules.copy_resources oc ;
1382313755
(** Generate build statement for each file *)
1382413756
Ext_list.iter bs_file_groups

0 commit comments

Comments
 (0)