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:
commit
d8bced813c
@ -1850,7 +1850,7 @@ int cmGlobalGenerator::Build(
|
|||||||
!makeCommand.empty() && cmSystemTools::LowerCase(
|
!makeCommand.empty() && cmSystemTools::LowerCase(
|
||||||
cmSystemTools::GetFilenameName(makeCommand[0])) == "vcexpress.exe")
|
cmSystemTools::GetFilenameName(makeCommand[0])) == "vcexpress.exe")
|
||||||
{
|
{
|
||||||
outputflag = cmSystemTools::OUTPUT_NORMAL;
|
outputflag = cmSystemTools::OUTPUT_FORWARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// should we do a clean first?
|
// should we do a clean first?
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
#ifdef __QNX__
|
#ifdef __QNX__
|
||||||
# include <malloc.h> /* for malloc/free on QNX */
|
# include <malloc.h> /* for malloc/free on QNX */
|
||||||
#endif
|
#endif
|
||||||
@ -660,14 +661,6 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
|
|||||||
argv.push_back(a->c_str());
|
argv.push_back(a->c_str());
|
||||||
}
|
}
|
||||||
argv.push_back(0);
|
argv.push_back(0);
|
||||||
if ( captureStdOut )
|
|
||||||
{
|
|
||||||
*captureStdOut = "";
|
|
||||||
}
|
|
||||||
if (captureStdErr && captureStdErr != captureStdOut)
|
|
||||||
{
|
|
||||||
*captureStdErr = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
cmsysProcess* cp = cmsysProcess_New();
|
cmsysProcess* cp = cmsysProcess_New();
|
||||||
cmsysProcess_SetCommand(cp, &*argv.begin());
|
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_STDOUT, 1);
|
||||||
cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 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_SetTimeout(cp, timeout);
|
||||||
cmsysProcess_Execute(cp);
|
cmsysProcess_Execute(cp);
|
||||||
@ -695,8 +697,6 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
|
|||||||
(captureStdOut || captureStdErr || outputflag != OUTPUT_NONE))
|
(captureStdOut || captureStdErr || outputflag != OUTPUT_NONE))
|
||||||
{
|
{
|
||||||
while((pipe = cmsysProcess_WaitForData(cp, &data, &length, 0)) > 0)
|
while((pipe = cmsysProcess_WaitForData(cp, &data, &length, 0)) > 0)
|
||||||
{
|
|
||||||
if(captureStdOut || captureStdErr || outputflag != OUTPUT_NONE)
|
|
||||||
{
|
{
|
||||||
// Translate NULL characters in the output into valid text.
|
// Translate NULL characters in the output into valid text.
|
||||||
// Visual Studio 7 puts these characters in the output of its
|
// Visual Studio 7 puts these characters in the output of its
|
||||||
@ -708,53 +708,40 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
|
|||||||
data[i] = ' ';
|
data[i] = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(pipe == cmsysProcess_Pipe_STDOUT ||
|
if (pipe == cmsysProcess_Pipe_STDOUT)
|
||||||
(pipe == cmsysProcess_Pipe_STDERR &&
|
|
||||||
captureStdOut == captureStdErr))
|
|
||||||
{
|
{
|
||||||
|
if (outputflag != OUTPUT_NONE)
|
||||||
|
{
|
||||||
|
cmSystemTools::Stdout(data, length);
|
||||||
|
}
|
||||||
if (captureStdOut)
|
if (captureStdOut)
|
||||||
{
|
{
|
||||||
tempStdOut.insert(tempStdOut.end(), data, data+length);
|
tempStdOut.insert(tempStdOut.end(), data, data+length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(pipe == cmsysProcess_Pipe_STDERR)
|
else if (pipe == cmsysProcess_Pipe_STDERR)
|
||||||
{
|
{
|
||||||
if (captureStdErr)
|
if (outputflag != OUTPUT_NONE)
|
||||||
{
|
|
||||||
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);
|
cmSystemTools::Stderr(data, length);
|
||||||
}
|
}
|
||||||
else if(pipe == cmsysProcess_Pipe_STDOUT)
|
if (captureStdErr)
|
||||||
{
|
{
|
||||||
cmSystemTools::Stdout(data, length);
|
tempStdErr.insert(tempStdErr.end(), data, data+length);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmsysProcess_WaitForExit(cp, 0);
|
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 &&
|
if (captureStdErr)
|
||||||
tempStdErr.begin() != tempStdErr.end())
|
|
||||||
{
|
{
|
||||||
captureStdErr->append(&*tempStdErr.begin(), tempStdErr.size());
|
captureStdErr->assign(tempStdErr.begin(), tempStdErr.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -203,7 +203,7 @@ public:
|
|||||||
* Output is controlled with outputflag. If outputflag is OUTPUT_NONE, no
|
* Output is controlled with outputflag. If outputflag is OUTPUT_NONE, no
|
||||||
* user-viewable output from the program being run will be generated.
|
* user-viewable output from the program being run will be generated.
|
||||||
* OUTPUT_MERGE is the legacy behaviour where stdout and stderr are merged
|
* 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.
|
* it was received. OUTPUT_PASSTHROUGH passes through the original handles.
|
||||||
*
|
*
|
||||||
* If timeout is specified, the command will be terminated after
|
* If timeout is specified, the command will be terminated after
|
||||||
@ -223,7 +223,7 @@ public:
|
|||||||
{
|
{
|
||||||
OUTPUT_NONE = 0,
|
OUTPUT_NONE = 0,
|
||||||
OUTPUT_MERGE,
|
OUTPUT_MERGE,
|
||||||
OUTPUT_NORMAL,
|
OUTPUT_FORWARD,
|
||||||
OUTPUT_PASSTHROUGH
|
OUTPUT_PASSTHROUGH
|
||||||
};
|
};
|
||||||
static bool RunSingleCommand(const char* command,
|
static bool RunSingleCommand(const char* command,
|
||||||
|
@ -361,11 +361,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now run the real compiler command and return its result value.
|
// 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))
|
cmSystemTools::OUTPUT_PASSTHROUGH))
|
||||||
{
|
{
|
||||||
std::cerr << "Error running '" << orig_cmd[0] << "': "
|
std::cerr << "Error running '" << orig_cmd[0] << "'\n";
|
||||||
<< stdErr << "\n";
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -621,7 +620,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
|||||||
int retval = 0;
|
int retval = 0;
|
||||||
int timeout = 0;
|
int timeout = 0;
|
||||||
if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, 0, &retval,
|
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;
|
return retval;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user