summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-01-14 21:11:23 (GMT)
committerBrad King <brad.king@kitware.com>2016-01-19 20:55:05 (GMT)
commit1040e690c6c99979f8edf2a121de6d835be96dbe (patch)
tree8c03c082a0f19212f2a634edf3ffe0551cacd59f /Source
parentce3b713baa1c899ae7739c192040e24445368a0a (diff)
downloadCMake-1040e690c6c99979f8edf2a121de6d835be96dbe.zip
CMake-1040e690c6c99979f8edf2a121de6d835be96dbe.tar.gz
CMake-1040e690c6c99979f8edf2a121de6d835be96dbe.tar.bz2
cmSystemTools: Teach RunSingleCommand to merge child pipes when possible
Audit the code to make sure there are no callers that use OUTPUT_MERGE with separate capture strings. Then change RunSingleCommand to implement output merging by giving the child process a single pipe for both its stdout and stderr descriptors. This will more cleanly merge the content on atomic write boundaries in the child instead of on arbitrary buffering boundaries in the parent.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmSystemTools.cxx44
1 files changed, 21 insertions, 23 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 3a730b2..3ba7287 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -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
@@ -673,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);
@@ -699,38 +709,26 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
}
}
- if(pipe == cmsysProcess_Pipe_STDOUT ||
- (pipe == cmsysProcess_Pipe_STDERR &&
- captureStdOut == captureStdErr))
+ if (pipe == cmsysProcess_Pipe_STDOUT)
{
- if (captureStdOut)
+ if (outputflag != OUTPUT_NONE)
{
- tempStdOut.insert(tempStdOut.end(), data, data+length);
+ cmSystemTools::Stdout(data, length);
}
- }
- else if(pipe == cmsysProcess_Pipe_STDERR)
- {
- if (captureStdErr)
+ if (captureStdOut)
{
- tempStdErr.insert(tempStdErr.end(), data, data+length);
+ tempStdOut.insert(tempStdOut.end(), data, data+length);
}
}
- if(outputflag != OUTPUT_NONE)
+ else if (pipe == cmsysProcess_Pipe_STDERR)
{
- if(outputflag == OUTPUT_MERGE)
+ if (outputflag != OUTPUT_NONE)
{
- cmSystemTools::Stdout(data, length);
+ cmSystemTools::Stderr(data, length);
}
- else
+ if (captureStdErr)
{
- if(pipe == cmsysProcess_Pipe_STDERR)
- {
- cmSystemTools::Stderr(data, length);
- }
- else if(pipe == cmsysProcess_Pipe_STDOUT)
- {
- cmSystemTools::Stdout(data, length);
- }
+ tempStdErr.insert(tempStdErr.end(), data, data+length);
}
}
}
@@ -741,7 +739,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string>const& command,
{
captureStdOut->assign(tempStdOut.begin(), tempStdOut.end());
}
- if (captureStdErr && captureStdErr != captureStdOut)
+ if (captureStdErr)
{
captureStdErr->assign(tempStdErr.begin(), tempStdErr.end());
}