diff options
author | Brad King <brad.king@kitware.com> | 2019-01-22 14:32:47 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-01-22 14:32:58 (GMT) |
commit | cb7fbf1dbbcc88fc7701250db5c3ccdf0ab7396e (patch) | |
tree | 6f19fc14a53cc58f2d2234077ee596934a60afe6 | |
parent | acaf9801d004dc77d8abbb09b2ce3a88fd182322 (diff) | |
parent | 3132ea801c2466773309edda82387025f903fc12 (diff) | |
download | CMake-cb7fbf1dbbcc88fc7701250db5c3ccdf0ab7396e.zip CMake-cb7fbf1dbbcc88fc7701250db5c3ccdf0ab7396e.tar.gz CMake-cb7fbf1dbbcc88fc7701250db5c3ccdf0ab7396e.tar.bz2 |
Merge topic 'stdout-string'
3132ea801c cmSystemTools: Stdout(),Stderr() accept std::string argument
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2829
-rw-r--r-- | Source/cmCTest.cxx | 4 | ||||
-rw-r--r-- | Source/cmDepends.cxx | 8 | ||||
-rw-r--r-- | Source/cmExecProgramCommand.cxx | 6 | ||||
-rw-r--r-- | Source/cmExecuteProcessCommand.cxx | 8 | ||||
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator3.cxx | 6 | ||||
-rw-r--r-- | Source/cmQtAutoGenerator.cxx | 8 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 36 | ||||
-rw-r--r-- | Source/cmSystemTools.h | 6 | ||||
-rw-r--r-- | Source/cmake.cxx | 16 |
9 files changed, 42 insertions, 56 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 5f71520..4e2f275 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2807,13 +2807,13 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args, if ((res == cmsysProcess_Pipe_STDOUT || res == cmsysProcess_Pipe_STDERR) && this->ExtraVerbose) { processOutput.DecodeText(data, length, strdata); - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } } if (this->ExtraVerbose) { processOutput.DecodeText(std::string(), strdata); if (!strdata.empty()) { - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } } diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index fae3d9b..3b3783a 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -88,7 +88,7 @@ void cmDepends::Clear(const std::string& file) if (this->Verbose) { std::ostringstream msg; msg << "Clearing dependencies in \"" << file << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } // Write an empty dependency file. @@ -171,7 +171,7 @@ bool cmDepends::CheckDependencies( std::ostringstream msg; msg << "Dependee \"" << dependee << "\" does not exist for depender \"" << depender << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } } else { if (dependerExists) { @@ -188,7 +188,7 @@ bool cmDepends::CheckDependencies( std::ostringstream msg; msg << "Dependee \"" << dependee << "\" is newer than depender \"" << depender << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } } } else { @@ -207,7 +207,7 @@ bool cmDepends::CheckDependencies( msg << "Dependee \"" << dependee << "\" is newer than depends file \"" << internalDependsFileName << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } } } diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx index ea4cd40..49d9841 100644 --- a/Source/cmExecProgramCommand.cxx +++ b/Source/cmExecProgramCommand.cxx @@ -221,7 +221,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, if (p == cmsysProcess_Pipe_STDOUT || p == cmsysProcess_Pipe_STDERR) { if (verbose) { processOutput.DecodeText(data, length, strdata); - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } output.append(data, length); } @@ -230,7 +230,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, if (verbose) { processOutput.DecodeText(std::string(), strdata); if (!strdata.empty()) { - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } } @@ -270,7 +270,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, } msg += "\n"; if (verbose) { - cmSystemTools::Stdout(msg.c_str()); + cmSystemTools::Stdout(msg); } output += msg; #else diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 8de012a..e29047f 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -249,14 +249,14 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args, if (p == cmsysProcess_Pipe_STDOUT && !output_quiet) { if (output_variable.empty()) { processOutput.DecodeText(data, length, strdata, 1); - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } else { cmExecuteProcessCommandAppend(tempOutput, data, length); } } else if (p == cmsysProcess_Pipe_STDERR && !error_quiet) { if (error_variable.empty()) { processOutput.DecodeText(data, length, strdata, 2); - cmSystemTools::Stderr(strdata.c_str(), strdata.size()); + cmSystemTools::Stderr(strdata); } else { cmExecuteProcessCommandAppend(tempError, data, length); } @@ -265,13 +265,13 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args, if (!output_quiet && output_variable.empty()) { processOutput.DecodeText(std::string(), strdata, 1); if (!strdata.empty()) { - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } } if (!error_quiet && error_variable.empty()) { processOutput.DecodeText(std::string(), strdata, 2); if (!strdata.empty()) { - cmSystemTools::Stderr(strdata.c_str(), strdata.size()); + cmSystemTools::Stderr(strdata); } } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 59c787e..5b9d108 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1286,7 +1286,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo, std::ostringstream msg; msg << "Dependee \"" << tgtInfo << "\" is newer than depender \"" << internalDependFile << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } needRescanDependInfo = true; } @@ -1307,7 +1307,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo, std::ostringstream msg; msg << "Dependee \"" << dirInfoFile << "\" is newer than depender \"" << internalDependFile << "\"." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } needRescanDirInfo = true; } @@ -1485,7 +1485,7 @@ void cmLocalUnixMakefileGenerator3::CheckMultipleOutputs(bool verbose) msg << "Deleting primary custom command output \"" << dependee << "\" because another output \"" << depender << "\" does not exist." << std::endl; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } cmSystemTools::RemoveFile(dependee); } diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx index c5d5d7c..e2d7deb 100644 --- a/Source/cmQtAutoGenerator.cxx +++ b/Source/cmQtAutoGenerator.cxx @@ -54,7 +54,7 @@ void cmQtAutoGenerator::Logger::Info(GeneratorT genType, } { std::lock_guard<std::mutex> lock(Mutex_); - cmSystemTools::Stdout(msg.c_str(), msg.size()); + cmSystemTools::Stdout(msg); } } @@ -78,7 +78,7 @@ void cmQtAutoGenerator::Logger::Warning(GeneratorT genType, msg.push_back('\n'); { std::lock_guard<std::mutex> lock(Mutex_); - cmSystemTools::Stdout(msg.c_str(), msg.size()); + cmSystemTools::Stdout(msg); } } @@ -107,7 +107,7 @@ void cmQtAutoGenerator::Logger::Error(GeneratorT genType, msg.push_back('\n'); { std::lock_guard<std::mutex> lock(Mutex_); - cmSystemTools::Stderr(msg.c_str(), msg.size()); + cmSystemTools::Stderr(msg); } } @@ -149,7 +149,7 @@ void cmQtAutoGenerator::Logger::ErrorCommand( msg.push_back('\n'); { std::lock_guard<std::mutex> lock(Mutex_); - cmSystemTools::Stderr(msg.c_str(), msg.size()); + cmSystemTools::Stderr(msg); } } diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 71a9cb4..9abc5f3 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -302,33 +302,21 @@ void cmSystemTools::SetStderrCallback(OutputCallback f, void* clientData) s_StderrCallbackClientData = clientData; } -void cmSystemTools::Stdout(const char* s) -{ - cmSystemTools::Stdout(s, strlen(s)); -} - -void cmSystemTools::Stderr(const char* s) -{ - cmSystemTools::Stderr(s, strlen(s)); -} - -void cmSystemTools::Stderr(const char* s, size_t length) +void cmSystemTools::Stderr(const std::string& s) { if (s_StderrCallback) { - (*s_StderrCallback)(s, length, s_StderrCallbackClientData); + (*s_StderrCallback)(s.c_str(), s.length(), s_StderrCallbackClientData); } else { - std::cerr.write(s, length); - std::cerr.flush(); + std::cerr << s << std::flush; } } -void cmSystemTools::Stdout(const char* s, size_t length) +void cmSystemTools::Stdout(const std::string& s) { if (s_StdoutCallback) { - (*s_StdoutCallback)(s, length, s_StdoutCallbackClientData); + (*s_StdoutCallback)(s.c_str(), s.length(), s_StdoutCallbackClientData); } else { - std::cout.write(s, length); - std::cout.flush(); + std::cout << s << std::flush; } } @@ -792,7 +780,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command, if (pipe == cmsysProcess_Pipe_STDOUT) { if (outputflag != OUTPUT_NONE) { processOutput.DecodeText(data, length, strdata, 1); - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } if (captureStdOut) { tempStdOut.insert(tempStdOut.end(), data, data + length); @@ -800,7 +788,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command, } else if (pipe == cmsysProcess_Pipe_STDERR) { if (outputflag != OUTPUT_NONE) { processOutput.DecodeText(data, length, strdata, 2); - cmSystemTools::Stderr(strdata.c_str(), strdata.size()); + cmSystemTools::Stderr(strdata); } if (captureStdErr) { tempStdErr.insert(tempStdErr.end(), data, data + length); @@ -811,11 +799,11 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command, if (outputflag != OUTPUT_NONE) { processOutput.DecodeText(std::string(), strdata, 1); if (!strdata.empty()) { - cmSystemTools::Stdout(strdata.c_str(), strdata.size()); + cmSystemTools::Stdout(strdata); } processOutput.DecodeText(std::string(), strdata, 2); if (!strdata.empty()) { - cmSystemTools::Stderr(strdata.c_str(), strdata.size()); + cmSystemTools::Stderr(strdata); } } } @@ -1899,13 +1887,13 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract) if (verbose) { if (extract) { cmSystemTools::Stdout("x "); - cmSystemTools::Stdout(cm_archive_entry_pathname(entry).c_str()); + cmSystemTools::Stdout(cm_archive_entry_pathname(entry)); } else { list_item_verbose(stdout, entry); } cmSystemTools::Stdout("\n"); } else if (!extract) { - cmSystemTools::Stdout(cm_archive_entry_pathname(entry).c_str()); + cmSystemTools::Stdout(cm_archive_entry_pathname(entry)); cmSystemTools::Stdout("\n"); } if (extract) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 489811d..7a209c6 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -79,13 +79,11 @@ public: typedef void (*OutputCallback)(const char*, size_t length, void*); ///! Send a string to stdout - static void Stdout(const char* s); - static void Stdout(const char* s, size_t length); + static void Stdout(const std::string& s); static void SetStdoutCallback(OutputCallback, void* clientData = nullptr); ///! Send a string to stderr - static void Stderr(const char* s); - static void Stderr(const char* s, size_t length); + static void Stderr(const std::string& s); static void SetStderrCallback(OutputCallback, void* clientData = nullptr); typedef bool (*InterruptCallback)(void*); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 42d2384..b44c325 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2014,7 +2014,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake no build system arguments\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2025,7 +2025,7 @@ int cmake::CheckBuildSystem() std::ostringstream msg; msg << "Re-run cmake missing file: " << this->CheckBuildSystemArgument << "\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2045,7 +2045,7 @@ int cmake::CheckBuildSystem() std::ostringstream msg; msg << "Re-run cmake error reading : " << this->CheckBuildSystemArgument << "\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } // There was an error reading the file. Just rerun. return 1; @@ -2079,7 +2079,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake, missing byproduct: " << p << "\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2100,7 +2100,7 @@ int cmake::CheckBuildSystem() std::ostringstream msg; msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS " "or CMAKE_MAKEFILE_OUTPUTS :\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2119,7 +2119,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake: build system dependency is missing\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2139,7 +2139,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake: build system output is missing\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } @@ -2155,7 +2155,7 @@ int cmake::CheckBuildSystem() std::ostringstream msg; msg << "Re-run cmake file: " << out_oldest << " older than: " << dep_newest << "\n"; - cmSystemTools::Stdout(msg.str().c_str()); + cmSystemTools::Stdout(msg.str()); } return 1; } |