From 4b750fe0e239ac67703fc7fbbb47153ab11822d2 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 16 Jun 2025 18:22:19 +0200 Subject: [PATCH] fixed #13941 - do not overwrite addons from CLI in GUI project import also added some TODOs --- lib/importproject.cpp | 21 +++++++++++---------- test/cli/lookup_test.py | 3 +-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/importproject.cpp b/lib/importproject.cpp index e23503885d0..285652eac6a 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -1292,9 +1292,9 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti } else if (strcmp(name, CppcheckXml::BuildDirElementName) == 0) temp.buildDir = joinRelativePath(path, empty_if_null(node->GetText())); else if (strcmp(name, CppcheckXml::IncludeDirElementName) == 0) - temp.includePaths = readXmlStringList(node, path, CppcheckXml::DirElementName, CppcheckXml::DirNameAttrib); + temp.includePaths = readXmlStringList(node, path, CppcheckXml::DirElementName, CppcheckXml::DirNameAttrib); // TODO: append instead of overwrite else if (strcmp(name, CppcheckXml::DefinesElementName) == 0) - temp.userDefines = join(readXmlStringList(node, "", CppcheckXml::DefineName, CppcheckXml::DefineNameAttrib), ";"); + temp.userDefines = join(readXmlStringList(node, "", CppcheckXml::DefineName, CppcheckXml::DefineNameAttrib), ";"); // TODO: append instead of overwrite else if (strcmp(name, CppcheckXml::UndefinesElementName) == 0) { for (const std::string &u : readXmlStringList(node, "", CppcheckXml::UndefineName, nullptr)) temp.userUndefs.insert(u); @@ -1306,15 +1306,15 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti else if (strcmp(name, CppcheckXml::PathsElementName) == 0) paths = readXmlStringList(node, path, CppcheckXml::PathName, CppcheckXml::PathNameAttrib); else if (strcmp(name, CppcheckXml::ExcludeElementName) == 0) - guiProject.excludedPaths = readXmlStringList(node, "", CppcheckXml::ExcludePathName, CppcheckXml::ExcludePathNameAttrib); + guiProject.excludedPaths = readXmlStringList(node, "", CppcheckXml::ExcludePathName, CppcheckXml::ExcludePathNameAttrib); // TODO: append instead of overwrite else if (strcmp(name, CppcheckXml::FunctionContracts) == 0) ; else if (strcmp(name, CppcheckXml::VariableContractsElementName) == 0) ; else if (strcmp(name, CppcheckXml::IgnoreElementName) == 0) - guiProject.excludedPaths = readXmlStringList(node, "", CppcheckXml::IgnorePathName, CppcheckXml::IgnorePathNameAttrib); + guiProject.excludedPaths = readXmlStringList(node, "", CppcheckXml::IgnorePathName, CppcheckXml::IgnorePathNameAttrib); // TODO: append instead of overwrite else if (strcmp(name, CppcheckXml::LibrariesElementName) == 0) - guiProject.libraries = readXmlStringList(node, "", CppcheckXml::LibraryElementName, nullptr); + guiProject.libraries = readXmlStringList(node, "", CppcheckXml::LibraryElementName, nullptr); // TODO: append instead of overwrite else if (strcmp(name, CppcheckXml::SuppressionsElementName) == 0) { for (const tinyxml2::XMLElement *child = node->FirstChildElement(); child; child = child->NextSiblingElement()) { if (strcmp(child->Name(), CppcheckXml::SuppressionElementName) != 0) @@ -1406,13 +1406,14 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti return false; } } - settings.basePaths = temp.basePaths; + settings.basePaths = temp.basePaths; // TODO: append instead of overwrite settings.relativePaths |= temp.relativePaths; settings.buildDir = temp.buildDir; - settings.includePaths = temp.includePaths; - settings.userDefines = temp.userDefines; - settings.userUndefs = temp.userUndefs; - settings.addons = temp.addons; + settings.includePaths = temp.includePaths; // TODO: append instead of overwrite + settings.userDefines = temp.userDefines; // TODO: append instead of overwrite + settings.userUndefs = temp.userUndefs; // TODO: append instead of overwrite + for (const std::string &addon : temp.addons) + settings.addons.emplace(addon); settings.clang = temp.clang; settings.clangTidy = temp.clangTidy; settings.analyzeAllVsConfigs = temp.analyzeAllVsConfigs; diff --git a/test/cli/lookup_test.py b/test/cli/lookup_test.py index 8980328c583..a8862547530 100644 --- a/test/cli/lookup_test.py +++ b/test/cli/lookup_test.py @@ -668,14 +668,13 @@ def test_addon_lookup_notfound(tmpdir): ] -@pytest.mark.xfail(strict=True) # TODO: no addon lookup is being performed at all def test_addon_lookup_notfound_project(tmpdir): # #13940 / #13941 project_file, _ = __create_gui_project(tmpdir) exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=none', '--project={}'.format(project_file)]) exepath = os.path.dirname(exe) exepath_sep = exepath + os.path.sep - assert exitcode == 0, stdout + assert exitcode == 1, stdout lines = stdout.splitlines() assert lines == [ # TODO: needs to look relative to the project file first