Skip to content

Commit 4268d18

Browse files
authored
Merge pull request #4745 from rescript-lang/shrink_ninja_file
part 2, significantly shrinking ninja file size
2 parents 67af904 + be65b41 commit 4268d18

14 files changed

+38
-65
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
[submodule "ninja"]
1010
path = ninja
1111
url = [email protected]:rescript-lang/ninja.git
12+
ignore = untracked

darwin/ninja.exe

144 Bytes
Binary file not shown.

jscomp/bsb/bsb_ninja_file_groups.ml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,7 @@ let handle_generators oc
4646
)
4747

4848

49-
let make_common_shadows
50-
package_specs
51-
dirname
52-
: Bsb_ninja_targets.shadow list
53-
=
54-
55-
[{ key = Bsb_ninja_global_vars.g_pkg_flg;
56-
op =
57-
Append
58-
(Bsb_package_specs.package_flag_of_package_specs
59-
package_specs dirname
60-
)
61-
}]
62-
49+
6350

6451
type suffixes = {
6552
impl : string;
@@ -117,10 +104,6 @@ let emit_module_build
117104
let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in
118105
let output_js =
119106
Bsb_package_specs.get_list_of_output_js package_specs output_filename_sans_extension in
120-
let common_shadows =
121-
make_common_shadows package_specs
122-
(Filename.dirname output_cmi)
123-
in
124107

125108
Bsb_ninja_targets.output_build oc
126109
~outputs:[output_mlast]
@@ -143,20 +126,19 @@ let emit_module_build
143126
;
144127
Bsb_ninja_targets.output_build oc
145128
~outputs:[output_cmi]
146-
~shadows:common_shadows
147129
~order_only_deps:[output_d]
148130
~inputs:[output_mliast]
149131
~rule:(if is_dev then rules.mi_dev else rules.mi)
150132
;
151133
end;
152134

153-
let shadows =
135+
let shadows : Bsb_ninja_targets.shadow list =
154136
match js_post_build_cmd with
155-
| None -> common_shadows
137+
| None -> []
156138
| Some cmd ->
157-
{key = Bsb_ninja_global_vars.postbuild;
158-
op = Overwrite ("&& " ^ cmd ^ Ext_string.single_space ^ String.concat Ext_string.single_space output_js)}
159-
:: common_shadows
139+
[{key = Bsb_ninja_global_vars.postbuild;
140+
op = Overwrite ("&& " ^ cmd ^ Ext_string.single_space ^ String.concat Ext_string.single_space output_js)}]
141+
160142
in
161143
let rule =
162144
if has_intf_file then

jscomp/bsb/bsb_ninja_gen.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ let output_ninja_and_namespace_map
204204
~has_pp:(pp_file <> None)
205205
~has_builtin:(built_in_dependency <> None)
206206
~reason_react_jsx
207+
~package_specs
207208
~digest
208209
generators in
209210
emit_bsc_lib_includes bs_dependencies source_dirs.lib external_includes namespace oc;

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ let make_custom_rules
121121
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
122122
~(digest : string)
123123
~(refmt : string option) (* set refmt path when needed *)
124+
~(package_specs: Bsb_package_specs.t)
124125
(custom_rules : command Map_string.t) :
125126
builtin =
126127
(** FIXME: We don't need set [-o ${out}] when building ast
@@ -133,6 +134,7 @@ let make_custom_rules
133134
Ext_buffer.clear buf;
134135
Ext_buffer.add_string buf "$bsc";
135136
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.g_pkg_flg;
137+
Ext_buffer.add_string buf (Bsb_package_specs.package_flag_of_package_specs package_specs "$in_d");
136138
if read_cmi = `yes then
137139
Ext_buffer.add_string buf " -bs-read-cmi";
138140
if is_dev then
@@ -176,11 +178,11 @@ let make_custom_rules
176178
let build_ast =
177179
define
178180
~command:(mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx:false )
179-
"build_ast" in
181+
"ast" in
180182
let build_ast_from_re =
181183
define
182184
~command:(mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx:true)
183-
"build_ast_from_re" in
185+
"astj" in
184186

185187
let copy_resources =
186188
define
@@ -195,13 +197,13 @@ let make_custom_rules
195197
~restat:()
196198
~command:
197199
("$bsdep -hash " ^ digest ^" $g_ns $in")
198-
"mk_deps" in
200+
"deps" in
199201
let build_bin_deps_dev =
200202
define
201203
~restat:()
202204
~command:
203205
("$bsdep -g -hash " ^ digest ^" $g_ns $in")
204-
"mk_deps_dev" in
206+
"deps_dev" in
205207
let aux ~name ~read_cmi ~postbuild =
206208
define
207209
~command:(mk_ml_cmj_cmd

jscomp/bsb/bsb_ninja_rule.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ val make_custom_rules :
7777
reason_react_jsx : Bsb_config_types.reason_react_jsx option ->
7878
digest:string ->
7979
refmt:string option ->
80+
package_specs:Bsb_package_specs.t ->
8081
command Map_string.t ->
8182
builtin
8283

jscomp/bsb/bsb_ninja_targets.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ let output_build
5757
~rule
5858
oc =
5959
let rule = Bsb_ninja_rule.get_name rule oc in (* Trigger building if not used *)
60-
output_string oc "build ";
60+
output_string oc "o ";
6161
Ext_list.iter outputs (fun s -> output_string oc Ext_string.single_space ; output_string oc s );
6262
if implicit_outputs <> [] then begin
6363
output_string oc " | ";
@@ -126,7 +126,7 @@ let output_build
126126

127127

128128
let phony ?(order_only_deps=[]) ~inputs ~output oc =
129-
output_string oc "build ";
129+
output_string oc "o ";
130130
output_string oc output ;
131131
output_string oc " : ";
132132
output_string oc "phony";

jscomp/core/js_packages_info.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
252252
Bsc_args.bad_arg ("invalid module system " ^ module_system)
253253
in
254254
let m =
255-
match Ext_string.split ~keep_empty:false s ':' with
255+
match Ext_string.split ~keep_empty:true s ':' with
256256
| [path] ->
257257
{module_system = NodeJS; path; suffix = Js}
258258
| [ module_system; path] ->

lib/4.06.1/bsb.ml

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13048,6 +13048,7 @@ val make_custom_rules :
1304813048
reason_react_jsx : Bsb_config_types.reason_react_jsx option ->
1304913049
digest:string ->
1305013050
refmt:string option ->
13051+
package_specs:Bsb_package_specs.t ->
1305113052
command Map_string.t ->
1305213053
builtin
1305313054

@@ -13177,6 +13178,7 @@ let make_custom_rules
1317713178
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
1317813179
~(digest : string)
1317913180
~(refmt : string option) (* set refmt path when needed *)
13181+
~(package_specs: Bsb_package_specs.t)
1318013182
(custom_rules : command Map_string.t) :
1318113183
builtin =
1318213184
(** FIXME: We don't need set [-o ${out}] when building ast
@@ -13189,6 +13191,7 @@ let make_custom_rules
1318913191
Ext_buffer.clear buf;
1319013192
Ext_buffer.add_string buf "$bsc";
1319113193
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.g_pkg_flg;
13194+
Ext_buffer.add_string buf (Bsb_package_specs.package_flag_of_package_specs package_specs "$in_d");
1319213195
if read_cmi = `yes then
1319313196
Ext_buffer.add_string buf " -bs-read-cmi";
1319413197
if is_dev then
@@ -13232,11 +13235,11 @@ let make_custom_rules
1323213235
let build_ast =
1323313236
define
1323413237
~command:(mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx:false )
13235-
"build_ast" in
13238+
"ast" in
1323613239
let build_ast_from_re =
1323713240
define
1323813241
~command:(mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx:true)
13239-
"build_ast_from_re" in
13242+
"astj" in
1324013243

1324113244
let copy_resources =
1324213245
define
@@ -13251,13 +13254,13 @@ let make_custom_rules
1325113254
~restat:()
1325213255
~command:
1325313256
("$bsdep -hash " ^ digest ^" $g_ns $in")
13254-
"mk_deps" in
13257+
"deps" in
1325513258
let build_bin_deps_dev =
1325613259
define
1325713260
~restat:()
1325813261
~command:
1325913262
("$bsdep -g -hash " ^ digest ^" $g_ns $in")
13260-
"mk_deps_dev" in
13263+
"deps_dev" in
1326113264
let aux ~name ~read_cmi ~postbuild =
1326213265
define
1326313266
~command:(mk_ml_cmj_cmd
@@ -13448,7 +13451,7 @@ let output_build
1344813451
~rule
1344913452
oc =
1345013453
let rule = Bsb_ninja_rule.get_name rule oc in (* Trigger building if not used *)
13451-
output_string oc "build ";
13454+
output_string oc "o ";
1345213455
Ext_list.iter outputs (fun s -> output_string oc Ext_string.single_space ; output_string oc s );
1345313456
if implicit_outputs <> [] then begin
1345413457
output_string oc " | ";
@@ -13517,7 +13520,7 @@ let output_build
1351713520

1351813521

1351913522
let phony ?(order_only_deps=[]) ~inputs ~output oc =
13520-
output_string oc "build ";
13523+
output_string oc "o ";
1352113524
output_string oc output ;
1352213525
output_string oc " : ";
1352313526
output_string oc "phony";
@@ -13694,20 +13697,7 @@ let handle_generators oc
1369413697
)
1369513698

1369613699

13697-
let make_common_shadows
13698-
package_specs
13699-
dirname
13700-
: Bsb_ninja_targets.shadow list
13701-
=
13702-
13703-
[{ key = Bsb_ninja_global_vars.g_pkg_flg;
13704-
op =
13705-
Append
13706-
(Bsb_package_specs.package_flag_of_package_specs
13707-
package_specs dirname
13708-
)
13709-
}]
13710-
13700+
1371113701

1371213702
type suffixes = {
1371313703
impl : string;
@@ -13765,10 +13755,6 @@ let emit_module_build
1376513755
let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in
1376613756
let output_js =
1376713757
Bsb_package_specs.get_list_of_output_js package_specs output_filename_sans_extension in
13768-
let common_shadows =
13769-
make_common_shadows package_specs
13770-
(Filename.dirname output_cmi)
13771-
in
1377213758

1377313759
Bsb_ninja_targets.output_build oc
1377413760
~outputs:[output_mlast]
@@ -13791,20 +13777,19 @@ let emit_module_build
1379113777
;
1379213778
Bsb_ninja_targets.output_build oc
1379313779
~outputs:[output_cmi]
13794-
~shadows:common_shadows
1379513780
~order_only_deps:[output_d]
1379613781
~inputs:[output_mliast]
1379713782
~rule:(if is_dev then rules.mi_dev else rules.mi)
1379813783
;
1379913784
end;
1380013785

13801-
let shadows =
13786+
let shadows : Bsb_ninja_targets.shadow list =
1380213787
match js_post_build_cmd with
13803-
| None -> common_shadows
13788+
| None -> []
1380413789
| Some cmd ->
13805-
{key = Bsb_ninja_global_vars.postbuild;
13806-
op = Overwrite ("&& " ^ cmd ^ Ext_string.single_space ^ String.concat Ext_string.single_space output_js)}
13807-
:: common_shadows
13790+
[{key = Bsb_ninja_global_vars.postbuild;
13791+
op = Overwrite ("&& " ^ cmd ^ Ext_string.single_space ^ String.concat Ext_string.single_space output_js)}]
13792+
1380813793
in
1380913794
let rule =
1381013795
if has_intf_file then
@@ -14111,6 +14096,7 @@ let output_ninja_and_namespace_map
1411114096
~has_pp:(pp_file <> None)
1411214097
~has_builtin:(built_in_dependency <> None)
1411314098
~reason_react_jsx
14099+
~package_specs
1411414100
~digest
1411514101
generators in
1411614102
emit_bsc_lib_includes bs_dependencies source_dirs.lib external_includes namespace oc;

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92641,7 +92641,7 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
9264192641
Bsc_args.bad_arg ("invalid module system " ^ module_system)
9264292642
in
9264392643
let m =
92644-
match Ext_string.split ~keep_empty:false s ':' with
92644+
match Ext_string.split ~keep_empty:true s ':' with
9264592645
| [path] ->
9264692646
{module_system = NodeJS; path; suffix = Js}
9264792647
| [ module_system; path] ->

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92641,7 +92641,7 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
9264192641
Bsc_args.bad_arg ("invalid module system " ^ module_system)
9264292642
in
9264392643
let m =
92644-
match Ext_string.split ~keep_empty:false s ':' with
92644+
match Ext_string.split ~keep_empty:true s ':' with
9264592645
| [path] ->
9264692646
{module_system = NodeJS; path; suffix = Js}
9264792647
| [ module_system; path] ->

lib/4.06.1/whole_compiler.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370176,7 +370176,7 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
370176370176
Bsc_args.bad_arg ("invalid module system " ^ module_system)
370177370177
in
370178370178
let m =
370179-
match Ext_string.split ~keep_empty:false s ':' with
370179+
match Ext_string.split ~keep_empty:true s ':' with
370180370180
| [path] ->
370181370181
{module_system = NodeJS; path; suffix = Js}
370182370182
| [ module_system; path] ->

linux/ninja.exe

16 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)