RunSingleCommand: Add a OUTPUT_NORMAL flag.

OUTPUT_NORMAL does no processing of the output streams, it just passes
them through the same streams as they were received on.
This commit is contained in:
Johan Björk 2011-07-26 09:36:40 +02:00 committed by Brad King
parent 856a9e499f
commit 642f10066a
5 changed files with 40 additions and 8 deletions

View File

@ -247,6 +247,12 @@ void cmSystemTools::Stdout(const char* s)
}
}
void cmSystemTools::Stderr(const char* s, int length)
{
std::cerr.write(s, length);
std::cerr.flush();
}
void cmSystemTools::Stdout(const char* s, int length)
{
if(s_StdoutCallback)
@ -629,9 +635,23 @@ bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command,
tempOutput.insert(tempOutput.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);
}
}
}
}
}

View File

@ -75,6 +75,9 @@ public:
typedef void (*StdoutCallback)(const char*, int length, void*);
static void SetStdoutCallback(StdoutCallback, void* clientData=0);
///! Send a string to stderr. Stdout callbacks will not be invoced.
static void Stderr(const char* s, int length);
///! Return true if there was an error at any point.
static bool GetErrorOccuredFlag()
{
@ -196,7 +199,8 @@ 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.
* into stdout. OUTPUT_NORMAL passes through the output to stdout/stderr as
* it was received.
*
* If timeout is specified, the command will be terminated after
* timeout expires. Timeout is specified in seconds.
@ -214,7 +218,8 @@ public:
enum OutputOption
{
OUTPUT_NONE = 0,
OUTPUT_MERGE
OUTPUT_MERGE,
OUTPUT_NORMAL
};
static bool RunSingleCommand(const char* command, std::string* output = 0,
int* retVal = 0, const char* dir = 0,

View File

@ -4296,7 +4296,8 @@ int cmake::Build(const std::string& dir,
const std::string& target,
const std::string& config,
const std::vector<std::string>& nativeOptions,
bool clean)
bool clean,
cmSystemTools::OutputOption outputflag)
{
if(!cmSystemTools::FileIsDirectory(dir.c_str()))
{
@ -4338,8 +4339,7 @@ int cmake::Build(const std::string& dir,
projName.c_str(), target.c_str(),
&output,
makeProgram.c_str(),
config.c_str(), clean, false, 0,
cmSystemTools::OUTPUT_MERGE,
config.c_str(), clean, false, 0, outputflag,
0, nativeOptions);
}

View File

@ -364,7 +364,8 @@ class cmake
const std::string& target,
const std::string& config,
const std::vector<std::string>& nativeOptions,
bool clean);
bool clean,
cmSystemTools::OutputOption outputflag);
void UnwatchUnusedCli(const char* var);
void WatchUnusedCli(const char* var);

View File

@ -62,6 +62,7 @@ static const char * cmDocumentationDescription[][3] =
" --config <cfg> = For multi-configuration tools, choose <cfg>.\n" \
" --clean-first = Build target 'clean' first, then build.\n" \
" (To clean only, use --target 'clean'.)\n" \
" --use-stderr = Don't merge stdout/stderr.\n" \
" -- = Pass remaining options to the native tool.\n"
//----------------------------------------------------------------------------
@ -568,6 +569,7 @@ static int do_build(int ac, char** av)
std::string dir;
std::vector<std::string> nativeOptions;
bool clean = false;
cmSystemTools::OutputOption outputflag = cmSystemTools::OUTPUT_MERGE;
enum Doing { DoingNone, DoingDir, DoingTarget, DoingConfig, DoingNative};
Doing doing = DoingDir;
@ -590,6 +592,10 @@ static int do_build(int ac, char** av)
clean = true;
doing = DoingNone;
}
else if(strcmp(av[i], "--use-stderr") == 0)
{
outputflag = cmSystemTools::OUTPUT_NORMAL;
}
else if(strcmp(av[i], "--") == 0)
{
doing = DoingNative;
@ -635,6 +641,6 @@ static int do_build(int ac, char** av)
}
cmake cm;
return cm.Build(dir, target, config, nativeOptions, clean);
return cm.Build(dir, target, config, nativeOptions, clean, outputflag);
#endif
}