diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-04-06 10:27:08 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2019-04-06 15:37:12 (GMT) |
commit | 95e72c0157ecd9c603fc541fa7e9fa246b777969 (patch) | |
tree | 9c74c3856b75c7389c6fe89149af090fe14cf9dd /Source | |
parent | f161cfe5a8fa00d6d203885e9c1985ec53d7d625 (diff) | |
download | CMake-95e72c0157ecd9c603fc541fa7e9fa246b777969.zip CMake-95e72c0157ecd9c603fc541fa7e9fa246b777969.tar.gz CMake-95e72c0157ecd9c603fc541fa7e9fa246b777969.tar.bz2 |
Autogen: Make cmQtAutoGenerator::FileSystem Logger free
`cmQtAutoGenerator::FileSystem` used to have a reference to a
`cmQtAutoGenerator::Logger` instances. This was used for utility methods
that automatically generated an error message on demand. Unfortunately this
resulted in double error messages in some places. To fix these and with
the additional purpose of removing the dependency of
`cmQtAutoGenerator::FileSystem` to `cmQtAutoGenerator::Logger`, this patch
removes the `Logger` reference in `cmQtAutoGenerator::FileSystem`.
In the process some silent error conditions gained error messages and
some existing error messages were extended.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmQtAutoGenerator.cxx | 48 | ||||
-rw-r--r-- | Source/cmQtAutoGenerator.h | 21 | ||||
-rw-r--r-- | Source/cmQtAutoGeneratorMocUic.cxx | 39 |
3 files changed, 33 insertions, 75 deletions
diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx index c1e6aab..83a00cf 100644 --- a/Source/cmQtAutoGenerator.cxx +++ b/Source/cmQtAutoGenerator.cxx @@ -261,6 +261,10 @@ bool cmQtAutoGenerator::FileWrite(std::string const& filename, }(); } +cmQtAutoGenerator::FileSystem::FileSystem() = default; + +cmQtAutoGenerator::FileSystem::~FileSystem() = default; + std::string cmQtAutoGenerator::FileSystem::GetRealPath( std::string const& filename) { @@ -380,18 +384,6 @@ bool cmQtAutoGenerator::FileSystem::FileRead(std::string& content, return cmQtAutoGenerator::FileRead(content, filename, error); } -bool cmQtAutoGenerator::FileSystem::FileRead(GenT genType, - std::string& content, - std::string const& filename) -{ - std::string error; - if (!FileRead(content, filename, &error)) { - Log()->ErrorFile(genType, filename, error); - return false; - } - return true; -} - bool cmQtAutoGenerator::FileSystem::FileWrite(std::string const& filename, std::string const& content, std::string* error) @@ -400,18 +392,6 @@ bool cmQtAutoGenerator::FileSystem::FileWrite(std::string const& filename, return cmQtAutoGenerator::FileWrite(filename, content, error); } -bool cmQtAutoGenerator::FileSystem::FileWrite(GenT genType, - std::string const& filename, - std::string const& content) -{ - std::string error; - if (!FileWrite(filename, content, &error)) { - Log()->ErrorFile(genType, filename, error); - return false; - } - return true; -} - bool cmQtAutoGenerator::FileSystem::FileDiffers(std::string const& filename, std::string const& content) { @@ -444,16 +424,6 @@ bool cmQtAutoGenerator::FileSystem::MakeDirectory(std::string const& dirname) return cmSystemTools::MakeDirectory(dirname); } -bool cmQtAutoGenerator::FileSystem::MakeDirectory(GenT genType, - std::string const& dirname) -{ - if (!MakeDirectory(dirname)) { - Log()->ErrorFile(genType, dirname, "Could not create directory"); - return false; - } - return true; -} - bool cmQtAutoGenerator::FileSystem::MakeParentDirectory( std::string const& filename) { @@ -461,16 +431,6 @@ bool cmQtAutoGenerator::FileSystem::MakeParentDirectory( return cmQtAutoGenerator::MakeParentDirectory(filename); } -bool cmQtAutoGenerator::FileSystem::MakeParentDirectory( - GenT genType, std::string const& filename) -{ - if (!MakeParentDirectory(filename)) { - Log()->ErrorFile(genType, filename, "Could not create parent directory"); - return false; - } - return true; -} - int cmQtAutoGenerator::ReadOnlyProcessT::PipeT::init(uv_loop_t* uv_loop, ReadOnlyProcessT* process) { diff --git a/Source/cmQtAutoGenerator.h b/Source/cmQtAutoGenerator.h index 2993946..862b18d 100644 --- a/Source/cmQtAutoGenerator.h +++ b/Source/cmQtAutoGenerator.h @@ -78,13 +78,8 @@ public: class FileSystem { public: - FileSystem(Logger* log) - : Log_(log) - { - } - - /// @brief Logger - Logger* Log() const { return Log_; } + FileSystem(); + ~FileSystem(); // -- Paths /// @brief Wrapper for cmSystemTools::GetRealPath @@ -125,15 +120,9 @@ public: bool FileRead(std::string& content, std::string const& filename, std::string* error = nullptr); - /// @brief Error logging version - bool FileRead(GenT genType, std::string& content, - std::string const& filename); bool FileWrite(std::string const& filename, std::string const& content, std::string* error = nullptr); - /// @brief Error logging version - bool FileWrite(GenT genType, std::string const& filename, - std::string const& content); bool FileDiffers(std::string const& filename, std::string const& content); @@ -142,17 +131,11 @@ public: // -- Directory access bool MakeDirectory(std::string const& dirname); - /// @brief Error logging version - bool MakeDirectory(GenT genType, std::string const& dirname); - bool MakeParentDirectory(std::string const& filename); - /// @brief Error logging version - bool MakeParentDirectory(GenT genType, std::string const& filename); private: std::mutex Mutex_; cmFilePathChecksum FilePathChecksum_; - Logger* Log_; }; /// @brief Return value and output of an external process diff --git a/Source/cmQtAutoGeneratorMocUic.cxx b/Source/cmQtAutoGeneratorMocUic.cxx index 607576f..32e5067 100644 --- a/Source/cmQtAutoGeneratorMocUic.cxx +++ b/Source/cmQtAutoGeneratorMocUic.cxx @@ -638,13 +638,15 @@ void cmQtAutoGeneratorMocUic::JobMocPredefsT::Process(WorkerT& wrk) if (!result.error()) { if (!fileExists || wrk.FileSys().FileDiffers(wrk.Moc().PredefsFileAbs, result.StdOut)) { - if (wrk.FileSys().FileWrite(GenT::MOC, wrk.Moc().PredefsFileAbs, - result.StdOut)) { + std::string error; + if (wrk.FileSys().FileWrite(wrk.Moc().PredefsFileAbs, result.StdOut, + &error)) { // Success } else { std::string emsg = "Writing "; emsg += Quoted(wrk.Moc().PredefsFileRel); - emsg += " failed."; + emsg += " failed. "; + emsg += error; wrk.LogFileError(GenT::MOC, wrk.Moc().PredefsFileAbs, emsg); } } else { @@ -835,7 +837,12 @@ bool cmQtAutoGeneratorMocUic::JobMocT::UpdateRequired(WorkerT& wrk) void cmQtAutoGeneratorMocUic::JobMocT::GenerateMoc(WorkerT& wrk) { // Make sure the parent directory exists - if (wrk.FileSys().MakeParentDirectory(GenT::MOC, BuildFile)) { + if (!wrk.FileSys().MakeParentDirectory(BuildFile)) { + wrk.LogFileError(GenT::MOC, BuildFile, + "Could not create parent directory."); + return; + } + { // Compose moc command std::vector<std::string> cmd; cmd.push_back(wrk.Moc().Executable); @@ -950,7 +957,12 @@ bool cmQtAutoGeneratorMocUic::JobUicT::UpdateRequired(WorkerT& wrk) void cmQtAutoGeneratorMocUic::JobUicT::GenerateUic(WorkerT& wrk) { // Make sure the parent directory exists - if (wrk.FileSys().MakeParentDirectory(GenT::UIC, BuildFile)) { + if (!wrk.FileSys().MakeParentDirectory(BuildFile)) { + wrk.LogFileError(GenT::UIC, BuildFile, + "Could not create parent directory."); + return; + } + { // Compose uic command std::vector<std::string> cmd; cmd.push_back(wrk.Uic().Executable); @@ -1126,8 +1138,7 @@ void cmQtAutoGeneratorMocUic::WorkerT::UVProcessFinished() } cmQtAutoGeneratorMocUic::cmQtAutoGeneratorMocUic() - : FileSys_(&Logger_) - , Base_(&FileSys()) + : Base_(&FileSys()) , Moc_(&FileSys()) { // Precompile regular expressions @@ -1692,9 +1703,10 @@ void cmQtAutoGeneratorMocUic::SettingsFileWrite() SettingAppend("uic", SettingsStringUic_); } // Write settings file - if (!FileSys().FileWrite(GenT::GEN, SettingsFile_, content)) { + std::string error; + if (!FileSys().FileWrite(SettingsFile_, content, &error)) { Log().ErrorFile(GenT::GEN, SettingsFile_, - "Settings file writing failed"); + "Settings file writing failed. " + error); // Remove old settings file to trigger a full rebuild on the next run FileSys().FileRemove(SettingsFile_); RegisterJobError(); @@ -1705,7 +1717,9 @@ void cmQtAutoGeneratorMocUic::SettingsFileWrite() void cmQtAutoGeneratorMocUic::CreateDirectories() { // Create AUTOGEN include directory - if (!FileSys().MakeDirectory(GenT::GEN, Base().AutogenIncludeDir)) { + if (!FileSys().MakeDirectory(Base().AutogenIncludeDir)) { + Log().ErrorFile(GenT::GEN, Base().AutogenIncludeDir, + "Could not create directory."); RegisterJobError(); } } @@ -2004,9 +2018,10 @@ void cmQtAutoGeneratorMocUic::MocGenerateCompilation() if (Log().Verbose()) { Log().Info(GenT::MOC, "Generating MOC compilation " + compAbs); } - if (!FileSys().FileWrite(GenT::MOC, compAbs, content)) { + std::string error; + if (!FileSys().FileWrite(compAbs, content, &error)) { Log().ErrorFile(GenT::MOC, compAbs, - "mocs compilation file writing failed"); + "mocs compilation file writing failed. " + error); RegisterJobError(); return; } |