Skip to content

Commit 0558898

Browse files
Fixing post build running before copying
1 parent e046f77 commit 0558898

File tree

1 file changed

+51
-29
lines changed

1 file changed

+51
-29
lines changed

Src/runcpp2/runcpp2.cpp

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,39 @@ namespace
505505

506506
return true;
507507
}
508+
509+
bool RunPostBuildCommands( const runcpp2::Data::ScriptInfo& scriptInfo,
510+
const runcpp2::Data::Profile& profile,
511+
const std::string& outputDir)
512+
{
513+
const runcpp2::Data::ProfilesCommands* postBuildCommands =
514+
runcpp2::GetValueFromPlatformMap(scriptInfo.PostBuild);
515+
516+
if(postBuildCommands != nullptr)
517+
{
518+
const std::vector<std::string>* commands =
519+
runcpp2::GetValueFromProfileMap(profile, postBuildCommands->CommandSteps);
520+
if(commands != nullptr)
521+
{
522+
for(const std::string& cmd : *commands)
523+
{
524+
std::string output;
525+
int returnCode = 0;
526+
if(!runcpp2::RunCommandAndGetOutput(cmd, output, returnCode, outputDir))
527+
{
528+
ssLOG_ERROR("PostBuild command failed: " << cmd <<
529+
" with return code " << returnCode);
530+
ssLOG_ERROR("Output: \n" << output);
531+
return false;
532+
}
533+
534+
ssLOG_INFO("PostBuild command ran: \n" << cmd);
535+
ssLOG_INFO("PostBuild command output: \n" << output);
536+
}
537+
}
538+
}
539+
return true;
540+
}
508541
}
509542

510543
void runcpp2::GetDefaultScriptInfo(std::string& scriptInfo)
@@ -726,6 +759,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
726759
return PipelineResult::UNEXPECTED_FAILURE;
727760
}
728761

762+
ssLOG_INFO("Cleanup command ran: \n" << cmd);
729763
ssLOG_INFO("Cleanup command output: \n" << output);
730764
}
731765
}
@@ -790,6 +824,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
790824
return PipelineResult::UNEXPECTED_FAILURE;
791825
}
792826

827+
ssLOG_INFO("Setup command ran: \n" << cmd);
793828
ssLOG_INFO("Setup command output: \n" << output);
794829
}
795830
}
@@ -1127,6 +1162,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
11271162
return PipelineResult::UNEXPECTED_FAILURE;
11281163
}
11291164

1165+
ssLOG_INFO("PreBuild command ran: \n" << cmd);
11301166
ssLOG_INFO("PreBuild command output: \n" << output);
11311167
}
11321168
}
@@ -1175,40 +1211,17 @@ runcpp2::StartPipeline( const std::string& scriptPath,
11751211
return PipelineResult::COMPILE_LINK_FAILED;
11761212
}
11771213
}
1178-
1179-
//Run PostBuild commands after successful compilation
1180-
const Data::ProfilesCommands* postBuildCommands =
1181-
runcpp2::GetValueFromPlatformMap(scriptInfo.PostBuild);
1182-
1183-
if(postBuildCommands != nullptr)
1184-
{
1185-
const std::vector<std::string>* commands =
1186-
runcpp2::GetValueFromProfileMap(profiles.at(profileIndex),
1187-
postBuildCommands->CommandSteps);
1188-
if(commands != nullptr)
1189-
{
1190-
std::string outputDir = buildOutputDir.empty() ? buildDir.string() : buildOutputDir;
1191-
for(const std::string& cmd : *commands)
1192-
{
1193-
std::string output;
1194-
int returnCode = 0;
1195-
if(!runcpp2::RunCommandAndGetOutput(cmd, output, returnCode, outputDir))
1196-
{
1197-
ssLOG_ERROR("PostBuild command failed: " << cmd <<
1198-
" with return code " << returnCode);
1199-
ssLOG_ERROR("Output: \n" << output);
1200-
return PipelineResult::UNEXPECTED_FAILURE;
1201-
}
1202-
1203-
ssLOG_INFO("PostBuild command output: \n" << output);
1204-
}
1205-
}
1206-
}
12071214
}
12081215

12091216
//We are only compiling when watching changes
12101217
if(currentOptions.count(CmdOptions::WATCH) > 0)
1218+
{
1219+
//Run PostBuild commands after successful compilation
1220+
if(!RunPostBuildCommands(scriptInfo, profiles.at(profileIndex), buildDir.string()))
1221+
return PipelineResult::UNEXPECTED_FAILURE;
1222+
12111223
return PipelineResult::SUCCESS;
1224+
}
12121225

12131226
//Run the compiled file at script directory
12141227
{
@@ -1249,12 +1262,17 @@ runcpp2::StartPipeline( const std::string& scriptPath,
12491262

12501263
if(currentOptions.count(CmdOptions::BUILD) == 0)
12511264
{
1265+
//TODO(NOW): Move copying to before post build
12521266
std::vector<std::string> copiedPaths;
12531267
if(!CopyFiles(buildDir, filesToCopyPaths, copiedPaths))
12541268
{
12551269
ssLOG_ERROR("Failed to copy binaries before running the script");
12561270
return PipelineResult::UNEXPECTED_FAILURE;
12571271
}
1272+
1273+
//Run PostBuild commands after successful compilation
1274+
if(!RunPostBuildCommands(scriptInfo, profiles.at(profileIndex), buildDir.string()))
1275+
return PipelineResult::UNEXPECTED_FAILURE;
12581276

12591277
//Prepare run arguments
12601278
std::vector<std::string> finalRunArgs;
@@ -1300,6 +1318,10 @@ runcpp2::StartPipeline( const std::string& scriptPath,
13001318
ssLOG_ERROR("Failed to copy binaries before running the script");
13011319
return PipelineResult::UNEXPECTED_FAILURE;
13021320
}
1321+
1322+
//Run PostBuild commands after successful compilation
1323+
if(!RunPostBuildCommands(scriptInfo, profiles.at(profileIndex), buildOutputDir))
1324+
return PipelineResult::UNEXPECTED_FAILURE;
13031325

13041326
ssLOG_BASE("Build completed. Files copied to " << buildOutputDir);
13051327
return PipelineResult::SUCCESS;

0 commit comments

Comments
 (0)