@@ -787,8 +787,86 @@ namespace vix::commands::RunCommand::detail
787787 }
788788#endif
789789
790+ int materialize_cmake_script_project (const Options &opt, const ScriptProjectState &state)
791+ {
792+ std::error_code ec;
793+ fs::create_directories (state.projectDir , ec);
794+ if (ec)
795+ {
796+ error (" Failed to create script project directory." );
797+ return 1 ;
798+ }
799+
800+ const std::string cmakeText = make_script_cmakelists (
801+ state.exeName ,
802+ state.script ,
803+ state.useVixRuntime ,
804+ opt.scriptFlags ,
805+ opt.withSqlite ,
806+ opt.withMySql );
807+
808+ {
809+ std::ofstream out (state.cmakeLists , std::ios::trunc);
810+ if (!out)
811+ {
812+ error (" Failed to write generated CMakeLists.txt." );
813+ return 1 ;
814+ }
815+ out << cmakeText;
816+ }
817+
818+ if (!state.configSignature .empty ())
819+ {
820+ std::ofstream sig (state.sigFile , std::ios::trunc);
821+ if (sig)
822+ sig << state.configSignature ;
823+ }
824+
825+ return 0 ;
826+ }
827+
828+ void compute_need_configure (ScriptProjectState &state)
829+ {
830+ state.needConfigure = true ;
831+
832+ std::error_code ec{};
833+ if (fs::exists (state.buildDir / " CMakeCache.txt" , ec) && !ec)
834+ {
835+ const std::string oldSig = text::read_text_file_or_empty (state.sigFile );
836+ if (!oldSig.empty () && oldSig == state.configSignature )
837+ state.needConfigure = false ;
838+ }
839+
840+ if (!cache_is_ninja_build (state.buildDir ))
841+ {
842+ std::error_code rmEc;
843+ fs::remove_all (state.buildDir , rmEc);
844+ state.needConfigure = true ;
845+ }
846+ }
847+
790848 int configure_and_build_script (Options &o, ScriptProjectState &state)
791849 {
850+ const int materializeCode = materialize_cmake_script_project (o, state);
851+ if (materializeCode != 0 )
852+ return materializeCode;
853+
854+ compute_need_configure (state);
855+
856+ if (o.clean )
857+ {
858+ std::error_code ec;
859+ fs::remove_all (state.buildDir , ec);
860+ fs::remove (state.sigFile , ec);
861+
862+ const int rematerializeCode = materialize_cmake_script_project (o, state);
863+ if (rematerializeCode != 0 )
864+ return rematerializeCode;
865+
866+ state.needConfigure = true ;
867+ state.skipBuild = false ;
868+ }
869+
792870 const int cfgCode = configure_script_project (o, state);
793871 if (cfgCode != 0 )
794872 return cfgCode;
@@ -905,64 +983,6 @@ namespace vix::commands::RunCommand::detail
905983 return out;
906984 }
907985
908- int materialize_cmake_script_project (const Options &opt, const ScriptProjectState &state)
909- {
910- std::error_code ec;
911- fs::create_directories (state.projectDir , ec);
912- if (ec)
913- {
914- error (" Failed to create script project directory." );
915- return 1 ;
916- }
917-
918- const std::string cmakeText = make_script_cmakelists (
919- state.exeName ,
920- state.script ,
921- state.useVixRuntime ,
922- opt.scriptFlags ,
923- opt.withSqlite ,
924- opt.withMySql );
925-
926- {
927- std::ofstream out (state.cmakeLists , std::ios::trunc);
928- if (!out)
929- {
930- error (" Failed to write generated CMakeLists.txt." );
931- return 1 ;
932- }
933- out << cmakeText;
934- }
935-
936- if (!state.configSignature .empty ())
937- {
938- std::ofstream sig (state.sigFile , std::ios::trunc);
939- if (sig)
940- sig << state.configSignature ;
941- }
942-
943- return 0 ;
944- }
945-
946- void compute_need_configure (ScriptProjectState &state)
947- {
948- state.needConfigure = true ;
949-
950- std::error_code ec{};
951- if (fs::exists (state.buildDir / " CMakeCache.txt" , ec) && !ec)
952- {
953- const std::string oldSig = text::read_text_file_or_empty (state.sigFile );
954- if (!oldSig.empty () && oldSig == state.configSignature )
955- state.needConfigure = false ;
956- }
957-
958- if (!cache_is_ninja_build (state.buildDir ))
959- {
960- std::error_code rmEc;
961- fs::remove_all (state.buildDir , rmEc);
962- state.needConfigure = true ;
963- }
964- }
965-
966986 } // namespace
967987
968988 CMakeScriptPlan make_cmake_script_plan (
@@ -1019,42 +1039,9 @@ namespace vix::commands::RunCommand::detail
10191039 Options o = opt;
10201040 ScriptProjectState state = make_state_from_cmake_plan (plan);
10211041
1022- if (o.clean )
1023- {
1024- std::error_code ec;
1025- fs::remove_all (state.buildDir , ec);
1026- fs::remove (state.sigFile , ec);
1027- state.needConfigure = true ;
1028- state.skipBuild = false ;
1029- }
1030-
1031- const int materializeCode = materialize_cmake_script_project (o, state);
1032- if (materializeCode != 0 )
1033- return materializeCode;
1034-
1035- compute_need_configure (state);
1036-
1037- #ifndef _WIN32
1038- if (!state.needConfigure &&
1039- !needs_rebuild_from_depfiles_cached (state.exePath , state.buildDir , state.exeName ))
1040- {
1041- state.skipBuild = true ;
1042- if (!o.quiet )
1043- hint (" Up to date (skip build)." );
1044- }
1045- #endif
1046-
1047- const int cfgCode = configure_script_project (o, state);
1048- if (cfgCode != 0 )
1049- return cfgCode;
1050-
1051- const int buildCode = build_script_project (o, state);
1052- if (buildCode != 0 )
1053- return buildCode;
1054-
1055- const int exeCode = ensure_script_executable_exists (state);
1056- if (exeCode != 0 )
1057- return exeCode;
1042+ const int code = configure_and_build_script (o, state);
1043+ if (code != 0 )
1044+ return code;
10581045
10591046#ifdef _WIN32
10601047 return run_script_binary_windows (o, state);
0 commit comments