mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-23 14:48:19 -05:00
Autogen: Add FileDiffers and FileWrite methods
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user