From 40bd42dfbcafd572ccd3541f1f84177453c9c255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C4=81vis=20Mos=C4=81ns?= Date: Tue, 1 Nov 2016 20:36:58 +0200 Subject: Add Encoding option for RunChild, RunMakeCommand and RunProcess --- Source/CTest/cmCTestBuildHandler.cxx | 4 ++-- Source/CTest/cmCTestBuildHandler.h | 5 ++++- Source/CTest/cmCTestVC.cxx | 9 +++++---- Source/CTest/cmCTestVC.h | 6 ++++-- Source/cmCTest.cxx | 12 ++++++------ Source/cmCTest.h | 11 ++++++++--- Source/cmExecProgramCommand.cxx | 4 ++-- Source/cmExecProgramCommand.h | 5 ++++- Source/cmProcessTools.cxx | 4 ++-- Source/cmProcessTools.h | 5 ++++- Source/cmSystemTools.cxx | 4 ++-- Source/cmSystemTools.h | 5 ++++- 12 files changed, 47 insertions(+), 27 deletions(-) diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index cd1f879..a455908 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -766,7 +766,7 @@ void cmCTestBuildHandler::LaunchHelper::WriteScrapeMatchers( int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, const char* dir, int timeout, - std::ostream& ofs) + std::ostream& ofs, Encoding encoding) { // First generate the command and arguments std::vector args = cmSystemTools::ParseArguments(command); @@ -810,7 +810,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, char* data; int length; - cmProcessOutput processOutput; + cmProcessOutput processOutput(encoding); std::string strdata; cmCTestOptionalLog( this->CTest, HANDLER_PROGRESS_OUTPUT, " Each symbol represents " diff --git a/Source/CTest/cmCTestBuildHandler.h b/Source/CTest/cmCTestBuildHandler.h index 9c64c10..a2f6112 100644 --- a/Source/CTest/cmCTestBuildHandler.h +++ b/Source/CTest/cmCTestBuildHandler.h @@ -7,6 +7,7 @@ #include "cmCTestGenericHandler.h" +#include #include #include #include @@ -25,6 +26,7 @@ class cmCTestBuildHandler : public cmCTestGenericHandler { public: typedef cmCTestGenericHandler Superclass; + typedef cmProcessOutput::Encoding Encoding; /* * The main entry point for this class @@ -49,7 +51,8 @@ private: //! Run command specialized for make and configure. Returns process status // and retVal is return value or exception. int RunMakeCommand(const char* command, int* retVal, const char* dir, - int timeout, std::ostream& ofs); + int timeout, std::ostream& ofs, + Encoding encoding = cmProcessOutput::Auto); enum { diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx index 7a2fa69..444c43d 100644 --- a/Source/CTest/cmCTestVC.cxx +++ b/Source/CTest/cmCTestVC.cxx @@ -76,7 +76,8 @@ bool cmCTestVC::InitialCheckout(const char* command) } bool cmCTestVC::RunChild(char const* const* cmd, OutputParser* out, - OutputParser* err, const char* workDir) + OutputParser* err, const char* workDir, + Encoding encoding) { this->Log << this->ComputeCommandLine(cmd) << "\n"; @@ -84,7 +85,7 @@ bool cmCTestVC::RunChild(char const* const* cmd, OutputParser* out, cmsysProcess_SetCommand(cp, cmd); workDir = workDir ? workDir : this->SourceDirectory.c_str(); cmsysProcess_SetWorkingDirectory(cp, workDir); - this->RunProcess(cp, out, err); + this->RunProcess(cp, out, err, encoding); int result = cmsysProcess_GetExitValue(cp); cmsysProcess_Delete(cp); return result == 0; @@ -102,7 +103,7 @@ std::string cmCTestVC::ComputeCommandLine(char const* const* cmd) } bool cmCTestVC::RunUpdateCommand(char const* const* cmd, OutputParser* out, - OutputParser* err) + OutputParser* err, Encoding encoding) { // Report the command line. this->UpdateCommandLine = this->ComputeCommandLine(cmd); @@ -112,7 +113,7 @@ bool cmCTestVC::RunUpdateCommand(char const* const* cmd, OutputParser* out, } // Run the command. - return this->RunChild(cmd, out, err); + return this->RunChild(cmd, out, err, CM_NULLPTR, encoding); } std::string cmCTestVC::GetNightlyTime() diff --git a/Source/CTest/cmCTestVC.h b/Source/CTest/cmCTestVC.h index 4f2bba0..dd8b973 100644 --- a/Source/CTest/cmCTestVC.h +++ b/Source/CTest/cmCTestVC.h @@ -116,11 +116,13 @@ protected: /** Run a command line and send output to given parsers. */ bool RunChild(char const* const* cmd, OutputParser* out, OutputParser* err, - const char* workDir = CM_NULLPTR); + const char* workDir = CM_NULLPTR, + Encoding encoding = cmProcessOutput::Auto); /** Run VC update command line and send output to given parsers. */ bool RunUpdateCommand(char const* const* cmd, OutputParser* out, - OutputParser* err = CM_NULLPTR); + OutputParser* err = CM_NULLPTR, + Encoding encoding = cmProcessOutput::Auto); /** Write xml element for one file. */ void WriteXMLEntry(cmXMLWriter& xml, std::string const& path, diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index bf4507e..1527b30 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -961,7 +961,7 @@ int cmCTest::GetTestModelFromString(const char* str) int cmCTest::RunMakeCommand(const char* command, std::string& output, int* retVal, const char* dir, int timeout, - std::ostream& ofs) + std::ostream& ofs, Encoding encoding) { // First generate the command and arguments std::vector args = cmSystemTools::ParseArguments(command); @@ -1000,7 +1000,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, char* data; int length; - cmProcessOutput processOutput; + cmProcessOutput processOutput(encoding); std::string strdata; cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Each . represents " << tick_len << " bytes of output" << std::endl @@ -1075,7 +1075,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, int cmCTest::RunTest(std::vector argv, std::string* output, int* retVal, std::ostream* log, double testTimeOut, - std::vector* environment) + std::vector* environment, Encoding encoding) { bool modifyEnv = (environment && !environment->empty()); @@ -1170,7 +1170,7 @@ int cmCTest::RunTest(std::vector argv, std::string* output, char* data; int length; - cmProcessOutput processOutput; + cmProcessOutput processOutput(encoding); std::string strdata; while (cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) { processOutput.DecodeText(data, length, strdata); @@ -2523,7 +2523,7 @@ bool cmCTest::SetCTestConfigurationFromCMakeVariable( bool cmCTest::RunCommand(const char* command, std::string* stdOut, std::string* stdErr, int* retVal, const char* dir, - double timeout) + double timeout, Encoding encoding) { std::vector args = cmSystemTools::ParseArguments(command); @@ -2554,7 +2554,7 @@ bool cmCTest::RunCommand(const char* command, std::string* stdOut, std::vector tempError; char* data; int length; - cmProcessOutput processOutput; + cmProcessOutput processOutput(encoding); std::string strdata; int res; bool done = false; diff --git a/Source/cmCTest.h b/Source/cmCTest.h index e5b4728..4436327 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -48,6 +49,7 @@ class cmCTest friend class cmCTestMultiProcessHandler; public: + typedef cmProcessOutput::Encoding Encoding; /** Enumerate parts of the testing and submission process. */ enum Part { @@ -267,7 +269,8 @@ public: */ bool RunCommand(const char* command, std::string* stdOut, std::string* stdErr, int* retVal = CM_NULLPTR, - const char* dir = CM_NULLPTR, double timeout = 0.0); + const char* dir = CM_NULLPTR, double timeout = 0.0, + Encoding encoding = cmProcessOutput::Auto); /** * Clean/make safe for xml the given value such that it may be used as @@ -286,7 +289,8 @@ public: * and retVal is return value or exception. */ int RunMakeCommand(const char* command, std::string& output, int* retVal, - const char* dir, int timeout, std::ostream& ofs); + const char* dir, int timeout, std::ostream& ofs, + Encoding encoding = cmProcessOutput::Auto); /** Return the current tag */ std::string GetCurrentTag(); @@ -333,7 +337,8 @@ public: */ int RunTest(std::vector args, std::string* output, int* retVal, std::ostream* logfile, double testTimeOut, - std::vector* environment); + std::vector* environment, + Encoding encoding = cmProcessOutput::Auto); /** * Execute handler and return its result. If the handler fails, it returns diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx index 6c271a2..6a7292d 100644 --- a/Source/cmExecProgramCommand.cxx +++ b/Source/cmExecProgramCommand.cxx @@ -117,7 +117,7 @@ bool cmExecProgramCommand::InitialPass(std::vector const& args, bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, int& retVal, const char* dir, - bool verbose) + bool verbose, Encoding encoding) { if (cmSystemTools::GetRunCommandOutput()) { verbose = false; @@ -215,7 +215,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, int length; char* data; int p; - cmProcessOutput processOutput; + cmProcessOutput processOutput(encoding); std::string strdata; while ((p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) { if (p == cmsysProcess_Pipe_STDOUT || p == cmsysProcess_Pipe_STDERR) { diff --git a/Source/cmExecProgramCommand.h b/Source/cmExecProgramCommand.h index 7cdf777..58e948e 100644 --- a/Source/cmExecProgramCommand.h +++ b/Source/cmExecProgramCommand.h @@ -8,6 +8,7 @@ #include #include "cmCommand.h" +#include "cmProcessOutput.h" class cmExecutionStatus; @@ -21,6 +22,7 @@ class cmExecutionStatus; class cmExecProgramCommand : public cmCommand { public: + typedef cmProcessOutput::Encoding Encoding; /** * This is a virtual constructor for the command. */ @@ -46,7 +48,8 @@ public: private: static bool RunCommand(const char* command, std::string& output, int& retVal, const char* directory = CM_NULLPTR, - bool verbose = true); + bool verbose = true, + Encoding encoding = cmProcessOutput::Auto); }; #endif diff --git a/Source/cmProcessTools.cxx b/Source/cmProcessTools.cxx index 652f1d6..b756650 100644 --- a/Source/cmProcessTools.cxx +++ b/Source/cmProcessTools.cxx @@ -7,13 +7,13 @@ #include void cmProcessTools::RunProcess(struct cmsysProcess_s* cp, OutputParser* out, - OutputParser* err) + OutputParser* err, Encoding encoding) { cmsysProcess_Execute(cp); char* data = CM_NULLPTR; int length = 0; int p; - cmProcessOutput processOutput; + cmProcessOutput processOutput(encoding); std::string strdata; while ((out || err) && (p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) { diff --git a/Source/cmProcessTools.h b/Source/cmProcessTools.h index e5a3fe9..df131b9 100644 --- a/Source/cmProcessTools.h +++ b/Source/cmProcessTools.h @@ -3,6 +3,7 @@ #ifndef cmProcessTools_h #define cmProcessTools_h +#include "cmProcessOutput.h" #include #include @@ -16,6 +17,7 @@ class cmProcessTools { public: + typedef cmProcessOutput::Encoding Encoding; /** Abstract interface for process output parsers. */ class OutputParser { @@ -79,7 +81,8 @@ public: /** Run a process and send output to given parsers. */ static void RunProcess(struct cmsysProcess_s* cp, OutputParser* out, - OutputParser* err = CM_NULLPTR); + OutputParser* err = CM_NULLPTR, + Encoding encoding = cmProcessOutput::Auto); }; #endif diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index b656070..029594f 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -574,7 +574,7 @@ bool cmSystemTools::RunSingleCommand(std::vector const& command, std::string* captureStdOut, std::string* captureStdErr, int* retVal, const char* dir, OutputOption outputflag, - double timeout) + double timeout, Encoding encoding) { std::vector argv; for (std::vector::const_iterator a = command.begin(); @@ -610,7 +610,7 @@ bool cmSystemTools::RunSingleCommand(std::vector const& command, char* data; int length; int pipe; - cmProcessOutput processOutput; + cmProcessOutput processOutput(encoding); std::string strdata; if (outputflag != OUTPUT_PASSTHROUGH && (captureStdOut || captureStdErr || outputflag != OUTPUT_NONE)) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 0801f26..10e8280 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -5,6 +5,7 @@ #include // IWYU pragma: keep +#include #include #include #include @@ -29,6 +30,7 @@ class cmSystemTools : public cmsys::SystemTools { public: typedef cmsys::SystemTools Superclass; + typedef cmProcessOutput::Encoding Encoding; /** Expand out any arguments in the vector that have ; separated * strings into multiple arguments. A new vector is created @@ -239,7 +241,8 @@ public: int* retVal = CM_NULLPTR, const char* dir = CM_NULLPTR, OutputOption outputflag = OUTPUT_MERGE, - double timeout = 0.0); + double timeout = 0.0, + Encoding encoding = cmProcessOutput::Auto); static std::string PrintSingleCommand(std::vector const&); -- cgit v0.12