@@ -561,9 +561,6 @@ runcpp2::StartPipeline( const std::string& scriptPath,
561561{
562562 INTERNAL_RUNCPP2_SAFE_START ();
563563
564- // Do lexically_normal on all the paths
565- // lexically_normal
566-
567564 ssLOG_FUNC_DEBUG ();
568565
569566 if (profiles.empty ())
@@ -717,39 +714,126 @@ runcpp2::StartPipeline( const std::string& scriptPath,
717714 }
718715
719716 // Check if script info has changed if provided
720- bool scriptInfoChanged = true ;
717+ bool recompileNeeded = false ;
718+ bool relinkNeeded = false ;
719+ std::vector<std::string> changedDependencies;
721720 {
722721 ghc::filesystem::path lastScriptInfoFilePath = buildDir / " LastScriptInfo.yaml" ;
722+ Data::ScriptInfo lastScriptInfoFromDisk;
723723
724- // Compare script info in memory
725- if (lastScriptInfo != nullptr )
726- scriptInfoChanged = lastScriptInfo->ToString (" " ) != scriptInfo.ToString (" " );
727- // Compare script info in disk
728- else
724+ // Compare script info in memory or from disk
725+ const Data::ScriptInfo* lastInfo = lastScriptInfo;
726+ if (lastScriptInfo == nullptr && ghc::filesystem::exists (lastScriptInfoFilePath, e))
729727 {
730- if (ghc::filesystem::exists (lastScriptInfoFilePath, e))
728+ ssLOG_DEBUG (" Last script info file exists: " << lastScriptInfoFilePath);
729+ std::ifstream lastScriptInfoFile;
730+ lastScriptInfoFile.open (lastScriptInfoFilePath);
731+ std::stringstream lastScriptInfoBuffer;
732+ lastScriptInfoBuffer << lastScriptInfoFile.rdbuf ();
733+
734+ if (ParseScriptInfo (lastScriptInfoBuffer.str (), lastScriptInfoFromDisk))
735+ lastInfo = &lastScriptInfoFromDisk;
736+ }
737+
738+ if (lastInfo != nullptr )
739+ {
740+ // Check link flags
741+ const Data::ProfilesFlagsOverride* lastLinkFlags =
742+ runcpp2::GetValueFromPlatformMap (lastInfo->OverrideLinkFlags );
743+ const Data::ProfilesFlagsOverride* currentLinkFlags =
744+ runcpp2::GetValueFromPlatformMap (scriptInfo.OverrideLinkFlags );
745+
746+ relinkNeeded = (lastLinkFlags == nullptr ) != (currentLinkFlags == nullptr ) ||
747+ (
748+ lastLinkFlags != nullptr &&
749+ currentLinkFlags != nullptr &&
750+ !lastLinkFlags->Equals (*currentLinkFlags)
751+ );
752+
753+ recompileNeeded = relinkNeeded;
754+
755+ // Check dependencies
756+ if (lastInfo->Dependencies .size () == scriptInfo.Dependencies .size ())
757+ {
758+ for (int i = 0 ; i < scriptInfo.Dependencies .size (); ++i)
759+ {
760+ if (!scriptInfo.Dependencies .at (i).Equals (lastInfo->Dependencies .at (i)))
761+ {
762+ changedDependencies.push_back (scriptInfo.Dependencies .at (i).Name );
763+ recompileNeeded = true ;
764+ }
765+ }
766+ }
767+ else
768+ {
769+ recompileNeeded = true ;
770+ // All dependencies need to be reset if count changed
771+ changedDependencies.clear ();
772+ }
773+
774+ if (!recompileNeeded)
731775 {
732- ssLOG_DEBUG (" Last script info file exists: " << lastScriptInfoFilePath);
733- std::ifstream lastScriptInfoFile;
734- lastScriptInfoFile.open (lastScriptInfoFilePath);
735- std::stringstream lastScriptInfoBuffer;
736- lastScriptInfoBuffer << lastScriptInfoFile.rdbuf ();
737- scriptInfoChanged = lastScriptInfoBuffer.str () != scriptInfo.ToString (" " );
776+ // Other changes that require recompilation
777+ const Data::ProfilesFlagsOverride* lastCompileFlags =
778+ runcpp2::GetValueFromPlatformMap (lastInfo->OverrideCompileFlags );
779+ const Data::ProfilesFlagsOverride* currentCompileFlags =
780+ runcpp2::GetValueFromPlatformMap (scriptInfo.OverrideCompileFlags );
781+
782+ const Data::ProfilesCompilesFiles* lastCompileFiles =
783+ runcpp2::GetValueFromPlatformMap (lastInfo->OtherFilesToBeCompiled );
784+ const Data::ProfilesCompilesFiles* currentCompileFiles =
785+ runcpp2::GetValueFromPlatformMap (scriptInfo.OtherFilesToBeCompiled );
786+
787+ const Data::ProfilesDefines* lastDefines =
788+ runcpp2::GetValueFromPlatformMap (lastInfo->Defines );
789+ const Data::ProfilesDefines* currentDefines =
790+ runcpp2::GetValueFromPlatformMap (scriptInfo.Defines );
791+
792+ recompileNeeded =
793+ (lastCompileFlags == nullptr ) != (currentCompileFlags == nullptr ) ||
794+ (
795+ lastCompileFlags != nullptr &&
796+ currentCompileFlags != nullptr &&
797+ !lastCompileFlags->Equals (*currentCompileFlags)
798+ ) ||
799+ (lastCompileFiles == nullptr ) != (currentCompileFiles == nullptr ) ||
800+ (
801+ lastCompileFiles != nullptr &&
802+ currentCompileFiles != nullptr &&
803+ !lastCompileFiles->Equals (*currentCompileFiles)
804+ ) ||
805+ (lastDefines == nullptr ) != (currentDefines == nullptr ) ||
806+ (
807+ lastDefines != nullptr &&
808+ currentDefines != nullptr &&
809+ !lastDefines->Equals (*currentDefines)
810+ );
738811 }
739812 }
813+ else
814+ recompileNeeded = true ;
740815
741- std::ofstream writeOutputFile (lastScriptInfoFilePath);
742- if (!writeOutputFile)
816+ ssLOG_DEBUG (" recompileNeeded: " << recompileNeeded <<
817+ " , changedDependencies.size(): " << changedDependencies.size () <<
818+ " , relinkNeeded: " << relinkNeeded);
819+
820+ if (recompileNeeded || !changedDependencies.empty () || relinkNeeded)
743821 {
744- ssLOG_ERROR (" Failed to open file: " << lastScriptInfoFilePath);
745- // TODO: Maybee add a pipeline result for this?
746- return PipelineResult::INVALID_BUILD_DIR;
747- }
822+ std::ofstream writeOutputFile (lastScriptInfoFilePath);
823+ if (!writeOutputFile)
824+ {
825+ ssLOG_ERROR (" Failed to open file: " << lastScriptInfoFilePath);
826+ // TODO: Maybee add a pipeline result for this?
827+ return PipelineResult::INVALID_BUILD_DIR;
828+ }
748829
749- writeOutputFile << scriptInfo.ToString (" " );
750-
751- // Pass the current script info out
752- outScriptInfo = scriptInfo;
830+ writeOutputFile << scriptInfo.ToString (" " );
831+
832+ // Pass the current script info out
833+ outScriptInfo = scriptInfo;
834+
835+ ssLOG_DEBUG (" Wrote current script info to " << lastScriptInfoFilePath.string ());
836+ }
753837 }
754838
755839 profileIndex = GetPreferredProfileIndex (absoluteScriptPath,
@@ -787,14 +871,24 @@ runcpp2::StartPipeline( const std::string& scriptPath,
787871 return PipelineResult::DEPENDENCIES_FAILED;
788872 }
789873
790- if (currentOptions.count (CmdOptions::RESET_DEPENDENCIES) > 0 || scriptInfoChanged)
874+ if ( currentOptions.count (CmdOptions::RESET_DEPENDENCIES) > 0 ||
875+ !changedDependencies.empty ())
791876 {
877+ std::string depsToReset = " all" ;
878+ if (!changedDependencies.empty ())
879+ {
880+ depsToReset = changedDependencies[0 ];
881+ for (int i = 1 ; i < changedDependencies.size (); ++i)
882+ depsToReset += " ," + changedDependencies[i];
883+ }
884+
792885 if (!CleanupDependencies (profiles.at (profileIndex),
793886 scriptInfo,
794887 availableDependencies,
795888 dependenciesLocalCopiesPaths,
796889 currentOptions.count (CmdOptions::RESET_DEPENDENCIES) > 0 ?
797- currentOptions.at (CmdOptions::RESET_DEPENDENCIES) : " all" ))
890+ currentOptions.at (CmdOptions::RESET_DEPENDENCIES) :
891+ depsToReset))
798892 {
799893 ssLOG_ERROR (" Failed to cleanup dependencies" );
800894 return PipelineResult::DEPENDENCIES_FAILED;
@@ -858,7 +952,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
858952 std::vector<ghc::filesystem::path> cachedObjectsFiles;
859953 ghc::filesystem::file_time_type finalObjectWriteTime;
860954
861- if (currentOptions.count (runcpp2::CmdOptions::RESET_CACHE) > 0 || scriptInfoChanged )
955+ if (currentOptions.count (runcpp2::CmdOptions::RESET_CACHE) > 0 || recompileNeeded )
862956 sourceHasCache = std::vector<bool >(sourceFiles.size (), false );
863957 else if (!HasCompiledCache ( absoluteScriptPath,
864958 sourceFiles,
@@ -950,7 +1044,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
9501044 scriptName,
9511045 exeExt,
9521046 linkFilesPaths,
953- finalObjectWriteTime))
1047+ finalObjectWriteTime) || relinkNeeded )
9541048 {
9551049 for (int i = 0 ; i < cachedObjectsFiles.size (); ++i)
9561050 linkFilesPaths.push_back (cachedObjectsFiles.at (i));
0 commit comments