From ba97c741c8fa8ccb598c4bf2e91b4417892ab057 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 5 May 2022 15:51:11 +0200 Subject: [PATCH] CMake: Replace parseCMakeCacheDotTxt() function ... by direct use of CMakeConfig::fromFile(). It was only duplicating checks that are done on the user side already. Change-Id: Iaf5e89c924c2b0a9080db9fe160970bbf6e33154 Reviewed-by: Reviewed-by: Cristian Adam --- .../cmakebuildconfiguration.cpp | 4 ++-- .../cmakeprojectmanager/cmakebuildsystem.cpp | 18 ++---------------- .../cmakeprojectmanager/cmakebuildsystem.h | 4 ---- .../cmakeprojectmanager/cmakeconfigitem.cpp | 1 - .../cmakeprojectimporter.cpp | 2 +- 5 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index fc2ee0f4ecf..1f0857e76e6 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -1665,7 +1665,7 @@ QString CMakeBuildSystem::cmakeBuildType() const QString cmakeBuildType = buildConfiguration()->aspect()->value(); const Utils::FilePath cmakeCacheTxt = buildConfiguration()->buildDirectory().pathAppended("CMakeCache.txt"); - const bool hasCMakeCache = QFile::exists(cmakeCacheTxt.toString()); + const bool hasCMakeCache = cmakeCacheTxt.exists(); CMakeConfig config; if (cmakeBuildType == "Unknown") { @@ -1673,7 +1673,7 @@ QString CMakeBuildSystem::cmakeBuildType() const // that doesn't have the "CMake.Build.Type" aspect saved if (hasCMakeCache) { QString errorMessage; - config = CMakeBuildSystem::parseCMakeCacheDotTxt(cmakeCacheTxt, &errorMessage); + config = CMakeConfig::fromFile(cmakeCacheTxt, &errorMessage); } else { config = initialCMakeConfiguration(); } diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index c6c68514d85..7331c912b7d 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -830,14 +830,14 @@ void CMakeBuildSystem::wireUpConnections() qCDebug(cmakeBuildSystemLog) << "Requesting parse due to build directory change"; const BuildDirParameters parameters(this); const FilePath cmakeCacheTxt = parameters.buildDirectory.pathAppended("CMakeCache.txt"); - const bool hasCMakeCache = QFile::exists(cmakeCacheTxt.toString()); + const bool hasCMakeCache = cmakeCacheTxt.exists(); const auto options = ReparseParameters( hasCMakeCache ? REPARSE_DEFAULT : (REPARSE_FORCE_INITIAL_CONFIGURATION | REPARSE_FORCE_CMAKE_RUN)); if (hasCMakeCache) { QString errorMessage; - const CMakeConfig config = CMakeBuildSystem::parseCMakeCacheDotTxt(cmakeCacheTxt, &errorMessage); + const CMakeConfig config = CMakeConfig::fromFile(cmakeCacheTxt, &errorMessage); if (!config.isEmpty() && errorMessage.isEmpty()) { QString cmakeBuildTypeName = config.stringValueOf("CMAKE_BUILD_TYPE"); setCMakeBuildType(cmakeBuildTypeName, true); @@ -1039,20 +1039,6 @@ const QList &CMakeBuildSystem::buildTargets() const return m_buildTargets; } -CMakeConfig CMakeBuildSystem::parseCMakeCacheDotTxt(const Utils::FilePath &cacheFile, - QString *errorMessage) -{ - if (!cacheFile.exists()) { - if (errorMessage) - *errorMessage = tr("CMakeCache.txt file not found."); - return {}; - } - CMakeConfig result = CMakeConfig::fromFile(cacheFile, errorMessage); - if (!errorMessage->isEmpty()) - return {}; - return result; -} - bool CMakeBuildSystem::filteredOutTarget(const CMakeBuildTarget &target) { return target.title.endsWith("_autogen") || diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.h b/src/plugins/cmakeprojectmanager/cmakebuildsystem.h index d47a5efb0b4..37b076b939d 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.h +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.h @@ -98,10 +98,6 @@ public: Utils::CommandLine commandLineForTests(const QList &tests, const QStringList &options) const final; - // Generic CMake helper functions: - static CMakeConfig parseCMakeCacheDotTxt(const Utils::FilePath &cacheFile, - QString *errorMessage); - static bool filteredOutTarget(const CMakeBuildTarget &target); bool isMultiConfig() const; diff --git a/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp b/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp index 002ece93261..51aab9a9836 100644 --- a/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp @@ -413,7 +413,6 @@ CMakeConfig CMakeConfig::fromFile(const Utils::FilePath &cacheFile, QString *err Utils::sort(result, &CMakeConfigItem::less); return result; - } QString CMakeConfigItem::toString(const Utils::MacroExpander *expander) const diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp index 12939e94dad..9bf2897744d 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp @@ -304,7 +304,7 @@ QList CMakeProjectImporter::examineDirectory(const FilePath &importPath, } QString errorMessage; - const CMakeConfig config = CMakeBuildSystem::parseCMakeCacheDotTxt(cacheFile, &errorMessage); + const CMakeConfig config = CMakeConfig::fromFile(cacheFile, &errorMessage); if (config.isEmpty() || !errorMessage.isEmpty()) { qCDebug(cmInputLog) << "Failed to read configuration from" << cacheFile << errorMessage; return { };