Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Include/runcpp2/PlatformUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ namespace runcpp2

std::vector<std::string> GetPlatformNames();

bool RunCommandAndGetOutput(const std::string& command,
std::string& outOutput,
std::string runDirectory = "");

bool RunCommandAndGetOutput(const std::string& command,
std::string& outOutput,
int& outReturnCode,
std::string runDirectory = "");
bool RunCommand(const std::string& command,
const bool& captureOutput,
const std::string& runDirectory,
std::string& outOutput,
int& outReturnCode);

#if defined(_WIN32)
std::string GetWindowsError();
Expand Down
66 changes: 37 additions & 29 deletions Src/runcpp2/CompilingLinking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ namespace

std::string setupOutput;
int setupResult;

if( !runcpp2::RunCommandAndGetOutput( setupStep,
setupOutput,
setupResult,
buildDir.string()) ||
if( !runcpp2::RunCommand( setupStep,
true,
buildDir.string(),
setupOutput,
setupResult) ||
setupResult != 0)
{
ssLOG_ERROR("Setup command \"" << setupStep << "\" failed");
Expand Down Expand Up @@ -375,10 +375,12 @@ namespace

std::string commandOutput;
int resultCode = 0;
if( !runcpp2::RunCommandAndGetOutput( compileCommand,
commandOutput,
resultCode,
buildDir.string()) ||

if( !runcpp2::RunCommand( compileCommand,
true,
buildDir.string(),
commandOutput,
resultCode) ||
resultCode != 0)
{
ssLOG_ERROR("Compile command failed with result " << resultCode);
Expand Down Expand Up @@ -413,10 +415,11 @@ namespace
std::string cleanupOutput;
int cleanupResult;

if( !runcpp2::RunCommandAndGetOutput( cleanupStep,
cleanupOutput,
cleanupResult,
buildDir.string()) ||
if( !runcpp2::RunCommand( cleanupStep,
true,
buildDir.string(),
cleanupOutput,
cleanupResult) ||
cleanupResult != 0)
{
ssLOG_ERROR("Cleanup command \"" << cleanupStep << "\" failed");
Expand Down Expand Up @@ -708,10 +711,11 @@ namespace
std::string setupOutput;
int setupResult;

if( !runcpp2::RunCommandAndGetOutput( setupStep,
setupOutput,
setupResult,
buildDir.string()) ||
if( !runcpp2::RunCommand( setupStep,
true,
buildDir.string(),
setupOutput,
setupResult) ||
setupResult != 0)
{
ssLOG_ERROR("Setup command \"" << setupStep << "\" failed");
Expand Down Expand Up @@ -744,10 +748,12 @@ namespace
ssLOG_INFO("running link command: " << linkCommand << " in " << buildDir.string());
std::string linkOutput;
int resultCode = 0;
if( !runcpp2::RunCommandAndGetOutput( linkCommand,
linkOutput,
resultCode,
buildDir.string()) ||

if( !runcpp2::RunCommand( linkCommand,
true,
buildDir.string(),
linkOutput,
resultCode) ||
resultCode != 0)
{
ssLOG_ERROR("Link command failed with result " << resultCode);
Expand Down Expand Up @@ -775,10 +781,11 @@ namespace
std::string cleanupOutput;
int cleanupResult;

if( !runcpp2::RunCommandAndGetOutput( cleanupStep,
cleanupOutput,
cleanupResult,
buildDir.string()) ||
if( !runcpp2::RunCommand( cleanupStep,
true,
buildDir.string(),
cleanupOutput,
cleanupResult) ||
cleanupResult != 0)
{
ssLOG_ERROR("Cleanup command \"" << cleanupStep << "\" failed");
Expand Down Expand Up @@ -812,10 +819,11 @@ namespace
std::string commandOutput;
int commandResult = 0;

if( !runcpp2::RunCommandAndGetOutput( steps.at(i),
commandOutput,
commandResult,
buildDir.string()) ||
if( !runcpp2::RunCommand( steps.at(i),
true,
buildDir.string(),
commandOutput,
commandResult) ||
commandResult != 0)
{
ssLOG_ERROR("Command \"" << steps.at(i) << "\" failed");
Expand Down
25 changes: 14 additions & 11 deletions Src/runcpp2/DependenciesHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,18 @@ namespace

int returnCode = 0;
std::string output;
if(!runcpp2::RunCommandAndGetOutput(gitCloneCommand,
output,
returnCode,
buildDir.string()))
if(!runcpp2::RunCommand(gitCloneCommand,
false,
buildDir.string(),
output,
returnCode))
{
ssLOG_ERROR("Failed to run git clone with result: " << returnCode);
ssLOG_ERROR("Output: \n" << output);
//ssLOG_ERROR("Output: \n" << output);
return false;
}
else
ssLOG_INFO("Output: \n" << output);
//else
// ssLOG_INFO("Output: \n" << output);
}
else if(mpark::get_if<runcpp2::Data::LocalSource>(&(dependency.Source.Source)))
{
Expand Down Expand Up @@ -257,10 +258,12 @@ namespace

int returnCode = 0;
std::string output;
if(!runcpp2::RunCommandAndGetOutput(commands->at(k),
output,
returnCode,
processedDependencyPath))

if(!runcpp2::RunCommand(commands->at(k),
true,
processedDependencyPath,
output,
returnCode))
{
ssLOG_ERROR("Failed to run command with result: " << returnCode);
ssLOG_ERROR("Output: \n" << output);
Expand Down
6 changes: 4 additions & 2 deletions Src/runcpp2/PipelineSteps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ runcpp2::RunProfileCommands(const Data::ProfilesCommands* commands,
{
std::string output;
int returnCode = 0;
if(!runcpp2::RunCommandAndGetOutput(cmd, output, returnCode, workingDir))

if(!runcpp2::RunCommand(cmd, true, workingDir, output, returnCode))
{
ssLOG_ERROR(commandType << " command failed: " << cmd <<
" with return code " << returnCode);
Expand Down Expand Up @@ -404,7 +405,8 @@ runcpp2::PipelineResult runcpp2::HandleCleanup( const Data::ScriptInfo& scriptIn
{
std::string output;
int returnCode = 0;
if(!runcpp2::RunCommandAndGetOutput(cmd, output, returnCode, scriptDirectory))

if(!runcpp2::RunCommand(cmd, true, scriptDirectory, output, returnCode))
{
ssLOG_ERROR("Cleanup command failed: " << cmd <<
" with return code " << returnCode);
Expand Down
47 changes: 22 additions & 25 deletions Src/runcpp2/PlatformUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,19 @@ std::vector<std::string> runcpp2::GetPlatformNames()
#endif
}

bool runcpp2::RunCommandAndGetOutput( const std::string& command,
std::string& outOutput,
std::string runDirectory)
{
int returnCode;
return RunCommandAndGetOutput(command, outOutput, returnCode, runDirectory);
}

bool runcpp2::RunCommandAndGetOutput( const std::string& command,
std::string& outOutput,
int& outReturnCode,
std::string runDirectory)
bool runcpp2::RunCommand( const std::string& command,
const bool& captureOutput,
const std::string& runDirectory,
std::string& outOutput,
int& outReturnCode)
{
ssLOG_FUNC_DEBUG();
ssLOG_DEBUG("Running: " << command);
System2CommandInfo commandInfo = {};
if(!runDirectory.empty())
commandInfo.RunDirectory = runDirectory.c_str();

commandInfo.RedirectOutput = true;
commandInfo.RedirectOutput = captureOutput;
SYSTEM2_RESULT sys2Result = System2Run(command.c_str(), &commandInfo);

if(sys2Result != SYSTEM2_RESULT_SUCCESS)
Expand All @@ -98,20 +91,23 @@ bool runcpp2::RunCommandAndGetOutput( const std::string& command,
}
outOutput.clear();

do
if(captureOutput)
{
uint32_t byteRead = 0;
outOutput.resize(outOutput.size() + 4096);

sys2Result =
System2ReadFromOutput( &commandInfo,
const_cast<char*>(outOutput.data()) + outOutput.size() - 4096,
4096,
&byteRead);
do
{
uint32_t byteRead = 0;
outOutput.resize(outOutput.size() + 4096);

sys2Result =
System2ReadFromOutput( &commandInfo,
const_cast<char*>(outOutput.data()) + outOutput.size() - 4096,
4096,
&byteRead);

outOutput.resize(outOutput.size() + byteRead);
outOutput.resize(outOutput.size() + byteRead);
}
while(sys2Result == SYSTEM2_RESULT_READ_NOT_FINISHED);
}
while(sys2Result == SYSTEM2_RESULT_READ_NOT_FINISHED);

sys2Result = System2GetCommandReturnValueSync(&commandInfo, &outReturnCode, false);
if(sys2Result != SYSTEM2_RESULT_SUCCESS)
Expand All @@ -120,7 +116,8 @@ bool runcpp2::RunCommandAndGetOutput( const std::string& command,
return false;
}

ssLOG_DEBUG("outOutput: \n" << outOutput.c_str());
if(captureOutput)
ssLOG_DEBUG("outOutput: \n" << outOutput.c_str());

if(outReturnCode != 0)
{
Expand Down
12 changes: 8 additions & 4 deletions Src/runcpp2/ProfileHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace
for(int i = 0; i < cleanupSteps.size(); ++i)
{
std::string output;
if(!runcpp2::RunCommandAndGetOutput(cleanupSteps.at(i), output))
int resultCode;
if(!runcpp2::RunCommand(cleanupSteps.at(i), true, "", output, resultCode))
{
ssLOG_INFO("Failed to run cleanup for " << profile.Name);
return false;
Expand All @@ -53,7 +54,8 @@ namespace
for(int i = 0; i < setupSteps.size(); ++i)
{
std::string output;
if(!runcpp2::RunCommandAndGetOutput(setupSteps.at(i), output))
int resultCode;
if(!runcpp2::RunCommand(setupSteps.at(i), true, "", output, resultCode))
{
ssLOG_INFO("Failed to run setup for " << profile.Name);
runCleanup();
Expand All @@ -77,7 +79,8 @@ namespace
command += *runcpp2::GetValueFromPlatformMap(profile.Compiler.CheckExistence);

std::string output;
if(!runcpp2::RunCommandAndGetOutput(command, output))
int returnCode;
if(!runcpp2::RunCommand(command, true, "", output, returnCode))
{
ssLOG_INFO("Failed to find compiler for profile " << profile.Name);
runCleanup();
Expand All @@ -100,7 +103,8 @@ namespace
command += *runcpp2::GetValueFromPlatformMap(profile.Linker.CheckExistence);

std::string output;
if(!runcpp2::RunCommandAndGetOutput(command, output))
int returnCode;
if(!runcpp2::RunCommand(command, true, "", output, returnCode))
{
ssLOG_INFO("Failed to find linker for profile " << profile.Name);
runCleanup();
Expand Down