Skip to content

part 2, significantly shrinking ninja file size #4745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
[submodule "ninja"]
path = ninja
url = [email protected]:rescript-lang/ninja.git
ignore = untracked
Binary file modified darwin/ninja.exe
Binary file not shown.
30 changes: 6 additions & 24 deletions jscomp/bsb/bsb_ninja_file_groups.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,7 @@ let handle_generators oc
)


let make_common_shadows
package_specs
dirname
: Bsb_ninja_targets.shadow list
=

[{ key = Bsb_ninja_global_vars.g_pkg_flg;
op =
Append
(Bsb_package_specs.package_flag_of_package_specs
package_specs dirname
)
}]



type suffixes = {
impl : string;
Expand Down Expand Up @@ -117,10 +104,6 @@ let emit_module_build
let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in
let output_js =
Bsb_package_specs.get_list_of_output_js package_specs output_filename_sans_extension in
let common_shadows =
make_common_shadows package_specs
(Filename.dirname output_cmi)
in

Bsb_ninja_targets.output_build oc
~outputs:[output_mlast]
Expand All @@ -143,20 +126,19 @@ let emit_module_build
;
Bsb_ninja_targets.output_build oc
~outputs:[output_cmi]
~shadows:common_shadows
~order_only_deps:[output_d]
~inputs:[output_mliast]
~rule:(if is_dev then rules.mi_dev else rules.mi)
;
end;

let shadows =
let shadows : Bsb_ninja_targets.shadow list =
match js_post_build_cmd with
| None -> common_shadows
| None -> []
| Some cmd ->
{key = Bsb_ninja_global_vars.postbuild;
op = Overwrite ("&& " ^ cmd ^ Ext_string.single_space ^ String.concat Ext_string.single_space output_js)}
:: common_shadows
[{key = Bsb_ninja_global_vars.postbuild;
op = Overwrite ("&& " ^ cmd ^ Ext_string.single_space ^ String.concat Ext_string.single_space output_js)}]

in
let rule =
if has_intf_file then
Expand Down
1 change: 1 addition & 0 deletions jscomp/bsb/bsb_ninja_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ let output_ninja_and_namespace_map
~has_pp:(pp_file <> None)
~has_builtin:(built_in_dependency <> None)
~reason_react_jsx
~package_specs
~digest
generators in
emit_bsc_lib_includes bs_dependencies source_dirs.lib external_includes namespace oc;
Expand Down
10 changes: 6 additions & 4 deletions jscomp/bsb/bsb_ninja_rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ let make_custom_rules
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
~(digest : string)
~(refmt : string option) (* set refmt path when needed *)
~(package_specs: Bsb_package_specs.t)
(custom_rules : command Map_string.t) :
builtin =
(** FIXME: We don't need set [-o ${out}] when building ast
Expand All @@ -133,6 +134,7 @@ let make_custom_rules
Ext_buffer.clear buf;
Ext_buffer.add_string buf "$bsc";
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.g_pkg_flg;
Ext_buffer.add_string buf (Bsb_package_specs.package_flag_of_package_specs package_specs "$in_d");
if read_cmi = `yes then
Ext_buffer.add_string buf " -bs-read-cmi";
if is_dev then
Expand Down Expand Up @@ -176,11 +178,11 @@ let make_custom_rules
let build_ast =
define
~command:(mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx:false )
"build_ast" in
"ast" in
let build_ast_from_re =
define
~command:(mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx:true)
"build_ast_from_re" in
"astj" in

let copy_resources =
define
Expand All @@ -195,13 +197,13 @@ let make_custom_rules
~restat:()
~command:
("$bsdep -hash " ^ digest ^" $g_ns $in")
"mk_deps" in
"deps" in
let build_bin_deps_dev =
define
~restat:()
~command:
("$bsdep -g -hash " ^ digest ^" $g_ns $in")
"mk_deps_dev" in
"deps_dev" in
let aux ~name ~read_cmi ~postbuild =
define
~command:(mk_ml_cmj_cmd
Expand Down
1 change: 1 addition & 0 deletions jscomp/bsb/bsb_ninja_rule.mli
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ val make_custom_rules :
reason_react_jsx : Bsb_config_types.reason_react_jsx option ->
digest:string ->
refmt:string option ->
package_specs:Bsb_package_specs.t ->
command Map_string.t ->
builtin

4 changes: 2 additions & 2 deletions jscomp/bsb/bsb_ninja_targets.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let output_build
~rule
oc =
let rule = Bsb_ninja_rule.get_name rule oc in (* Trigger building if not used *)
output_string oc "build ";
output_string oc "o ";
Ext_list.iter outputs (fun s -> output_string oc Ext_string.single_space ; output_string oc s );
if implicit_outputs <> [] then begin
output_string oc " | ";
Expand Down Expand Up @@ -126,7 +126,7 @@ let output_build


let phony ?(order_only_deps=[]) ~inputs ~output oc =
output_string oc "build ";
output_string oc "o ";
output_string oc output ;
output_string oc " : ";
output_string oc "phony";
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_packages_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
Bsc_args.bad_arg ("invalid module system " ^ module_system)
in
let m =
match Ext_string.split ~keep_empty:false s ':' with
match Ext_string.split ~keep_empty:true s ':' with
| [path] ->
{module_system = NodeJS; path; suffix = Js}
| [ module_system; path] ->
Expand Down
46 changes: 16 additions & 30 deletions lib/4.06.1/bsb.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13048,6 +13048,7 @@ val make_custom_rules :
reason_react_jsx : Bsb_config_types.reason_react_jsx option ->
digest:string ->
refmt:string option ->
package_specs:Bsb_package_specs.t ->
command Map_string.t ->
builtin

Expand Down Expand Up @@ -13177,6 +13178,7 @@ let make_custom_rules
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
~(digest : string)
~(refmt : string option) (* set refmt path when needed *)
~(package_specs: Bsb_package_specs.t)
(custom_rules : command Map_string.t) :
builtin =
(** FIXME: We don't need set [-o ${out}] when building ast
Expand All @@ -13189,6 +13191,7 @@ let make_custom_rules
Ext_buffer.clear buf;
Ext_buffer.add_string buf "$bsc";
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.g_pkg_flg;
Ext_buffer.add_string buf (Bsb_package_specs.package_flag_of_package_specs package_specs "$in_d");
if read_cmi = `yes then
Ext_buffer.add_string buf " -bs-read-cmi";
if is_dev then
Expand Down Expand Up @@ -13232,11 +13235,11 @@ let make_custom_rules
let build_ast =
define
~command:(mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx:false )
"build_ast" in
"ast" in
let build_ast_from_re =
define
~command:(mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx:true)
"build_ast_from_re" in
"astj" in

let copy_resources =
define
Expand All @@ -13251,13 +13254,13 @@ let make_custom_rules
~restat:()
~command:
("$bsdep -hash " ^ digest ^" $g_ns $in")
"mk_deps" in
"deps" in
let build_bin_deps_dev =
define
~restat:()
~command:
("$bsdep -g -hash " ^ digest ^" $g_ns $in")
"mk_deps_dev" in
"deps_dev" in
let aux ~name ~read_cmi ~postbuild =
define
~command:(mk_ml_cmj_cmd
Expand Down Expand Up @@ -13448,7 +13451,7 @@ let output_build
~rule
oc =
let rule = Bsb_ninja_rule.get_name rule oc in (* Trigger building if not used *)
output_string oc "build ";
output_string oc "o ";
Ext_list.iter outputs (fun s -> output_string oc Ext_string.single_space ; output_string oc s );
if implicit_outputs <> [] then begin
output_string oc " | ";
Expand Down Expand Up @@ -13517,7 +13520,7 @@ let output_build


let phony ?(order_only_deps=[]) ~inputs ~output oc =
output_string oc "build ";
output_string oc "o ";
output_string oc output ;
output_string oc " : ";
output_string oc "phony";
Expand Down Expand Up @@ -13694,20 +13697,7 @@ let handle_generators oc
)


let make_common_shadows
package_specs
dirname
: Bsb_ninja_targets.shadow list
=

[{ key = Bsb_ninja_global_vars.g_pkg_flg;
op =
Append
(Bsb_package_specs.package_flag_of_package_specs
package_specs dirname
)
}]



type suffixes = {
impl : string;
Expand Down Expand Up @@ -13765,10 +13755,6 @@ let emit_module_build
let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in
let output_js =
Bsb_package_specs.get_list_of_output_js package_specs output_filename_sans_extension in
let common_shadows =
make_common_shadows package_specs
(Filename.dirname output_cmi)
in

Bsb_ninja_targets.output_build oc
~outputs:[output_mlast]
Expand All @@ -13791,20 +13777,19 @@ let emit_module_build
;
Bsb_ninja_targets.output_build oc
~outputs:[output_cmi]
~shadows:common_shadows
~order_only_deps:[output_d]
~inputs:[output_mliast]
~rule:(if is_dev then rules.mi_dev else rules.mi)
;
end;

let shadows =
let shadows : Bsb_ninja_targets.shadow list =
match js_post_build_cmd with
| None -> common_shadows
| None -> []
| Some cmd ->
{key = Bsb_ninja_global_vars.postbuild;
op = Overwrite ("&& " ^ cmd ^ Ext_string.single_space ^ String.concat Ext_string.single_space output_js)}
:: common_shadows
[{key = Bsb_ninja_global_vars.postbuild;
op = Overwrite ("&& " ^ cmd ^ Ext_string.single_space ^ String.concat Ext_string.single_space output_js)}]

in
let rule =
if has_intf_file then
Expand Down Expand Up @@ -14111,6 +14096,7 @@ let output_ninja_and_namespace_map
~has_pp:(pp_file <> None)
~has_builtin:(built_in_dependency <> None)
~reason_react_jsx
~package_specs
~digest
generators in
emit_bsc_lib_includes bs_dependencies source_dirs.lib external_includes namespace oc;
Expand Down
2 changes: 1 addition & 1 deletion lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92641,7 +92641,7 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
Bsc_args.bad_arg ("invalid module system " ^ module_system)
in
let m =
match Ext_string.split ~keep_empty:false s ':' with
match Ext_string.split ~keep_empty:true s ':' with
| [path] ->
{module_system = NodeJS; path; suffix = Js}
| [ module_system; path] ->
Expand Down
2 changes: 1 addition & 1 deletion lib/4.06.1/unstable/js_refmt_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92641,7 +92641,7 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
Bsc_args.bad_arg ("invalid module system " ^ module_system)
in
let m =
match Ext_string.split ~keep_empty:false s ':' with
match Ext_string.split ~keep_empty:true s ':' with
| [path] ->
{module_system = NodeJS; path; suffix = Js}
| [ module_system; path] ->
Expand Down
2 changes: 1 addition & 1 deletion lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -370176,7 +370176,7 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
Bsc_args.bad_arg ("invalid module system " ^ module_system)
in
let m =
match Ext_string.split ~keep_empty:false s ':' with
match Ext_string.split ~keep_empty:true s ':' with
| [path] ->
{module_system = NodeJS; path; suffix = Js}
| [ module_system; path] ->
Expand Down
Binary file modified linux/ninja.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion ninja
Submodule ninja updated 3 files
+3 −3 src/graph.cc
+171 −160 src/lexer.cc
+1 −0 src/lexer.in.cc