Skip to content

Commit 0904880

Browse files
authored
Merge pull request #4429 from BuckleScript/build_dev
flatten dev groups
2 parents fef665e + f68e5ff commit 0904880

22 files changed

+201
-774
lines changed

jscomp/bsb/bsb_config_parse.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ let interpret_json
440440
| Some sources ->
441441
let cut_generators =
442442
extract_boolean map Bsb_build_schemas.cut_generators false in
443-
let groups, number_of_dev_groups = Bsb_parse_sources.scan
443+
let groups = Bsb_parse_sources.scan
444444
~ignored_dirs:(extract_ignored_dirs map)
445445
~toplevel
446446
~root: per_proj_dir
@@ -484,7 +484,6 @@ let interpret_json
484484
entries;
485485
generators = extract_generators map ;
486486
cut_generators ;
487-
number_of_dev_groups;
488487
}
489488
| None ->
490489
Bsb_exception.invalid_spec

jscomp/bsb/bsb_config_types.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,4 @@ type t =
8181
cut_generators : bool; (* note when used as a dev mode, we will always ignore it *)
8282
bs_suffix : bool ; (* true means [.bs.js] we should pass [-bs-suffix] flag *)
8383
gentype_config : gentype_config option;
84-
number_of_dev_groups : int
8584
}

jscomp/bsb/bsb_file_groups.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type file_group =
4040
sources : Bsb_db.t;
4141
resources : string list ;
4242
public : public ;
43-
dir_index : Bsb_dir_index.t ;
43+
dev_index : bool ;
4444
generators : build_generator list ;
4545
(* output of [generators] should be added to [sources],
4646
if it is [.ml,.mli,.re,.rei]

jscomp/bsb/bsb_file_groups.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type file_group =
4040
sources : Bsb_db.t;
4141
resources : string list ;
4242
public : public ;
43-
dir_index : Bsb_dir_index.t ;
43+
dev_index : bool ; (* false means not in dev mode *)
4444
generators : build_generator list ;
4545
(* output of [generators] should be added to [sources],
4646
if it is [.ml,.mli,.re,.rei]

jscomp/bsb/bsb_ninja_file_groups.ml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,23 @@ let handle_generators oc
4949
let make_common_shadows
5050
package_specs
5151
dirname
52-
dir_index
5352
: Bsb_ninja_targets.shadow list
5453
=
5554

56-
{ key = Bsb_ninja_global_vars.g_pkg_flg;
55+
[{ key = Bsb_ninja_global_vars.g_pkg_flg;
5756
op =
5857
Append
5958
(Bsb_package_specs.package_flag_of_package_specs
6059
package_specs dirname
6160
)
62-
} ::
63-
(if Bsb_dir_index.is_lib_dir dir_index then [] else
64-
[
65-
{ key = Bsb_ninja_global_vars.g_dev_incls;
66-
op = OverwriteVar (Bsb_dir_index.string_of_bsb_dev_include dir_index);
67-
}
68-
]
69-
)
61+
}]
7062

7163

7264

7365
let emit_module_build
7466
(rules : Bsb_ninja_rule.builtin)
7567
(package_specs : Bsb_package_specs.t)
76-
(group_dir_index : Bsb_dir_index.t)
68+
(is_dev : bool)
7769
oc
7870
~bs_suffix
7971
js_post_build_cmd
@@ -83,7 +75,6 @@ let emit_module_build
8375
let has_intf_file = module_info.info = Ml_mli in
8476
let is_re = module_info.is_re in
8577
let filename_sans_extension = module_info.name_sans_extension in
86-
let is_dev = not (Bsb_dir_index.is_lib_dir group_dir_index) in
8778
let input_impl =
8879
Bsb_config.proj_rel
8980
(filename_sans_extension ^ if is_re then Literals.suffix_re else Literals.suffix_ml ) in
@@ -105,7 +96,7 @@ let emit_module_build
10596
let common_shadows =
10697
make_common_shadows package_specs
10798
(Filename.dirname output_cmi)
108-
group_dir_index in
99+
in
109100
let ast_rule =
110101
if is_re then
111102
rules.build_ast_from_re
@@ -123,7 +114,7 @@ let emit_module_build
123114
?shadows:(if is_dev then
124115
Some [{Bsb_ninja_targets.key = Bsb_build_schemas.bsb_dir_group ;
125116
op =
126-
Overwrite (string_of_int (group_dir_index :> int)) }]
117+
Overwrite "-g" }]
127118
else None)
128119
;
129120
if has_intf_file then begin
@@ -203,7 +194,7 @@ let handle_files_per_dir
203194
module_info.name_sans_extension;
204195
emit_module_build rules
205196
package_specs
206-
group.dir_index
197+
group.dev_index
207198
oc
208199
~bs_suffix
209200
js_post_build_cmd

jscomp/bsb/bsb_ninja_gen.ml

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ let output_ninja_and_namespace_map
116116
namespace ;
117117
warning;
118118
gentype_config;
119-
number_of_dev_groups;
119+
120120
} : Bsb_config_types.t) : unit
121121
=
122122
let lib_artifacts_dir = !Bsb_global_backend.lib_artifacts_dir in
@@ -160,48 +160,34 @@ let output_ninja_and_namespace_map
160160
bs_dev_dependencies
161161
(fun x -> x.package_install_path));
162162
Bsb_ninja_global_vars.g_ns , g_ns_flg ;
163-
Bsb_build_schemas.bsb_dir_group, "0" (*TODO: avoid name conflict in the future *)
164163
|] oc
165164
in
166165
let bs_groups, bsc_lib_dirs, static_resources =
167-
if number_of_dev_groups = 0 then
168-
let bs_group, source_dirs,static_resources =
169-
Ext_list.fold_left bs_file_groups (Map_string.empty,[],[])
170-
(fun (acc, dirs,acc_resources) ({sources ; dir; resources } as x)
171-
->
172-
Bsb_db_util.merge acc sources ,
173-
(if Bsb_file_groups.is_empty x then dirs else dir::dirs) ,
174-
( if resources = [] then acc_resources
175-
else Ext_list.map_append resources acc_resources (fun x -> dir // x ) )
176-
) in
177-
Bsb_db_util.sanity_check bs_group;
178-
[|bs_group|], source_dirs, static_resources
179-
else
180-
let bs_groups = Array.init (number_of_dev_groups + 1 ) (fun _ -> Map_string.empty) in
181-
let source_dirs = Array.init (number_of_dev_groups + 1 ) (fun _ -> []) in
166+
(* number_of_dev_groups = 1 -- all devs share the same group *)
167+
let bs_groups = Array.init 2 (fun _ -> Map_string.empty) in
168+
let source_dirs = Array.init 2 (fun _ -> []) in
182169
let static_resources =
183-
Ext_list.fold_left bs_file_groups [] (fun (acc_resources : string list) {sources; dir; resources; dir_index}
170+
Ext_list.fold_left bs_file_groups [] (fun (acc_resources : string list) {sources; dir; resources; dev_index}
184171
->
185-
let dir_index = (dir_index :> int) in
172+
let dir_index = if dev_index then 1 else 0 in
186173
bs_groups.(dir_index) <- Bsb_db_util.merge bs_groups.(dir_index) sources ;
187174
source_dirs.(dir_index) <- dir :: source_dirs.(dir_index);
188175
Ext_list.map_append resources acc_resources (fun x -> dir//x)
189176
) in
190-
let lib = bs_groups.((Bsb_dir_index.lib_dir_index :> int)) in
177+
let lib = bs_groups.(0) in
191178
Bsb_db_util.sanity_check lib;
192-
for i = 1 to number_of_dev_groups do
193-
let c = bs_groups.(i) in
194-
Bsb_db_util.sanity_check c;
195-
Map_string.iter c
196-
(fun k a ->
197-
if Map_string.mem lib k then
198-
Bsb_db_util.conflict_module_info k a (Map_string.find_exn lib k)
199-
) ;
200-
Bsb_ninja_targets.output_kv
201-
(Bsb_dir_index.(string_of_bsb_dev_include (of_int i)))
202-
(Bsb_build_util.include_dirs source_dirs.(i)) oc
203-
done ;
204-
bs_groups,source_dirs.((Bsb_dir_index.lib_dir_index:>int)), static_resources
179+
let c = bs_groups.(1) in
180+
Bsb_db_util.sanity_check c;
181+
Map_string.iter c
182+
(fun k a ->
183+
if Map_string.mem lib k then
184+
Bsb_db_util.conflict_module_info k a (Map_string.find_exn lib k)
185+
) ;
186+
Bsb_ninja_targets.output_kv
187+
Bsb_ninja_global_vars.g_dev_incls
188+
(Bsb_build_util.include_dirs source_dirs.(1)) oc
189+
;
190+
bs_groups,source_dirs.(0), static_resources
205191
in
206192

207193
let digest = Bsb_db_encode.write_build_cache ~dir:cwd_lib_bs bs_groups in

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ let make_custom_rules
194194
define
195195
~restat:()
196196
~command:
197-
("$bsdep -hash " ^ digest ^" $g_ns -g $bsb_dir_group $in")
197+
("$bsdep -hash " ^ digest ^" $g_ns $bsb_dir_group $in")
198198
"build_deps" in
199199
let aux ~name ~read_cmi ~postbuild =
200200
let postbuild = has_postbuild && postbuild in

jscomp/bsb/bsb_parse_sources.ml

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let errorf x fmt =
4545

4646
type cxt = {
4747
toplevel : bool ;
48-
dir_index : Bsb_dir_index.t ;
48+
dev_index : bool;
4949
cwd : string ;
5050
root : string;
5151
cut_generators : bool;
@@ -339,18 +339,18 @@ let rec
339339
sources = sources;
340340
resources ;
341341
public ;
342-
dir_index = cxt.dir_index ;
342+
dev_index = cxt.dev_index ;
343343
generators = if has_generators then scanned_generators else [] }
344344
?globbed_dir:(
345345
if !cur_globbed_dirs then Some dir else None)
346346
children
347347

348348

349-
and parsing_single_source ({toplevel; dir_index ; cwd} as cxt ) (x : Ext_json_types.t )
349+
and parsing_single_source ({toplevel; dev_index ; cwd} as cxt ) (x : Ext_json_types.t )
350350
: t =
351351
match x with
352352
| Str { str = dir } ->
353-
if not toplevel && not (Bsb_dir_index.is_lib_dir dir_index) then
353+
if not toplevel && dev_index then
354354
Bsb_file_groups.empty
355355
else
356356
parsing_source_dir_map
@@ -361,10 +361,10 @@ and parsing_single_source ({toplevel; dir_index ; cwd} as cxt ) (x : Ext_json_ty
361361
let current_dir_index =
362362
match Map_string.find_opt map Bsb_build_schemas.type_ with
363363
| Some (Str {str="dev"}) ->
364-
Bsb_dir_index.get_dev_index ()
364+
true
365365
| Some _ -> Bsb_exception.config_error x {|type field expect "dev" literal |}
366-
| None -> dir_index in
367-
if not toplevel && not (Bsb_dir_index.is_lib_dir current_dir_index) then
366+
| None -> dev_index in
367+
if not toplevel && current_dir_index then
368368
Bsb_file_groups.empty
369369
else
370370
let dir =
@@ -379,7 +379,7 @@ and parsing_single_source ({toplevel; dir_index ; cwd} as cxt ) (x : Ext_json_ty
379379

380380
in
381381
parsing_source_dir_map
382-
{cxt with dir_index = current_dir_index;
382+
{cxt with dev_index = current_dir_index;
383383
cwd= Ext_path.concat cwd dir} map
384384
| _ -> Bsb_file_groups.empty
385385
and parsing_arr_sources cxt (file_groups : Ext_json_types.t array) =
@@ -401,21 +401,18 @@ let scan
401401
~namespace
402402
~bs_suffix
403403
~ignored_dirs
404-
x : t * int =
405-
Bsb_dir_index.reset ();
406-
let output =
407-
parse_sources {
408-
ignored_dirs;
409-
toplevel;
410-
dir_index = Bsb_dir_index.lib_dir_index;
411-
cwd = Filename.current_dir_name;
412-
root ;
413-
cut_generators;
414-
namespace;
415-
bs_suffix;
416-
traverse = false
417-
} x in
418-
output, Bsb_dir_index.get_current_number_of_dev_groups ()
404+
x : t =
405+
parse_sources {
406+
ignored_dirs;
407+
toplevel;
408+
dev_index = false;
409+
cwd = Filename.current_dir_name;
410+
root ;
411+
cut_generators;
412+
namespace;
413+
bs_suffix;
414+
traverse = false
415+
} x
419416

420417

421418

jscomp/bsb/bsb_parse_sources.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ val scan :
3737
bs_suffix:bool ->
3838
ignored_dirs:Set_string.t ->
3939
Ext_json_types.t ->
40-
Bsb_file_groups.t * int
40+
Bsb_file_groups.t
4141

4242
(** This function has some duplication
4343
from [scan],

jscomp/bsb_helper/bsb_db_decode.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ type module_info = {
102102

103103

104104
let find_opt
105-
((sorteds,whole) : t ) i (key : string)
105+
((sorteds,whole) : t )
106+
(i : int) (key : string)
106107
: module_info option =
107108
let group = sorteds.(i) in
108109
let i = Ext_string_array.find_sorted group.modules key in
@@ -130,5 +131,11 @@ let find_opt
130131
in
131132
Some {case ; dir_name = String.sub whole dir_name_start (dir_name_finish - dir_name_start)}
132133

133-
134-
134+
let find db dependent_module is_not_lib_dir =
135+
let opt = find_opt db 0 dependent_module in
136+
match opt with
137+
| Some _ -> opt
138+
| None ->
139+
if is_not_lib_dir then
140+
find_opt db 1 dependent_module
141+
else None

0 commit comments

Comments
 (0)