summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-01-20 13:33:41 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2016-01-20 13:33:41 (GMT)
commitd8bced813cdd0c3eb7c2e3e150f513da04ded513 (patch)
tree1ea979feee77f26ae39b11d0df4571733c441de4
parentae5f30b36a58bffbc0954906eb2e60961f57caca (diff)
parent1040e690c6c99979f8edf2a121de6d835be96dbe (diff)
downloadCMake-d8bced813cdd0c3eb7c2e3e150f513da04ded513.zip
CMake-d8bced813cdd0c3eb7c2e3e150f513da04ded513.tar.gz
CMake-d8bced813cdd0c3eb7c2e3e150f513da04ded513.tar.bz2
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
-rw-r--r--Source/cmGlobalGenerator.cxx2
-rw-r--r--Source/cmSystemTools.cxx75
-rw-r--r--Source/cmSystemTools.h4
-rw-r--r--Source/cmcmd.cxx7
4 files changed, 37 insertions, 51 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 2126c71..c50bf66 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -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?
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index a89a6e0b..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
@@ -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 (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);
}
}
}
}
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;
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 9cafbec..f511ae4 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -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,
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index fb7b1f5..8dd902b 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -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;
}