@@ -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
78117814val 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
78177820end = struct
78187821#1 " bsb_dep_infos.ml"
@@ -7848,7 +7851,8 @@ type dep_info = {
78487851type 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+
78777903let 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
78997934let 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
79027941end
79037942module 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*)
90059044let 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
90359080let 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 "
0 commit comments