@@ -7797,22 +7797,24 @@ type dep_info = {
7797
7797
7798
7798
It may not, since there is some subtlies here (__FILE__ or __dirname)
7799
7799
*)
7800
- type t =
7801
- { file_stamps : dep_info array ;
7802
- source_directory : string ;
7803
- bsb_version : string
7804
- }
7805
-
7806
7800
7807
7801
7808
7802
7809
7803
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
7810
7811
7812
+ val to_str : check_result -> string
7811
7813
val store : cwd :string -> string -> dep_info array -> unit
7812
7814
7813
7815
7814
7816
(* * check if [build.ninja] should be regenerated *)
7815
- val check : cwd :string -> string -> string
7817
+ val check : cwd :string -> bool -> string -> check_result
7816
7818
7817
7819
end = struct
7818
7820
#1 " bsb_dep_infos.ml"
@@ -7848,56 +7850,96 @@ type dep_info = {
7848
7850
type t =
7849
7851
{ file_stamps : dep_info array ;
7850
7852
source_directory : string ;
7851
- bsb_version : string
7853
+ bsb_version : string ;
7854
+ bsc_version : string ;
7852
7855
}
7853
7856
7854
7857
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 *)
7857
7861
7858
7862
let write (fname : string ) (x : t ) =
7859
7863
let oc = open_out_bin fname in
7860
7864
output_string oc magic_number ;
7861
7865
output_value oc x ;
7862
7866
close_out oc
7863
7867
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
7871
7868
7872
7869
7873
7870
7874
- let no_need_regenerate = " "
7875
7871
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
7876
7892
7877
7893
let rec check_aux xs i finish =
7878
- if i = finish then no_need_regenerate
7894
+ if i = finish then Good
7879
7895
else
7880
7896
let k = Array. unsafe_get xs i in
7881
7897
let current_file = k.dir_or_file in
7882
7898
let stat = Unix. stat current_file in
7883
7899
if stat.st_mtime < = k.stamp then
7884
7900
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
+
7886
7915
7887
7916
(* * check time stamp for all files
7888
7917
TODO: those checks system call can be saved later
7889
7918
Return a reason
7919
+ Even forced, we still need walk through a little
7920
+ bit in case we found a different version of compiler
7890
7921
*)
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
7898
7936
7899
7937
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 }
7901
7943
7902
7944
end
7903
7945
module Bsb_file : sig
@@ -8987,7 +9029,7 @@ let bsb_main_flags =
8987
9029
no_dev, Arg. Set Bsb_config. no_dev,
8988
9030
" (internal)Build dev dependencies in make-world and dev group(in combination with -regen)" ;
8989
9031
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)"
8991
9033
;
8992
9034
internal_package_specs, Arg. String Bsb_config. cmd_override_package_specs,
8993
9035
" (internal)Overide package specs (in combination with -regen)" ;
@@ -9004,14 +9046,21 @@ let bsb_main_flags =
9004
9046
*)
9005
9047
let regenerate_ninja cwd bsc_dir forced =
9006
9048
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 ;
9015
9064
let config =
9016
9065
Bsb_config_parse. interpret_json
9017
9066
~override_package_specs: ! Bsb_config. cmd_package_specs
@@ -9028,9 +9077,7 @@ let regenerate_ninja cwd bsc_dir forced =
9028
9077
|> (fun x -> Bsb_dep_infos. store ~cwd output_deps (Array. of_list x));
9029
9078
Some config
9030
9079
end
9031
- (* This makes sense since we did parse the json file *)
9032
- end
9033
- else None
9080
+ end
9034
9081
9035
9082
let ninja_error_message = " ninja (required for bsb build system) is not installed, \n \
9036
9083
please visit https://github.com/ninja-build/ninja to have it installed\n "
0 commit comments