@@ -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
78117813val 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
78177819end = struct
78187820#1 " bsb_dep_infos.ml"
@@ -7848,56 +7850,96 @@ type dep_info = {
78487850type 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
78587862let 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
78777893let 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
78997937let 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
79027944end
79037945module 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*)
90059047let 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
90359082let 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 "
0 commit comments