Skip to content

Commit 2934a3f

Browse files
authored
Merge pull request #1197 from bloomberg/detect_compiler_world
fix Makefile bugs, under specified dependency on compiler
2 parents 89c46a5 + 3134229 commit 2934a3f

File tree

7 files changed

+183
-85
lines changed

7 files changed

+183
-85
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: 87 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7797,22 +7797,24 @@ 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_source_directory_changed
7808+
| Bsb_bsc_version_mismatch
7809+
| Bsb_forced
7810+
| Other of string
78107811

7812+
val to_str : check_result -> string
78117813
val store : cwd:string -> string -> dep_info array -> unit
78127814

78137815

78147816
(** check if [build.ninja] should be regenerated *)
7815-
val check : cwd:string -> string -> string
7817+
val check : cwd:string -> bool -> string -> check_result
78167818

78177819
end = struct
78187820
#1 "bsb_dep_infos.ml"
@@ -7848,56 +7850,96 @@ type dep_info = {
78487850
type t =
78497851
{ file_stamps : dep_info array ;
78507852
source_directory : string ;
7851-
bsb_version : string
7853+
bsb_version : string;
7854+
bsc_version : string;
78527855
}
78537856

78547857

7855-
let magic_number = "BS_DEP_INFOS_20161116"
7856-
let bsb_version = "20160121+dev"
7858+
let magic_number = "BS_DEP_INFOS_20170209"
7859+
let bsb_version = "20170209+dev"
7860+
(* TODO: for such small data structure, maybe text format is better *)
78577861

78587862
let write (fname : string) (x : t) =
78597863
let oc = open_out_bin fname in
78607864
output_string oc magic_number ;
78617865
output_value oc x ;
78627866
close_out oc
78637867

7864-
let read (fname : string) : t =
7865-
let ic = open_in_bin fname in (* Windows binary mode*)
7866-
let buffer = really_input_string ic (String.length magic_number) in
7867-
assert (buffer = magic_number);
7868-
let res : t = input_value ic in
7869-
close_in ic ;
7870-
res
78717868

78727869

78737870

7874-
let no_need_regenerate = ""
78757871

7872+
type check_result =
7873+
| Good
7874+
| Bsb_file_not_exist (** We assume that it is a clean repo *)
7875+
| Bsb_source_directory_changed
7876+
| Bsb_bsc_version_mismatch
7877+
| Bsb_forced
7878+
| Other of string
7879+
7880+
let to_str (check_resoult : check_result) =
7881+
match check_resoult with
7882+
| Good -> Ext_string.empty
7883+
| Bsb_file_not_exist -> "File not found"
7884+
| Bsb_source_directory_changed ->
7885+
"Bsb source directory changed"
7886+
| Bsb_bsc_version_mismatch ->
7887+
"bsc or bsb version mismatch"
7888+
| Bsb_forced ->
7889+
"Bsb forced rebuild "
7890+
| Other s ->
7891+
s
78767892

78777893
let rec check_aux xs i finish =
7878-
if i = finish then no_need_regenerate
7894+
if i = finish then Good
78797895
else
78807896
let k = Array.unsafe_get xs i in
78817897
let current_file = k.dir_or_file in
78827898
let stat = Unix.stat current_file in
78837899
if stat.st_mtime <= k.stamp then
78847900
check_aux xs (i + 1 ) finish
7885-
else current_file
7901+
else Other current_file
7902+
7903+
7904+
let read (fname : string) cont =
7905+
match open_in_bin fname with (* Windows binary mode*)
7906+
| ic ->
7907+
let buffer = really_input_string ic (String.length magic_number) in
7908+
if (buffer <> magic_number) then Bsb_bsc_version_mismatch
7909+
else
7910+
let res : t = input_value ic in
7911+
close_in ic ;
7912+
cont res
7913+
| exception _ -> Bsb_file_not_exist
7914+
78867915

78877916
(** check time stamp for all files
78887917
TODO: those checks system call can be saved later
78897918
Return a reason
7919+
Even forced, we still need walk through a little
7920+
bit in case we found a different version of compiler
78907921
*)
7891-
let check ~cwd file =
7892-
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
7896-
check_aux xs 0 (Array.length xs)
7897-
with _ -> file ^ " does not exist"
7922+
let check ~cwd forced file =
7923+
read file begin function {
7924+
file_stamps = xs; source_directory; bsb_version = old_version;
7925+
bsc_version
7926+
} ->
7927+
if old_version <> bsb_version then Bsb_bsc_version_mismatch else
7928+
if cwd <> source_directory then Bsb_source_directory_changed else
7929+
if bsc_version <> Bs_version.version then Bsb_bsc_version_mismatch else
7930+
if forced then Bsb_forced (* No need walk through *)
7931+
else
7932+
try
7933+
check_aux xs 0 (Array.length xs)
7934+
with _ -> Bsb_file_not_exist
7935+
end
78987936

78997937
let store ~cwd name file_stamps =
7900-
write name { file_stamps ; source_directory = cwd ; bsb_version }
7938+
write name
7939+
{ file_stamps ;
7940+
source_directory = cwd ;
7941+
bsb_version ;
7942+
bsc_version = Bs_version.version }
79017943

79027944
end
79037945
module Bsb_file : sig
@@ -8987,7 +9029,7 @@ let bsb_main_flags =
89879029
no_dev, Arg.Set Bsb_config.no_dev,
89889030
" (internal)Build dev dependencies in make-world and dev group(in combination with -regen)";
89899031
regen, Arg.Set force_regenerate,
8990-
" Always regenerate build.ninja no matter bsconfig.json is changed or not (for debugging purpose)"
9032+
" (internal)Always regenerate build.ninja no matter bsconfig.json is changed or not (for debugging purpose)"
89919033
;
89929034
internal_package_specs, Arg.String Bsb_config.cmd_override_package_specs,
89939035
" (internal)Overide package specs (in combination with -regen)";
@@ -9004,14 +9046,21 @@ let bsb_main_flags =
90049046
*)
90059047
let regenerate_ninja cwd bsc_dir forced =
90069048
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";
9049+
let reason : Bsb_dep_infos.check_result =
9050+
Bsb_dep_infos.check ~cwd forced output_deps in
9051+
begin match reason with
9052+
| Good -> None (* Fast path *)
9053+
| Bsb_forced
9054+
| Bsb_bsc_version_mismatch
9055+
| Bsb_file_not_exist
9056+
| Bsb_source_directory_changed
9057+
| Other _ ->
9058+
print_string "Regenerating build spec : ";
9059+
print_endline (Bsb_dep_infos.to_str reason) ;
9060+
if reason = Bsb_bsc_version_mismatch then begin
9061+
print_endline "Also clean current repo due to we have detected a different compiler";
9062+
clean_self ();
9063+
end ;
90159064
let config =
90169065
Bsb_config_parse.interpret_json
90179066
~override_package_specs:!Bsb_config.cmd_package_specs
@@ -9028,9 +9077,7 @@ let regenerate_ninja cwd bsc_dir forced =
90289077
|> (fun x -> Bsb_dep_infos.store ~cwd output_deps (Array.of_list x));
90299078
Some config
90309079
end
9031-
(* This makes sense since we did parse the json file *)
9032-
end
9033-
else None
9080+
end
90349081

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

jscomp/bsb/bsb_dep_infos.ml

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,53 +30,93 @@ 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

37-
let magic_number = "BS_DEP_INFOS_20161116"
38-
let bsb_version = "20160121+dev"
38+
let magic_number = "BS_DEP_INFOS_20170209"
39+
let bsb_version = "20170209+dev"
40+
(* TODO: for such small data structure, maybe text format is better *)
3941

4042
let write (fname : string) (x : t) =
4143
let oc = open_out_bin fname in
4244
output_string oc magic_number ;
4345
output_value oc x ;
4446
close_out oc
4547

46-
let read (fname : string) : t =
47-
let ic = open_in_bin fname in (* Windows binary mode*)
48-
let buffer = really_input_string ic (String.length magic_number) in
49-
assert (buffer = magic_number);
50-
let res : t = input_value ic in
51-
close_in ic ;
52-
res
5348

5449

5550

56-
let no_need_regenerate = ""
5751

52+
type check_result =
53+
| Good
54+
| Bsb_file_not_exist (** We assume that it is a clean repo *)
55+
| Bsb_source_directory_changed
56+
| Bsb_bsc_version_mismatch
57+
| Bsb_forced
58+
| Other of string
59+
60+
let to_str (check_resoult : check_result) =
61+
match check_resoult with
62+
| Good -> Ext_string.empty
63+
| Bsb_file_not_exist -> "File not found"
64+
| Bsb_source_directory_changed ->
65+
"Bsb source directory changed"
66+
| Bsb_bsc_version_mismatch ->
67+
"bsc or bsb version mismatch"
68+
| Bsb_forced ->
69+
"Bsb forced rebuild "
70+
| Other s ->
71+
s
5872

5973
let rec check_aux xs i finish =
60-
if i = finish then no_need_regenerate
74+
if i = finish then Good
6175
else
6276
let k = Array.unsafe_get xs i in
6377
let current_file = k.dir_or_file in
6478
let stat = Unix.stat current_file in
6579
if stat.st_mtime <= k.stamp then
6680
check_aux xs (i + 1 ) finish
67-
else current_file
81+
else Other current_file
82+
83+
84+
let read (fname : string) cont =
85+
match open_in_bin fname with (* Windows binary mode*)
86+
| ic ->
87+
let buffer = really_input_string ic (String.length magic_number) in
88+
if (buffer <> magic_number) then Bsb_bsc_version_mismatch
89+
else
90+
let res : t = input_value ic in
91+
close_in ic ;
92+
cont res
93+
| exception _ -> Bsb_file_not_exist
94+
6895

6996
(** check time stamp for all files
7097
TODO: those checks system call can be saved later
7198
Return a reason
99+
Even forced, we still need walk through a little
100+
bit in case we found a different version of compiler
72101
*)
73-
let check ~cwd file =
74-
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
78-
check_aux xs 0 (Array.length xs)
79-
with _ -> file ^ " does not exist"
102+
let check ~cwd forced file =
103+
read file begin function {
104+
file_stamps = xs; source_directory; bsb_version = old_version;
105+
bsc_version
106+
} ->
107+
if old_version <> bsb_version then Bsb_bsc_version_mismatch else
108+
if cwd <> source_directory then Bsb_source_directory_changed else
109+
if bsc_version <> Bs_version.version then Bsb_bsc_version_mismatch else
110+
if forced then Bsb_forced (* No need walk through *)
111+
else
112+
try
113+
check_aux xs 0 (Array.length xs)
114+
with _ -> Bsb_file_not_exist
115+
end
80116

81117
let store ~cwd name file_stamps =
82-
write name { file_stamps ; source_directory = cwd ; bsb_version }
118+
write name
119+
{ file_stamps ;
120+
source_directory = cwd ;
121+
bsb_version ;
122+
bsc_version = Bs_version.version }

jscomp/bsb/bsb_dep_infos.mli

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,21 @@ 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_source_directory_changed
50+
| Bsb_bsc_version_mismatch
51+
| Bsb_forced
52+
| Other of string
5253

54+
val to_str : check_result -> string
5355
val store : cwd:string -> string -> dep_info array -> unit
5456

5557

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

0 commit comments

Comments
 (0)