@@ -1104,15 +1104,87 @@ runcpp2::PipelineResult runcpp2::HandlePreBuild( const Data::ScriptInfo& scri
11041104 return PipelineResult::SUCCESS;
11051105}
11061106
1107- runcpp2::PipelineResult runcpp2::StartPipeline ( const std::string& scriptPath,
1108- const std::vector<Data::Profile>& profiles,
1109- const std::string& configPreferredProfile,
1110- const std::unordered_map<CmdOptions, std::string> currentOptions,
1111- const std::vector<std::string>& runArgs,
1112- const Data::ScriptInfo* lastScriptInfo,
1113- Data::ScriptInfo& outScriptInfo,
1114- const std::string& buildOutputDir,
1115- int & returnStatus)
1107+ runcpp2::PipelineResult
1108+ runcpp2::RunCompiledOutput ( const ghc::filesystem::path& target,
1109+ const ghc::filesystem::path& absoluteScriptPath,
1110+ const Data::ScriptInfo& scriptInfo,
1111+ const std::vector<std::string>& runArgs,
1112+ const std::unordered_map<CmdOptions, std::string>& currentOptions,
1113+ int & returnStatus)
1114+ {
1115+ // Prepare run arguments
1116+ std::vector<std::string> finalRunArgs;
1117+ finalRunArgs.push_back (target.string ());
1118+ if (scriptInfo.PassScriptPath )
1119+ finalRunArgs.push_back (absoluteScriptPath);
1120+
1121+ // Add user provided arguments
1122+ for (size_t i = 0 ; i < runArgs.size (); ++i)
1123+ finalRunArgs.push_back (runArgs[i]);
1124+
1125+ if (currentOptions.count (CmdOptions::EXECUTABLE) > 0 )
1126+ {
1127+ // Running the script with modified args
1128+ if (!RunCompiledScript (target, absoluteScriptPath, finalRunArgs, returnStatus))
1129+ {
1130+ ssLOG_ERROR (" Failed to run script" );
1131+ return PipelineResult::RUN_SCRIPT_FAILED;
1132+ }
1133+ }
1134+ else
1135+ {
1136+ // Load the shared library and run it with modified args
1137+ if (!RunCompiledSharedLib (absoluteScriptPath, target, finalRunArgs, returnStatus))
1138+ {
1139+ ssLOG_ERROR (" Failed to run script" );
1140+ return PipelineResult::RUN_SCRIPT_FAILED;
1141+ }
1142+ }
1143+
1144+ return PipelineResult::SUCCESS;
1145+ }
1146+
1147+ runcpp2::PipelineResult
1148+ runcpp2::HandleBuildOutput ( const ghc::filesystem::path& target,
1149+ const std::vector<std::string>& filesToCopyPaths,
1150+ const Data::ScriptInfo& scriptInfo,
1151+ const Data::Profile& profile,
1152+ const std::string& buildOutputDir,
1153+ const std::unordered_map<CmdOptions, std::string>& currentOptions)
1154+ {
1155+ // Copy the output file
1156+ std::vector<std::string> filesToCopy = filesToCopyPaths;
1157+ filesToCopy.push_back (target);
1158+
1159+ std::vector<std::string> copiedPaths;
1160+ if (!CopyFiles (buildOutputDir, filesToCopy, copiedPaths))
1161+ {
1162+ ssLOG_ERROR (" Failed to copy binaries before running the script" );
1163+ return PipelineResult::UNEXPECTED_FAILURE;
1164+ }
1165+
1166+ // Run PostBuild commands after successful compilation
1167+ if (!RunPostBuildCommands (scriptInfo, profile, buildOutputDir))
1168+ return PipelineResult::UNEXPECTED_FAILURE;
1169+
1170+ // Don't output anything here if we are just watching
1171+ if (currentOptions.count (CmdOptions::WATCH) > 0 )
1172+ return PipelineResult::SUCCESS;
1173+
1174+ ssLOG_BASE (" Build completed. Files copied to " << buildOutputDir);
1175+ return PipelineResult::SUCCESS;
1176+ }
1177+
1178+ runcpp2::PipelineResult
1179+ runcpp2::StartPipeline ( const std::string& scriptPath,
1180+ const std::vector<Data::Profile>& profiles,
1181+ const std::string& configPreferredProfile,
1182+ const std::unordered_map<CmdOptions, std::string> currentOptions,
1183+ const std::vector<std::string>& runArgs,
1184+ const Data::ScriptInfo* lastScriptInfo,
1185+ Data::ScriptInfo& outScriptInfo,
1186+ const std::string& buildOutputDir,
1187+ int & returnStatus)
11161188{
11171189 INTERNAL_RUNCPP2_SAFE_START ();
11181190 ssLOG_FUNC_DEBUG ();
@@ -1403,62 +1475,21 @@ runcpp2::PipelineResult runcpp2::StartPipeline( const std::string& scriptPath,
14031475 return PipelineResult::SUCCESS;
14041476
14051477 ssLOG_INFO (" Running script..." );
1406-
1407- // Prepare run arguments
1408- std::vector<std::string> finalRunArgs;
1409- finalRunArgs.push_back (target.string ());
1410- if (scriptInfo.PassScriptPath )
1411- finalRunArgs.push_back (absoluteScriptPath);
1412-
1413- // Add user provided arguments
1414- for (size_t i = 0 ; i < runArgs.size (); ++i)
1415- finalRunArgs.push_back (runArgs[i]);
1416-
1417- if (currentOptions.count (CmdOptions::EXECUTABLE) > 0 )
1418- {
1419- // Running the script with modified args
1420- if (!RunCompiledScript (target, absoluteScriptPath, finalRunArgs, returnStatus))
1421- {
1422- ssLOG_ERROR (" Failed to run script" );
1423- return PipelineResult::RUN_SCRIPT_FAILED;
1424- }
1425-
1426- return PipelineResult::SUCCESS;
1427- }
1428- // Load the shared library and run it with modified args
1429- else
1430- {
1431- if (!RunCompiledSharedLib (absoluteScriptPath, target, finalRunArgs, returnStatus))
1432- {
1433- ssLOG_ERROR (" Failed to run script" );
1434- return PipelineResult::RUN_SCRIPT_FAILED;
1435- }
1436-
1437- return PipelineResult::SUCCESS;
1438- }
1478+ return RunCompiledOutput ( target,
1479+ absoluteScriptPath,
1480+ scriptInfo,
1481+ runArgs,
1482+ currentOptions,
1483+ returnStatus);
14391484 }
14401485 else
14411486 {
1442- // Copy the output file
1443- filesToCopyPaths.push_back (target);
1444-
1445- std::vector<std::string> copiedPaths;
1446- if (!CopyFiles (buildOutputDir, filesToCopyPaths, copiedPaths))
1447- {
1448- ssLOG_ERROR (" Failed to copy binaries before running the script" );
1449- return PipelineResult::UNEXPECTED_FAILURE;
1450- }
1451-
1452- // Run PostBuild commands after successful compilation
1453- if (!RunPostBuildCommands (scriptInfo, profiles.at (profileIndex), buildOutputDir))
1454- return PipelineResult::UNEXPECTED_FAILURE;
1455-
1456- // Don't output anything here if we are just watching
1457- if (currentOptions.count (CmdOptions::WATCH) > 0 )
1458- return PipelineResult::SUCCESS;
1459-
1460- ssLOG_BASE (" Build completed. Files copied to " << buildOutputDir);
1461- return PipelineResult::SUCCESS;
1487+ return HandleBuildOutput ( target,
1488+ filesToCopyPaths,
1489+ scriptInfo,
1490+ profiles.at (profileIndex),
1491+ buildOutputDir,
1492+ currentOptions);
14621493 }
14631494 }
14641495
0 commit comments