From 5a52fa80fb80b45686e999dc506b54e430cb25bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Thu, 5 Oct 2023 21:36:44 +0200 Subject: [PATCH] refs #12022 - disallow multiple `--project` options (#5499) --- cli/cmdlineparser.cpp | 6 ++++ gui/mainwindow.cpp | 3 ++ gui/test/projectfile/testprojectfile.cpp | 1 - lib/importproject.cpp | 5 ---- lib/importproject.h | 5 ++-- releasenotes.txt | 1 + test/testcmdlineparser.cpp | 35 ++++++++++++++++++++++++ 7 files changed, 48 insertions(+), 8 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index fffe0b02d..173e63133 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -654,6 +654,12 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) // --project else if (std::strncmp(argv[i], "--project=", 10) == 0) { + if (mSettings.project.projectType != ImportProject::Type::NONE) + { + mLogger.printError("multiple --project options are not supported."); + return false; + } + mSettings.checkAllConfigurations = false; // Can be overridden with --max-configs or --force std::string projectFile = argv[i]+10; ImportProject::Type projType = mSettings.project.import(projectFile, &mSettings); diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5f0d740b1..2cacb1810 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1747,6 +1747,9 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check case ImportProject::Type::FAILURE: errorMessage = tr("Failed to import project file"); break; + case ImportProject::Type::NONE: + // can never happen + break; } if (!errorMessage.isEmpty()) { diff --git a/gui/test/projectfile/testprojectfile.cpp b/gui/test/projectfile/testprojectfile.cpp index 65531aa0f..572219710 100644 --- a/gui/test/projectfile/testprojectfile.cpp +++ b/gui/test/projectfile/testprojectfile.cpp @@ -41,7 +41,6 @@ const char Settings::SafeChecks::XmlInternalFunctions[] = "internal-functions"; const char Settings::SafeChecks::XmlExternalVariables[] = "external-variables"; Settings::Settings() : maxCtuDepth(10) {} cppcheck::Platform::Platform() = default; -ImportProject::ImportProject() = default; bool ImportProject::sourceFileExists(const std::string & /*file*/) { return true; } diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 571676520..aeb66089d 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -42,11 +42,6 @@ #include "json.h" -ImportProject::ImportProject() -{ - projectType = Type::UNKNOWN; -} - void ImportProject::ignorePaths(const std::vector &ipaths) { for (std::list::iterator it = fileSettings.begin(); it != fileSettings.end();) { diff --git a/lib/importproject.h b/lib/importproject.h index 8ccf95c8a..46abbda9d 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -51,6 +51,7 @@ class Settings; class CPPCHECKLIB ImportProject { public: enum class Type { + NONE, UNKNOWN, MISSING, FAILURE, @@ -82,9 +83,9 @@ public: void setIncludePaths(const std::string &basepath, const std::list &in, std::map &variables); }; std::list fileSettings; - Type projectType; + Type projectType{Type::NONE}; - ImportProject(); + ImportProject() = default; virtual ~ImportProject() = default; ImportProject(const ImportProject&) = default; ImportProject& operator=(const ImportProject&) = default; diff --git a/releasenotes.txt b/releasenotes.txt index 80455123a..b0b87e6db 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -20,3 +20,4 @@ Other: - The undocumented and deprecated command-line options `--template