Skip to content

Commit 2958e6c

Browse files
committed
detect compiler version, if mismatches, do a clean and rebuild
1 parent b9c5d24 commit 2958e6c

File tree

5 files changed

+150
-59
lines changed

5 files changed

+150
-59
lines changed

jscomp/all.depend

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@ bsb/bsb_default.cmx : ext/string_set.cmx ext/literals.cmx \
667667
ext/ext_pervasives.cmx ext/ext_filename.cmx bsb/bsb_config_types.cmx \
668668
bsb/bsb_config.cmx bsb/bsb_build_util.cmx common/bs_version.cmx \
669669
common/bs_pkg.cmx bsb/bsb_default.cmi
670-
bsb/bsb_dep_infos.cmx : bsb/bsb_dep_infos.cmi
670+
bsb/bsb_dep_infos.cmx : ext/ext_string.cmx common/bs_version.cmx \
671+
bsb/bsb_dep_infos.cmi
671672
bsb/bsb_dir.cmx : bsb/bsb_dir.cmi
672673
bsb/bsb_file.cmx : bsb/bsb_file.cmi
673674
bsb/bsb_gen.cmx : ext/string_map.cmx ext/literals.cmx ext/ext_string.cmx \

jscomp/bin/bsb.ml

Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7797,22 +7797,25 @@ type dep_info = {
77977797
77987798
It may not, since there is some subtlies here (__FILE__ or __dirname)
77997799
*)
7800-
type t =
7801-
{ file_stamps : dep_info array ;
7802-
source_directory : string ;
7803-
bsb_version : string
7804-
}
7805-
78067800

78077801

78087802

78097803

7804+
type check_result =
7805+
| Good
7806+
| Bsb_file_not_exist (** We assume that it is a clean repo *)
7807+
| Bsb_version_mismatch
7808+
| Bsb_source_directory_changed
7809+
| Bsc_version_mismatch
7810+
| Bsb_forced
7811+
| Other of string
78107812

7813+
val to_str : check_result -> string
78117814
val store : cwd:string -> string -> dep_info array -> unit
78127815

78137816

78147817
(** check if [build.ninja] should be regenerated *)
7815-
val check : cwd:string -> string -> string
7818+
val check : cwd:string -> bool -> string -> check_result
78167819

78177820
end = struct
78187821
#1 "bsb_dep_infos.ml"
@@ -7848,7 +7851,8 @@ type dep_info = {
78487851
type t =
78497852
{ file_stamps : dep_info array ;
78507853
source_directory : string ;
7851-
bsb_version : string
7854+
bsb_version : string;
7855+
bsc_version : string;
78527856
}
78537857

78547858

@@ -7871,33 +7875,68 @@ let read (fname : string) : t =
78717875

78727876

78737877

7874-
let no_need_regenerate = ""
78757878

78767879

7880+
type check_result =
7881+
| Good
7882+
| Bsb_file_not_exist (** We assume that it is a clean repo *)
7883+
| Bsb_version_mismatch
7884+
| Bsb_source_directory_changed
7885+
| Bsc_version_mismatch
7886+
| Bsb_forced
7887+
| Other of string
7888+
7889+
let to_str (check_resoult : check_result) =
7890+
match check_resoult with
7891+
| Good -> Ext_string.empty
7892+
| Bsb_file_not_exist -> "File not found"
7893+
| Bsb_version_mismatch -> "Bsb version mismatch"
7894+
| Bsb_source_directory_changed ->
7895+
"Bsb source directory changed"
7896+
| Bsc_version_mismatch ->
7897+
"Bsc version mismatch"
7898+
| Bsb_forced ->
7899+
"Bsb forced rebuild "
7900+
| Other s ->
7901+
s
7902+
78777903
let rec check_aux xs i finish =
7878-
if i = finish then no_need_regenerate
7904+
if i = finish then Good
78797905
else
78807906
let k = Array.unsafe_get xs i in
78817907
let current_file = k.dir_or_file in
78827908
let stat = Unix.stat current_file in
78837909
if stat.st_mtime <= k.stamp then
78847910
check_aux xs (i + 1 ) finish
7885-
else current_file
7911+
else Other current_file
78867912

7913+
78877914
(** check time stamp for all files
78887915
TODO: those checks system call can be saved later
78897916
Return a reason
7917+
Even forced, we still need walk through a little
7918+
bit in case we found a different version of compiler
78907919
*)
7891-
let check ~cwd file =
7920+
let check ~cwd forced file =
78927921
try
7893-
let {file_stamps = xs; source_directory; bsb_version = old_version} = read file in
7894-
if old_version <> bsb_version then old_version ^ " -> " ^ bsb_version else
7895-
if cwd <> source_directory then source_directory ^ " -> " ^ cwd else
7922+
let {
7923+
file_stamps = xs; source_directory; bsb_version = old_version;
7924+
bsc_version
7925+
} = read file in
7926+
if old_version <> bsb_version then Bsb_version_mismatch else
7927+
if cwd <> source_directory then Bsb_source_directory_changed else
7928+
if bsc_version <> Bs_version.version then Bsc_version_mismatch else
7929+
if forced then Bsb_forced (* No need walk through *)
7930+
else
78967931
check_aux xs 0 (Array.length xs)
7897-
with _ -> file ^ " does not exist"
7932+
with _ -> Bsb_file_not_exist
78987933

78997934
let store ~cwd name file_stamps =
7900-
write name { file_stamps ; source_directory = cwd ; bsb_version }
7935+
write name
7936+
{ file_stamps ;
7937+
source_directory = cwd ;
7938+
bsb_version ;
7939+
bsc_version = Bs_version.version }
79017940

79027941
end
79037942
module Bsb_file : sig
@@ -8987,7 +9026,7 @@ let bsb_main_flags =
89879026
no_dev, Arg.Set Bsb_config.no_dev,
89889027
" (internal)Build dev dependencies in make-world and dev group(in combination with -regen)";
89899028
regen, Arg.Set force_regenerate,
8990-
" Always regenerate build.ninja no matter bsconfig.json is changed or not (for debugging purpose)"
9029+
" (internal)Always regenerate build.ninja no matter bsconfig.json is changed or not (for debugging purpose)"
89919030
;
89929031
internal_package_specs, Arg.String Bsb_config.cmd_override_package_specs,
89939032
" (internal)Overide package specs (in combination with -regen)";
@@ -9004,14 +9043,22 @@ let bsb_main_flags =
90049043
*)
90059044
let regenerate_ninja cwd bsc_dir forced =
90069045
let output_deps = Bsb_config.lib_bs // bsdeps in
9007-
let reason =
9008-
if forced then "Regenerating ninja (triggered by command line -regen)"
9009-
else
9010-
Bsb_dep_infos.check ~cwd output_deps in
9011-
if String.length reason <> 0 then
9012-
begin
9013-
print_endline reason ;
9014-
print_endline "Regenerating build spec";
9046+
let reason : Bsb_dep_infos.check_result =
9047+
Bsb_dep_infos.check ~cwd forced output_deps in
9048+
begin match reason with
9049+
| Good -> None (* Fast path *)
9050+
| Bsb_forced
9051+
| Bsc_version_mismatch
9052+
| Bsb_file_not_exist
9053+
| Bsb_version_mismatch
9054+
| Bsb_source_directory_changed
9055+
| Other _ ->
9056+
print_string "Regenerating build spec : ";
9057+
print_endline (Bsb_dep_infos.to_str reason) ;
9058+
if reason = Bsc_version_mismatch then begin
9059+
print_endline "Also clean current repo due to we have detected a different compiler";
9060+
clean_self ();
9061+
end ;
90159062
let config =
90169063
Bsb_config_parse.interpret_json
90179064
~override_package_specs:!Bsb_config.cmd_package_specs
@@ -9028,9 +9075,7 @@ let regenerate_ninja cwd bsc_dir forced =
90289075
|> (fun x -> Bsb_dep_infos.store ~cwd output_deps (Array.of_list x));
90299076
Some config
90309077
end
9031-
(* This makes sense since we did parse the json file *)
9032-
end
9033-
else None
9078+
end
90349079

90359080
let ninja_error_message = "ninja (required for bsb build system) is not installed, \n\
90369081
please visit https://github.com/ninja-build/ninja to have it installed\n"

jscomp/bsb/bsb_dep_infos.ml

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ type dep_info = {
3030
type t =
3131
{ file_stamps : dep_info array ;
3232
source_directory : string ;
33-
bsb_version : string
33+
bsb_version : string;
34+
bsc_version : string;
3435
}
3536

3637

@@ -53,30 +54,65 @@ let read (fname : string) : t =
5354

5455

5556

56-
let no_need_regenerate = ""
5757

5858

59+
type check_result =
60+
| Good
61+
| Bsb_file_not_exist (** We assume that it is a clean repo *)
62+
| Bsb_version_mismatch
63+
| Bsb_source_directory_changed
64+
| Bsc_version_mismatch
65+
| Bsb_forced
66+
| Other of string
67+
68+
let to_str (check_resoult : check_result) =
69+
match check_resoult with
70+
| Good -> Ext_string.empty
71+
| Bsb_file_not_exist -> "File not found"
72+
| Bsb_version_mismatch -> "Bsb version mismatch"
73+
| Bsb_source_directory_changed ->
74+
"Bsb source directory changed"
75+
| Bsc_version_mismatch ->
76+
"Bsc version mismatch"
77+
| Bsb_forced ->
78+
"Bsb forced rebuild "
79+
| Other s ->
80+
s
81+
5982
let rec check_aux xs i finish =
60-
if i = finish then no_need_regenerate
83+
if i = finish then Good
6184
else
6285
let k = Array.unsafe_get xs i in
6386
let current_file = k.dir_or_file in
6487
let stat = Unix.stat current_file in
6588
if stat.st_mtime <= k.stamp then
6689
check_aux xs (i + 1 ) finish
67-
else current_file
90+
else Other current_file
6891

92+
6993
(** check time stamp for all files
7094
TODO: those checks system call can be saved later
7195
Return a reason
96+
Even forced, we still need walk through a little
97+
bit in case we found a different version of compiler
7298
*)
73-
let check ~cwd file =
99+
let check ~cwd forced file =
74100
try
75-
let {file_stamps = xs; source_directory; bsb_version = old_version} = read file in
76-
if old_version <> bsb_version then old_version ^ " -> " ^ bsb_version else
77-
if cwd <> source_directory then source_directory ^ " -> " ^ cwd else
101+
let {
102+
file_stamps = xs; source_directory; bsb_version = old_version;
103+
bsc_version
104+
} = read file in
105+
if old_version <> bsb_version then Bsb_version_mismatch else
106+
if cwd <> source_directory then Bsb_source_directory_changed else
107+
if bsc_version <> Bs_version.version then Bsc_version_mismatch else
108+
if forced then Bsb_forced (* No need walk through *)
109+
else
78110
check_aux xs 0 (Array.length xs)
79-
with _ -> file ^ " does not exist"
111+
with _ -> Bsb_file_not_exist
80112

81113
let store ~cwd name file_stamps =
82-
write name { file_stamps ; source_directory = cwd ; bsb_version }
114+
write name
115+
{ file_stamps ;
116+
source_directory = cwd ;
117+
bsb_version ;
118+
bsc_version = Bs_version.version }

jscomp/bsb/bsb_dep_infos.mli

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,22 @@ type dep_info = {
3939
4040
It may not, since there is some subtlies here (__FILE__ or __dirname)
4141
*)
42-
type t =
43-
{ file_stamps : dep_info array ;
44-
source_directory : string ;
45-
bsb_version : string
46-
}
47-
4842

4943

5044

5145

46+
type check_result =
47+
| Good
48+
| Bsb_file_not_exist (** We assume that it is a clean repo *)
49+
| Bsb_version_mismatch
50+
| Bsb_source_directory_changed
51+
| Bsc_version_mismatch
52+
| Bsb_forced
53+
| Other of string
5254

55+
val to_str : check_result -> string
5356
val store : cwd:string -> string -> dep_info array -> unit
5457

5558

5659
(** check if [build.ninja] should be regenerated *)
57-
val check : cwd:string -> string -> string
60+
val check : cwd:string -> bool -> string -> check_result

jscomp/bsb/bsb_main.ml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ let bsb_main_flags =
108108
no_dev, Arg.Set Bsb_config.no_dev,
109109
" (internal)Build dev dependencies in make-world and dev group(in combination with -regen)";
110110
regen, Arg.Set force_regenerate,
111-
" Always regenerate build.ninja no matter bsconfig.json is changed or not (for debugging purpose)"
111+
" (internal)Always regenerate build.ninja no matter bsconfig.json is changed or not (for debugging purpose)"
112112
;
113113
internal_package_specs, Arg.String Bsb_config.cmd_override_package_specs,
114114
" (internal)Overide package specs (in combination with -regen)";
@@ -125,14 +125,22 @@ let bsb_main_flags =
125125
*)
126126
let regenerate_ninja cwd bsc_dir forced =
127127
let output_deps = Bsb_config.lib_bs // bsdeps in
128-
let reason =
129-
if forced then "Regenerating ninja (triggered by command line -regen)"
130-
else
131-
Bsb_dep_infos.check ~cwd output_deps in
132-
if String.length reason <> 0 then
133-
begin
134-
print_endline reason ;
135-
print_endline "Regenerating build spec";
128+
let reason : Bsb_dep_infos.check_result =
129+
Bsb_dep_infos.check ~cwd forced output_deps in
130+
begin match reason with
131+
| Good -> None (* Fast path *)
132+
| Bsb_forced
133+
| Bsc_version_mismatch
134+
| Bsb_file_not_exist
135+
| Bsb_version_mismatch
136+
| Bsb_source_directory_changed
137+
| Other _ ->
138+
print_string "Regenerating build spec : ";
139+
print_endline (Bsb_dep_infos.to_str reason) ;
140+
if reason = Bsc_version_mismatch then begin
141+
print_endline "Also clean current repo due to we have detected a different compiler";
142+
clean_self ();
143+
end ;
136144
let config =
137145
Bsb_config_parse.interpret_json
138146
~override_package_specs:!Bsb_config.cmd_package_specs
@@ -149,9 +157,7 @@ let regenerate_ninja cwd bsc_dir forced =
149157
|> (fun x -> Bsb_dep_infos.store ~cwd output_deps (Array.of_list x));
150158
Some config
151159
end
152-
(* This makes sense since we did parse the json file *)
153-
end
154-
else None
160+
end
155161

156162
let ninja_error_message = "ninja (required for bsb build system) is not installed, \n\
157163
please visit https://github.com/ninja-build/ninja to have it installed\n"

0 commit comments

Comments
 (0)