Merge topic 'cleanup-RunSingleCommand'

1040e690 cmSystemTools: Teach RunSingleCommand to merge child pipes when possible
ce3b713b cmSystemTools: Simplify RunSingleCommand output string construction
dc039cc0 cmSystemTools: Drop redundant condition in RunSingleCommand
ffa2a8c9 cmSystemTools: Rename OUTPUT_NORMAL to OUTPUT_FORWARD to clarify its purpose
92e9bb21 cmcmd.cxx: Remove unused code in __run_iwyu implementation
fb1526f5 cmake: Change `-E chdir` to pass through stdout/stderr directly
This commit is contained in:
Brad King 2016-01-20 08:33:41 -05:00 committed by CMake Topic Stage
commit d8bced813c
4 changed files with 37 additions and 51 deletions

View File

@ -1850,7 +1850,7 @@ int cmGlobalGenerator::Build(
!makeCommand.empty() && cmSystemTools::LowerCase(
cmSystemTools::GetFilenameName(makeCommand[0])) == "vcexpress.exe")
{
outputflag = cmSystemTools::OUTPUT_NORMAL;
outputflag = cmSystemTools::OUTPUT_FORWARD;
}
// should we do a clean first?

View File

@ -17,6 +17,7 @@
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#ifdef __QNX__
# include <malloc.h> /* for malloc/free on QNX */
#endif
@ -660,14 +661,6 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
argv.push_back(a->c_str());
}
argv.push_back(0);
if ( captureStdOut )
{
*captureStdOut = "";
}
if (captureStdErr && captureStdErr != captureStdOut)
{
*captureStdErr = "";
}
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
@ -681,7 +674,16 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
{
cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
captureStdOut = 0;
captureStdErr = 0;
}
else if (outputflag == OUTPUT_MERGE ||
(captureStdErr && captureStdErr == captureStdOut))
{
cmsysProcess_SetOption(cp, cmsysProcess_Option_MergeOutput, 1);
captureStdErr = 0;
}
assert(!captureStdErr || captureStdErr != captureStdOut);
cmsysProcess_SetTimeout(cp, timeout);
cmsysProcess_Execute(cp);
@ -696,65 +698,50 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
{
while((pipe = cmsysProcess_WaitForData(cp, &data, &length, 0)) > 0)
{
if(captureStdOut || captureStdErr || outputflag != OUTPUT_NONE)
// Translate NULL characters in the output into valid text.
// Visual Studio 7 puts these characters in the output of its
// build process.
for(int i=0; i < length; ++i)
{
// Translate NULL characters in the output into valid text.
// Visual Studio 7 puts these characters in the output of its
// build process.
for(int i=0; i < length; ++i)
if(data[i] == '\0')
{
if(data[i] == '\0')
{
data[i] = ' ';
}
data[i] = ' ';
}
}
if(pipe == cmsysProcess_Pipe_STDOUT ||
(pipe == cmsysProcess_Pipe_STDERR &&
captureStdOut == captureStdErr))
if (pipe == cmsysProcess_Pipe_STDOUT)
{
if (outputflag != OUTPUT_NONE)
{
cmSystemTools::Stdout(data, length);
}
if (captureStdOut)
{
tempStdOut.insert(tempStdOut.end(), data, data+length);
}
}
else if(pipe == cmsysProcess_Pipe_STDERR)
else if (pipe == cmsysProcess_Pipe_STDERR)
{
if (outputflag != OUTPUT_NONE)
{
cmSystemTools::Stderr(data, length);
}
if (captureStdErr)
{
tempStdErr.insert(tempStdErr.end(), data, data+length);
}
}
if(outputflag != OUTPUT_NONE)
{
if(outputflag == OUTPUT_MERGE)
{
cmSystemTools::Stdout(data, length);
}
else
{
if(pipe == cmsysProcess_Pipe_STDERR)
{
cmSystemTools::Stderr(data, length);
}
else if(pipe == cmsysProcess_Pipe_STDOUT)
{
cmSystemTools::Stdout(data, length);
}
}
}
}
}
cmsysProcess_WaitForExit(cp, 0);
if ( captureStdOut && tempStdOut.begin() != tempStdOut.end())
if (captureStdOut)
{
captureStdOut->append(&*tempStdOut.begin(), tempStdOut.size());
captureStdOut->assign(tempStdOut.begin(), tempStdOut.end());
}
if ( captureStdErr && captureStdErr != captureStdOut &&
tempStdErr.begin() != tempStdErr.end())
if (captureStdErr)
{
captureStdErr->append(&*tempStdErr.begin(), tempStdErr.size());
captureStdErr->assign(tempStdErr.begin(), tempStdErr.end());
}
bool result = true;

View File

@ -203,7 +203,7 @@ public:
* Output is controlled with outputflag. If outputflag is OUTPUT_NONE, no
* user-viewable output from the program being run will be generated.
* OUTPUT_MERGE is the legacy behaviour where stdout and stderr are merged
* into stdout. OUTPUT_NORMAL passes through the output to stdout/stderr as
* into stdout. OUTPUT_FORWARD copies the output to stdout/stderr as
* it was received. OUTPUT_PASSTHROUGH passes through the original handles.
*
* If timeout is specified, the command will be terminated after
@ -223,7 +223,7 @@ public:
{
OUTPUT_NONE = 0,
OUTPUT_MERGE,
OUTPUT_NORMAL,
OUTPUT_FORWARD,
OUTPUT_PASSTHROUGH
};
static bool RunSingleCommand(const char* command,

View File

@ -361,11 +361,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
}
// Now run the real compiler command and return its result value.
if(!cmSystemTools::RunSingleCommand(orig_cmd, 0, &stdErr, &ret, 0,
if(!cmSystemTools::RunSingleCommand(orig_cmd, 0, 0, &ret, 0,
cmSystemTools::OUTPUT_PASSTHROUGH))
{
std::cerr << "Error running '" << orig_cmd[0] << "': "
<< stdErr << "\n";
std::cerr << "Error running '" << orig_cmd[0] << "'\n";
return 1;
}
return ret;
@ -621,7 +620,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
int retval = 0;
int timeout = 0;
if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, 0, &retval,
directory.c_str(), cmSystemTools::OUTPUT_NORMAL, timeout) )
directory.c_str(), cmSystemTools::OUTPUT_PASSTHROUGH, timeout) )
{
return retval;
}