@@ -1020,6 +1020,90 @@ runcpp2::ProcessDependencies( Data::ScriptInfo& scriptInfo,
10201020 return PipelineResult::SUCCESS;
10211021}
10221022
1023+ void runcpp2::SeparateDependencyFiles ( const Data::FilesTypesInfo& filesTypes,
1024+ const std::vector<std::string>& gatheredBinariesPaths,
1025+ std::vector<std::string>& outLinkFilesPaths,
1026+ std::vector<std::string>& outFilesToCopyPaths)
1027+ {
1028+ std::unordered_set<std::string> linkExtensions;
1029+
1030+ // Populate the set of link extensions
1031+ if (runcpp2::HasValueFromPlatformMap (filesTypes.StaticLinkFile .Extension ))
1032+ linkExtensions.insert (*runcpp2::GetValueFromPlatformMap (filesTypes.StaticLinkFile .Extension ));
1033+ if (runcpp2::HasValueFromPlatformMap (filesTypes.SharedLinkFile .Extension ))
1034+ linkExtensions.insert (*runcpp2::GetValueFromPlatformMap (filesTypes.SharedLinkFile .Extension ));
1035+ if (runcpp2::HasValueFromPlatformMap (filesTypes.ObjectLinkFile .Extension ))
1036+ linkExtensions.insert (*runcpp2::GetValueFromPlatformMap (filesTypes.ObjectLinkFile .Extension ));
1037+
1038+ // Separate the gathered files from dependencies into files to link and files to copy
1039+ for (int i = 0 ; i < gatheredBinariesPaths.size (); ++i)
1040+ {
1041+ ghc::filesystem::path filePath (gatheredBinariesPaths.at (i));
1042+ std::string extension = runcpp2::GetFileExtensionWithoutVersion (filePath);
1043+
1044+ // Check if the file is a link file based on its extension
1045+ if (linkExtensions.find (extension) != linkExtensions.end ())
1046+ {
1047+ outLinkFilesPaths.push_back (gatheredBinariesPaths.at (i));
1048+
1049+ // Special case when SharedLinkFile and SharedLibraryFile share the same extension
1050+ if ( runcpp2::HasValueFromPlatformMap (filesTypes.SharedLibraryFile .Extension ) &&
1051+ *runcpp2::GetValueFromPlatformMap (filesTypes.SharedLibraryFile
1052+ .Extension ) == extension)
1053+ {
1054+ outFilesToCopyPaths.push_back (gatheredBinariesPaths.at (i));
1055+ }
1056+ }
1057+ else
1058+ outFilesToCopyPaths.push_back (gatheredBinariesPaths.at (i));
1059+ }
1060+
1061+ ssLOG_INFO (" Files to link:" );
1062+ for (int i = 0 ; i < outLinkFilesPaths.size (); ++i)
1063+ ssLOG_INFO (" " << outLinkFilesPaths[i]);
1064+
1065+ ssLOG_INFO (" Files to copy:" );
1066+ for (int i = 0 ; i < outFilesToCopyPaths.size (); ++i)
1067+ ssLOG_INFO (" " << outFilesToCopyPaths[i]);
1068+ }
1069+
1070+ runcpp2::PipelineResult runcpp2::HandlePreBuild ( const Data::ScriptInfo& scriptInfo,
1071+ const Data::Profile& profile,
1072+ const ghc::filesystem::path& buildDir)
1073+ {
1074+ const Data::ProfilesCommands* preBuildCommands =
1075+ runcpp2::GetValueFromPlatformMap (scriptInfo.PreBuild );
1076+
1077+ if (preBuildCommands != nullptr )
1078+ {
1079+ const std::vector<std::string>* commands =
1080+ runcpp2::GetValueFromProfileMap (profile, preBuildCommands->CommandSteps );
1081+ if (commands != nullptr )
1082+ {
1083+ for (const std::string& cmd : *commands)
1084+ {
1085+ std::string output;
1086+ int returnCode = 0 ;
1087+ if (!runcpp2::RunCommandAndGetOutput (cmd,
1088+ output,
1089+ returnCode,
1090+ buildDir.string ()))
1091+ {
1092+ ssLOG_ERROR (" PreBuild command failed: " << cmd <<
1093+ " with return code " << returnCode);
1094+ ssLOG_ERROR (" Output: \n " << output);
1095+ return PipelineResult::UNEXPECTED_FAILURE;
1096+ }
1097+
1098+ ssLOG_INFO (" PreBuild command ran: \n " << cmd);
1099+ ssLOG_INFO (" PreBuild command output: \n " << output);
1100+ }
1101+ }
1102+ }
1103+
1104+ return PipelineResult::SUCCESS;
1105+ }
1106+
10231107runcpp2::PipelineResult runcpp2::StartPipeline ( const std::string& scriptPath,
10241108 const std::vector<Data::Profile>& profiles,
10251109 const std::string& configPreferredProfile,
@@ -1182,58 +1266,10 @@ runcpp2::PipelineResult runcpp2::StartPipeline( const std::string& scriptPath,
11821266 }
11831267
11841268 std::vector<std::string> linkFilesPaths;
1185- std::unordered_set<std::string> linkExtensions;
1186- const Data::FilesTypesInfo& currentFileTypes = profiles.at (profileIndex).FilesTypes ;
1187-
1188- // Populate the set of link extensions
1189- if (runcpp2::HasValueFromPlatformMap (currentFileTypes.StaticLinkFile .Extension ))
1190- {
1191- linkExtensions.insert (*runcpp2::GetValueFromPlatformMap (currentFileTypes.StaticLinkFile
1192- .Extension ));
1193- }
1194- if (runcpp2::HasValueFromPlatformMap (currentFileTypes.SharedLinkFile .Extension ))
1195- {
1196- linkExtensions.insert (*runcpp2::GetValueFromPlatformMap (currentFileTypes.SharedLinkFile
1197- .Extension ));
1198- }
1199- if (runcpp2::HasValueFromPlatformMap (currentFileTypes.ObjectLinkFile .Extension ))
1200- {
1201- linkExtensions.insert (*runcpp2::GetValueFromPlatformMap (currentFileTypes.ObjectLinkFile
1202- .Extension ));
1203- }
1204-
1205- // Separate the gathered files from dependencies into files to link and files to copy
1206- for (int i = 0 ; i < gatheredBinariesPaths.size (); ++i)
1207- {
1208- ghc::filesystem::path filePath (gatheredBinariesPaths.at (i));
1209- std::string extension = runcpp2::GetFileExtensionWithoutVersion (filePath);
1210-
1211- // Check if the file is a link file based on its extension
1212- if (linkExtensions.find (extension) != linkExtensions.end ())
1213- {
1214- linkFilesPaths.push_back (gatheredBinariesPaths.at (i));
1215-
1216- // Special case when SharedLinkFile and SharedLibraryFile share the same extension
1217- if ( runcpp2::HasValueFromPlatformMap (currentFileTypes.SharedLibraryFile .Extension ) &&
1218- *runcpp2::GetValueFromPlatformMap (currentFileTypes .SharedLibraryFile
1219- .Extension ) == extension)
1220- {
1221- filesToCopyPaths.push_back (gatheredBinariesPaths.at (i));
1222- }
1223- }
1224- else
1225- filesToCopyPaths.push_back (gatheredBinariesPaths.at (i));
1226- }
1227-
1228- {
1229- ssLOG_INFO (" Files to link:" );
1230- for (int i = 0 ; i < linkFilesPaths.size (); ++i)
1231- ssLOG_INFO (" " << linkFilesPaths[i]);
1232-
1233- ssLOG_INFO (" Files to copy:" );
1234- for (int i = 0 ; i < filesToCopyPaths.size (); ++i)
1235- ssLOG_INFO (" " << filesToCopyPaths[i]);
1236- }
1269+ SeparateDependencyFiles (profiles.at (profileIndex).FilesTypes ,
1270+ gatheredBinariesPaths,
1271+ linkFilesPaths,
1272+ filesToCopyPaths);
12371273
12381274 std::error_code e;
12391275
@@ -1254,36 +1290,9 @@ runcpp2::PipelineResult runcpp2::StartPipeline( const std::string& scriptPath,
12541290 }
12551291
12561292 // Run PreBuild commands before compilation
1257- const Data::ProfilesCommands* preBuildCommands =
1258- runcpp2::GetValueFromPlatformMap (scriptInfo.PreBuild );
1259-
1260- if (preBuildCommands != nullptr )
1261- {
1262- const std::vector<std::string>* commands =
1263- runcpp2::GetValueFromProfileMap (profiles.at (profileIndex),
1264- preBuildCommands->CommandSteps );
1265- if (commands != nullptr )
1266- {
1267- for (const std::string& cmd : *commands)
1268- {
1269- std::string output;
1270- int returnCode = 0 ;
1271- if (!runcpp2::RunCommandAndGetOutput (cmd,
1272- output,
1273- returnCode,
1274- buildDir.string ()))
1275- {
1276- ssLOG_ERROR (" PreBuild command failed: " << cmd <<
1277- " with return code " << returnCode);
1278- ssLOG_ERROR (" Output: \n " << output);
1279- return PipelineResult::UNEXPECTED_FAILURE;
1280- }
1281-
1282- ssLOG_INFO (" PreBuild command ran: \n " << cmd);
1283- ssLOG_INFO (" PreBuild command output: \n " << output);
1284- }
1285- }
1286- }
1293+ result = HandlePreBuild (scriptInfo, profiles.at (profileIndex), buildDir);
1294+ if (result != PipelineResult::SUCCESS)
1295+ return result;
12871296
12881297 std::string exeExt = " " ;
12891298 #ifdef _WIN32
0 commit comments