diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2017-04-22 11:36:35 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2017-04-22 12:01:18 (GMT) |
commit | 65290169f277a5759226929cf457f45610f89d92 (patch) | |
tree | e68f1bcde3beddf8b599c1ae1f6332f20b15fed3 | |
parent | 344a6d8448d16e2d28a318e4809ea0ff2a544c0d (diff) | |
download | CMake-65290169f277a5759226929cf457f45610f89d92.zip CMake-65290169f277a5759226929cf457f45610f89d92.tar.gz CMake-65290169f277a5759226929cf457f45610f89d92.tar.bz2 |
Autogen: Add FileDiffers and FileWrite methods
-rw-r--r-- | Source/cmQtAutoGenerators.cxx | 43 | ||||
-rw-r--r-- | Source/cmQtAutoGenerators.h | 4 |
2 files changed, 47 insertions, 0 deletions
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index a42db11..e907779 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -1856,6 +1856,49 @@ bool cmQtAutoGenerators::MakeParentDirectory(const char* logPrefix, return success; } +bool cmQtAutoGenerators::FileDiffers(const std::string& filename, + const std::string& content) +{ + bool differs = true; + { + std::string oldContents; + if (ReadAll(oldContents, filename)) { + differs = (oldContents != content); + } + } + return differs; +} + +bool cmQtAutoGenerators::FileWrite(const char* logPrefix, + const std::string& filename, + const std::string& content) +{ + std::string error; + // Make sure the parent directory exists + if (this->MakeParentDirectory(logPrefix, filename)) { + cmsys::ofstream outfile; + outfile.open(filename.c_str(), std::ios::trunc); + if (outfile) { + outfile << content; + // Check for write errors + if (!outfile.good()) { + error = logPrefix; + error += ": Error writing "; + error += Quoted(filename); + } + } else { + error = logPrefix; + error = ": Error opening "; + error += Quoted(filename); + } + } + if (!error.empty()) { + this->LogError(error); + return false; + } + return true; +} + /** * @brief Runs a command and returns true on success * @return True on success diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 7419cdc..df43b33 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -143,6 +143,10 @@ private: const char* baseSuffix) const; bool MakeParentDirectory(const char* logPrefix, const std::string& filename) const; + bool FileDiffers(const std::string& filename, const std::string& content); + bool FileWrite(const char* logPrefix, const std::string& filename, + const std::string& content); + bool RunCommand(const std::vector<std::string>& command, std::string& output, bool verbose = true) const; |