Skip to content

Commit bcde32a

Browse files
Extracting ProcessDependencies
1 parent 2d94de6 commit bcde32a

File tree

2 files changed

+120
-85
lines changed

2 files changed

+120
-85
lines changed

Include/runcpp2/runcpp2.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ namespace runcpp2
9999
bool& outRelinkNeeded,
100100
std::vector<std::string>& outChangedDependencies);
101101

102+
PipelineResult
103+
ProcessDependencies(Data::ScriptInfo& scriptInfo,
104+
const Data::Profile& profile,
105+
const ghc::filesystem::path& absoluteScriptPath,
106+
const ghc::filesystem::path& buildDir,
107+
const std::unordered_map<CmdOptions, std::string>& currentOptions,
108+
const std::vector<std::string>& changedDependencies,
109+
std::vector<Data::DependencyInfo*>& outAvailableDependencies,
110+
std::vector<std::string>& outGatheredBinariesPaths);
111+
102112
PipelineResult StartPipeline( const std::string& scriptPath,
103113
const std::vector<Data::Profile>& profiles,
104114
const std::string& configPreferredProfile,

Src/runcpp2/runcpp2.cpp

Lines changed: 110 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,105 @@ runcpp2::CheckScriptInfoChanges(const ghc::filesystem::path& buildDir,
921921
return PipelineResult::SUCCESS;
922922
}
923923

924+
runcpp2::PipelineResult
925+
runcpp2::ProcessDependencies( Data::ScriptInfo& scriptInfo,
926+
const Data::Profile& profile,
927+
const ghc::filesystem::path& absoluteScriptPath,
928+
const ghc::filesystem::path& buildDir,
929+
const std::unordered_map<CmdOptions, std::string>& currentOptions,
930+
const std::vector<std::string>& changedDependencies,
931+
std::vector<Data::DependencyInfo*>& outAvailableDependencies,
932+
std::vector<std::string>& outGatheredBinariesPaths)
933+
{
934+
for(int i = 0; i < scriptInfo.Dependencies.size(); ++i)
935+
{
936+
if(IsDependencyAvailableForThisPlatform(scriptInfo.Dependencies.at(i)))
937+
outAvailableDependencies.push_back(&scriptInfo.Dependencies.at(i));
938+
}
939+
940+
std::vector<std::string> dependenciesLocalCopiesPaths;
941+
std::vector<std::string> dependenciesSourcePaths;
942+
if(!GetDependenciesPaths( outAvailableDependencies,
943+
dependenciesLocalCopiesPaths,
944+
dependenciesSourcePaths,
945+
absoluteScriptPath,
946+
buildDir))
947+
{
948+
ssLOG_ERROR("Failed to get dependencies paths");
949+
return PipelineResult::DEPENDENCIES_FAILED;
950+
}
951+
952+
if(currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0 || !changedDependencies.empty())
953+
{
954+
if(currentOptions.count(CmdOptions::BUILD_SOURCE_ONLY) > 0)
955+
{
956+
ssLOG_ERROR("Dependencies settings have changed or being reset explicitly.");
957+
ssLOG_ERROR("Cannot just build source files only without building dependencies");
958+
return PipelineResult::INVALID_OPTION;
959+
}
960+
961+
std::string depsToReset = "all";
962+
if(!changedDependencies.empty())
963+
{
964+
depsToReset = changedDependencies[0];
965+
for(int i = 1; i < changedDependencies.size(); ++i)
966+
depsToReset += "," + changedDependencies[i];
967+
}
968+
969+
if(!CleanupDependencies(profile,
970+
scriptInfo,
971+
outAvailableDependencies,
972+
dependenciesLocalCopiesPaths,
973+
currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0 ?
974+
currentOptions.at(CmdOptions::RESET_DEPENDENCIES) :
975+
depsToReset))
976+
{
977+
ssLOG_ERROR("Failed to cleanup dependencies");
978+
return PipelineResult::DEPENDENCIES_FAILED;
979+
}
980+
}
981+
982+
if(currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0)
983+
{
984+
ssLOG_LINE("Removed script dependencies");
985+
return PipelineResult::SUCCESS;
986+
}
987+
988+
if(!SetupDependenciesIfNeeded( profile,
989+
buildDir,
990+
scriptInfo,
991+
outAvailableDependencies,
992+
dependenciesLocalCopiesPaths,
993+
dependenciesSourcePaths))
994+
{
995+
ssLOG_ERROR("Failed to setup script dependencies");
996+
return PipelineResult::DEPENDENCIES_FAILED;
997+
}
998+
999+
if(currentOptions.count(CmdOptions::BUILD_SOURCE_ONLY) == 0)
1000+
{
1001+
if(!BuildDependencies( profile,
1002+
scriptInfo,
1003+
outAvailableDependencies,
1004+
dependenciesLocalCopiesPaths))
1005+
{
1006+
ssLOG_ERROR("Failed to build script dependencies");
1007+
return PipelineResult::DEPENDENCIES_FAILED;
1008+
}
1009+
}
1010+
1011+
if(!GatherDependenciesBinaries( outAvailableDependencies,
1012+
dependenciesLocalCopiesPaths,
1013+
profile,
1014+
outGatheredBinariesPaths))
1015+
{
1016+
ssLOG_ERROR("Failed to gather dependencies binaries");
1017+
return PipelineResult::DEPENDENCIES_FAILED;
1018+
}
1019+
1020+
return PipelineResult::SUCCESS;
1021+
}
1022+
9241023
runcpp2::PipelineResult runcpp2::StartPipeline( const std::string& scriptPath,
9251024
const std::vector<Data::Profile>& profiles,
9261025
const std::string& configPreferredProfile,
@@ -1038,95 +1137,21 @@ runcpp2::PipelineResult runcpp2::StartPipeline( const std::string& scriptPath,
10381137

10391138
//Process Dependencies
10401139
std::vector<Data::DependencyInfo*> availableDependencies;
1041-
{
1042-
for(int i = 0; i < scriptInfo.Dependencies.size(); ++i)
1043-
{
1044-
if(IsDependencyAvailableForThisPlatform(scriptInfo.Dependencies.at(i)))
1045-
availableDependencies.push_back(&scriptInfo.Dependencies.at(i));
1046-
}
1047-
1048-
std::vector<std::string> dependenciesLocalCopiesPaths;
1049-
std::vector<std::string> dependenciesSourcePaths;
1050-
if(!GetDependenciesPaths( availableDependencies,
1051-
dependenciesLocalCopiesPaths,
1052-
dependenciesSourcePaths,
1140+
result = ProcessDependencies( scriptInfo,
1141+
profiles.at(profileIndex),
10531142
absoluteScriptPath,
1054-
buildDir))
1055-
{
1056-
ssLOG_ERROR("Failed to get dependencies paths");
1057-
return PipelineResult::DEPENDENCIES_FAILED;
1058-
}
1059-
1060-
if( currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0 ||
1061-
!changedDependencies.empty())
1062-
{
1063-
if(currentOptions.count(CmdOptions::BUILD_SOURCE_ONLY) > 0)
1064-
{
1065-
ssLOG_ERROR("Dependencies settings have changed or being reset explicitly.");
1066-
ssLOG_ERROR("Cannot just build source files only without building dependencies");
1067-
return PipelineResult::INVALID_OPTION;
1068-
}
1069-
1070-
std::string depsToReset = "all";
1071-
if(!changedDependencies.empty())
1072-
{
1073-
depsToReset = changedDependencies[0];
1074-
for(int i = 1; i < changedDependencies.size(); ++i)
1075-
depsToReset += "," + changedDependencies[i];
1076-
}
1077-
1078-
if(!CleanupDependencies(profiles.at(profileIndex),
1079-
scriptInfo,
1143+
buildDir,
1144+
currentOptions,
1145+
changedDependencies,
10801146
availableDependencies,
1081-
dependenciesLocalCopiesPaths,
1082-
currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0 ?
1083-
currentOptions.at(CmdOptions::RESET_DEPENDENCIES) :
1084-
depsToReset))
1085-
{
1086-
ssLOG_ERROR("Failed to cleanup dependencies");
1087-
return PipelineResult::DEPENDENCIES_FAILED;
1088-
}
1089-
}
1090-
1091-
if(currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0)
1092-
{
1093-
ssLOG_LINE("Removed script dependencies");
1094-
return PipelineResult::SUCCESS;
1095-
}
1147+
gatheredBinariesPaths);
10961148

1097-
if(!SetupDependenciesIfNeeded( profiles.at(profileIndex),
1098-
buildDir,
1099-
scriptInfo,
1100-
availableDependencies,
1101-
dependenciesLocalCopiesPaths,
1102-
dependenciesSourcePaths))
1103-
{
1104-
ssLOG_ERROR("Failed to setup script dependencies");
1105-
return PipelineResult::DEPENDENCIES_FAILED;
1106-
}
1107-
1108-
if(currentOptions.count(CmdOptions::BUILD_SOURCE_ONLY) == 0)
1109-
{
1110-
if(!BuildDependencies( profiles.at(profileIndex),
1111-
scriptInfo,
1112-
availableDependencies,
1113-
dependenciesLocalCopiesPaths))
1114-
{
1115-
ssLOG_ERROR("Failed to build script dependencies");
1116-
return PipelineResult::DEPENDENCIES_FAILED;
1117-
}
1118-
}
1119-
1120-
if(!GatherDependenciesBinaries( availableDependencies,
1121-
dependenciesLocalCopiesPaths,
1122-
profiles.at(profileIndex),
1123-
gatheredBinariesPaths))
1124-
{
1125-
ssLOG_ERROR("Failed to gather dependencies binaries");
1126-
return PipelineResult::DEPENDENCIES_FAILED;
1127-
}
1128-
}
1149+
if(result != PipelineResult::SUCCESS)
1150+
return result;
11291151

1152+
if(currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0)
1153+
return PipelineResult::SUCCESS;
1154+
11301155
//Get all the files we are trying to compile
11311156
std::vector<ghc::filesystem::path> sourceFiles;
11321157
if(!GatherSourceFiles( absoluteScriptPath,

0 commit comments

Comments
 (0)