Skip to content

Commit 35eaf8f

Browse files
committed
output cleaner to notify the build engine to do the clean work
1 parent cd5fa52 commit 35eaf8f

File tree

2 files changed

+9
-74
lines changed

2 files changed

+9
-74
lines changed

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

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)