From defdfc0c4b81dae6e7e4849128ec135f57d715db Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 30 Jun 2026 18:33:01 -0400 Subject: [PATCH 1/8] add support for Folders and skip non C++ projects --- lib/importproject.cpp | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 2d63fa8bbb7..09f6b892885 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -529,27 +529,48 @@ bool ImportProject::importSlnx(const std::string& filename, const std::vectorName(), "Solution") != 0) { + errors.emplace_back("Invalid Visual Studio solution file format"); + return false; + } + std::map variables; variables["SolutionDir"] = Path::simplifyPath(Path::getPathFromFilename(filename)); bool found = false; std::vector sharedItemsProjects; + auto processProject = [&](const tinyxml2::XMLElement* projectNode) { + const char* pathAttribute = projectNode->Attribute("Path"); + if (pathAttribute == nullptr) + return; + + std::string vcxproj(pathAttribute); + vcxproj = Path::toNativeSeparators(std::move(vcxproj)); + + if (Path::getFilenameExtensionInLowerCase(vcxproj) != ".vcxproj") + return; // skip other project types + + if (!Path::isAbsolute(vcxproj)) + vcxproj = variables["SolutionDir"] + vcxproj; + + vcxproj = Path::fromNativeSeparators(std::move(vcxproj)); + if (!importVcxproj(vcxproj, variables, "", fileFilters, sharedItemsProjects)) { + errors.emplace_back("failed to load '" + vcxproj + "' from Visual Studio solution"); + return; + } + found = true; + }; + for (const tinyxml2::XMLElement* node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) { const char* name = node->Name(); if (std::strcmp(name, "Project") == 0) { - const char* labelAttribute = node->Attribute("Path"); - if (labelAttribute) { - std::string vcxproj(labelAttribute); - vcxproj = Path::toNativeSeparators(std::move(vcxproj)); - if (!Path::isAbsolute(vcxproj)) - vcxproj = variables["SolutionDir"] + vcxproj; - vcxproj = Path::fromNativeSeparators(std::move(vcxproj)); - if (!importVcxproj(vcxproj, variables, "", fileFilters, sharedItemsProjects)) { - errors.emplace_back("failed to load '" + vcxproj + "' from Visual Studio solution"); - return false; + processProject(node); + } else if (std::strcmp(name, "Folder") == 0) { + for (const tinyxml2::XMLElement* childNode = node->FirstChildElement(); childNode; childNode = childNode->NextSiblingElement()) { + if (std::strcmp(childNode->Name(), "Project") == 0) { + processProject(childNode); } - found = true; } } } From ff2b767ff6ab0cdb69bde3a651db8d91436497c6 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 30 Jun 2026 23:55:26 -0400 Subject: [PATCH 2/8] fix ci --- .github/workflows/selfcheck.yml | 2 +- lib/importproject.cpp | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/selfcheck.yml b/.github/workflows/selfcheck.yml index 6d100c4ddc8..1d9f963ddde 100644 --- a/.github/workflows/selfcheck.yml +++ b/.github/workflows/selfcheck.yml @@ -121,7 +121,7 @@ jobs: - name: Self check (unusedFunction / no test / no gui) run: | - supprs="--suppress=unusedFunction:lib/errorlogger.h:197 --suppress=unusedFunction:lib/importproject.cpp:1671 --suppress=unusedFunction:lib/importproject.cpp:1695" + supprs="--suppress=unusedFunction:lib/errorlogger.h:197 --suppress=unusedFunction:lib/importproject.cpp:1695 --suppress=unusedFunction:lib/importproject.cpp:1719" ./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr $supprs env: DISABLE_VALUEFLOW: 1 diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 09f6b892885..0e6ca353480 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -543,13 +543,13 @@ bool ImportProject::importSlnx(const std::string& filename, const std::vectorAttribute("Path"); if (pathAttribute == nullptr) - return; + return true; std::string vcxproj(pathAttribute); vcxproj = Path::toNativeSeparators(std::move(vcxproj)); if (Path::getFilenameExtensionInLowerCase(vcxproj) != ".vcxproj") - return; // skip other project types + return true; // skip other project types if (!Path::isAbsolute(vcxproj)) vcxproj = variables["SolutionDir"] + vcxproj; @@ -557,19 +557,22 @@ bool ImportProject::importSlnx(const std::string& filename, const std::vectorFirstChildElement(); node; node = node->NextSiblingElement()) { const char* name = node->Name(); if (std::strcmp(name, "Project") == 0) { - processProject(node); + if (!processProject(node)) + return false; } else if (std::strcmp(name, "Folder") == 0) { for (const tinyxml2::XMLElement* childNode = node->FirstChildElement(); childNode; childNode = childNode->NextSiblingElement()) { if (std::strcmp(childNode->Name(), "Project") == 0) { - processProject(childNode); + if (!processProject(childNode)) + return false; } } } From 5d12bdaa032ba9681861ddcff8a730c6208610ce Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 1 Jul 2026 09:22:34 -0400 Subject: [PATCH 3/8] add test for missing project file in folder --- test/cli/project_test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/cli/project_test.py b/test/cli/project_test.py index 7421ca406a6..ca288fb97fb 100644 --- a/test/cli/project_test.py +++ b/test/cli/project_test.py @@ -179,6 +179,26 @@ def test_slnx_project_file_not_found(tmpdir): __test_project_error(tmpdir, "slnx", content, expected) +def test_slnx_project_file_in_folder_not_found(tmpdir): + content = '\r\n' \ + "\r\n" \ + " \r\n" \ + ' \r\n' \ + ' \r\n' \ + " \r\n" \ + ' \r\n' \ + ' \r\n' \ + ' \r\n' \ + "\r\n" + + expected = "Visual Studio project file is not a valid XML - XML_ERROR_FILE_NOT_FOUND\n" \ + "cppcheck: error: failed to load '{}' from Visual Studio solution".format(os.path.join(tmpdir, "common/test.vcxproj")) + if sys.platform == "win32": + expected = expected.replace('\\', '/') + + __test_project_error(tmpdir, "slnx", content, expected) + + def test_vcxproj_no_xml_root(tmpdir): content = '' From 2517e6f2dd920e1a3a98e57c5336dc549fbf8192 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 1 Jul 2026 13:28:04 -0400 Subject: [PATCH 4/8] add test for no project in folder --- test/cli/project_test.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/cli/project_test.py b/test/cli/project_test.py index ca288fb97fb..bc2ca761653 100644 --- a/test/cli/project_test.py +++ b/test/cli/project_test.py @@ -161,6 +161,22 @@ def test_slnx_no_projects(tmpdir): __test_project_error(tmpdir, "slnx", content, expected) +def test_slnx_no_projects_in_folder(tmpdir): + content = '\r\n' \ + "\r\n" \ + " \r\n" \ + ' \r\n' \ + ' \r\n' \ + " \r\n" \ + ' \r\n' \ + ' \r\n' \ + "\r\n" + + expected = "no projects found in Visual Studio solution file" + + __test_project_error(tmpdir, "slnx", content, expected) + + def test_slnx_project_file_not_found(tmpdir): content = '\r\n' \ "\r\n" \ From 1d324a26ab956609781123a2a961d6ffbf07c904 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 1 Jul 2026 13:34:12 -0400 Subject: [PATCH 5/8] add test for invalid xml root --- test/cli/project_test.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/cli/project_test.py b/test/cli/project_test.py index bc2ca761653..64bb406a709 100644 --- a/test/cli/project_test.py +++ b/test/cli/project_test.py @@ -147,6 +147,16 @@ def test_slnx_no_xml_root(tmpdir): __test_project_error(tmpdir, "slnx", content, expected) +def test_slnx_invalid_xml_root(tmpdir): + content = '\r\n' \ + "\r\n" \ + "\r\n" + + expected = "Invalid Visual Studio solution file format" + + __test_project_error(tmpdir, "slnx", content, expected) + + def test_slnx_no_projects(tmpdir): content = '\r\n' \ "\r\n" \ From 4714c5ee5ea1c0abeca93969bbd8cce29b54bbeb Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 2 Jul 2026 13:48:59 -0400 Subject: [PATCH 6/8] run tests on actual project --- test/cli/slnx-folders/app/app.cpp | 7 ++ test/cli/slnx-folders/app/app.vcxproj | 102 ++++++++++++++++++++ test/cli/slnx-folders/lib/lib.cpp | 9 ++ test/cli/slnx-folders/lib/lib.h | 1 + test/cli/slnx-folders/lib/lib.vcxproj | 97 +++++++++++++++++++ test/cli/slnx-folders/slnx-folders.cppcheck | 17 ++++ test/cli/slnx-folders/slnx-folders.slnx | 12 +++ test/cli/slnx-folders_test.py | 77 +++++++++++++++ 8 files changed, 322 insertions(+) create mode 100644 test/cli/slnx-folders/app/app.cpp create mode 100644 test/cli/slnx-folders/app/app.vcxproj create mode 100644 test/cli/slnx-folders/lib/lib.cpp create mode 100644 test/cli/slnx-folders/lib/lib.h create mode 100644 test/cli/slnx-folders/lib/lib.vcxproj create mode 100644 test/cli/slnx-folders/slnx-folders.cppcheck create mode 100644 test/cli/slnx-folders/slnx-folders.slnx create mode 100644 test/cli/slnx-folders_test.py diff --git a/test/cli/slnx-folders/app/app.cpp b/test/cli/slnx-folders/app/app.cpp new file mode 100644 index 00000000000..3454c2de254 --- /dev/null +++ b/test/cli/slnx-folders/app/app.cpp @@ -0,0 +1,7 @@ +#include "../lib/lib.h" + +int main(int argc, char *argv[]) +{ + int x = 3 / 0; (void)x; // ERROR + return foo(); +} diff --git a/test/cli/slnx-folders/app/app.vcxproj b/test/cli/slnx-folders/app/app.vcxproj new file mode 100644 index 00000000000..b72ae55c565 --- /dev/null +++ b/test/cli/slnx-folders/app/app.vcxproj @@ -0,0 +1,102 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 18.0 + Win32Proj + {0de77c38-881a-4f9f-bdfa-2c429968985e} + unused + 10.0 + + + + Application + true + v145 + Unicode + + + Application + false + v145 + true + Unicode + + + + + + + + + + + + + + + ..\x64\Debug\ + x64\Debug\ + + + ..\x64\Release\ + x64\Release\ + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + + + Console + true + ../lib + + + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + true + + + + + + + + {93BE1430-BE74-35DF-1882-AF70E49C9898} + + + + + + diff --git a/test/cli/slnx-folders/lib/lib.cpp b/test/cli/slnx-folders/lib/lib.cpp new file mode 100644 index 00000000000..b4a89cee1c7 --- /dev/null +++ b/test/cli/slnx-folders/lib/lib.cpp @@ -0,0 +1,9 @@ +#include +#include "lib.h" + +int foo() +{ + std::cout << "hello world\n"; + int x = 3 / 0; (void)x; // ERROR + return 0; +} diff --git a/test/cli/slnx-folders/lib/lib.h b/test/cli/slnx-folders/lib/lib.h new file mode 100644 index 00000000000..cf790ac3eab --- /dev/null +++ b/test/cli/slnx-folders/lib/lib.h @@ -0,0 +1 @@ +extern int foo(); diff --git a/test/cli/slnx-folders/lib/lib.vcxproj b/test/cli/slnx-folders/lib/lib.vcxproj new file mode 100644 index 00000000000..232c2478e2f --- /dev/null +++ b/test/cli/slnx-folders/lib/lib.vcxproj @@ -0,0 +1,97 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 18.0 + Win32Proj + {93BE1430-BE74-35DF-1882-AF70E49C9898} + unused + 10.0 + + + + StaticLibrary + true + v145 + Unicode + + + StaticLibrary + false + v145 + true + Unicode + + + + + + + + + + + + + + + ..\x64\Debug\ + x64\Debug\ + + + ..\x64\Release\ + x64\Release\ + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + + + Console + true + ../lib + + + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + true + + + + + + + + + diff --git a/test/cli/slnx-folders/slnx-folders.cppcheck b/test/cli/slnx-folders/slnx-folders.cppcheck new file mode 100644 index 00000000000..4fa0c4e7623 --- /dev/null +++ b/test/cli/slnx-folders/slnx-folders.cppcheck @@ -0,0 +1,17 @@ + + + slnx-folders-cppcheck-build-dir + slnx-folders.slnx + false + true + true + true + 2 + 100 + + Debug + Release + + + slnx-folders + diff --git a/test/cli/slnx-folders/slnx-folders.slnx b/test/cli/slnx-folders/slnx-folders.slnx new file mode 100644 index 00000000000..ce6b9014431 --- /dev/null +++ b/test/cli/slnx-folders/slnx-folders.slnx @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/test/cli/slnx-folders_test.py b/test/cli/slnx-folders_test.py new file mode 100644 index 00000000000..8dc42c780d5 --- /dev/null +++ b/test/cli/slnx-folders_test.py @@ -0,0 +1,77 @@ + +# python -m pytest slnx-folders_test.py + +import os +import re +import glob +import json +import shutil +import xml.etree.ElementTree as ET + +import pytest + +from testutils import create_gui_project_file, cppcheck + +__script_dir = os.path.dirname(os.path.abspath(__file__)) +__proj_dir = os.path.join(__script_dir, 'slnx-folders') + + +# Get Visual Studio configurations checking a file +# Checking {file} {config}... +def __getVsConfigs(stdout, filename): + ret = [] + for line in stdout.split('\n'): + if not line.startswith('Checking %s ' % filename): + continue + if not line.endswith('...'): + continue + res = re.match(r'.* ([A-Za-z0-9|]+)...', line) + if res: + ret.append(res.group(1)) + ret.sort() + return ' '.join(ret) + +def test_relative_path(): + args = [ + '--template=cppcheck1', + 'slnx-folders' + ] + ret, stdout, stderr = cppcheck(args, cwd=__script_dir) + filename1 = os.path.join('slnx-folders', 'app', 'app.cpp') + filename2 = os.path.join('slnx-folders', 'lib', 'lib.cpp') + assert ret == 0, stdout + expected = ( + '[%s:5]: (error) Division by zero.\n' + '[%s:7]: (error) Division by zero.\n' % (filename1, filename2) + ) + assert stderr == expected + +def test_local_path(): + args = [ + '--template=cppcheck1', + '.' + ] + ret, stdout, stderr = cppcheck(args, cwd=__proj_dir) + filename1 = os.path.join('app', 'app.cpp') + filename2 = os.path.join('lib', 'lib.cpp') + assert ret == 0, stdout + expected = ( + '[%s:5]: (error) Division by zero.\n' + '[%s:7]: (error) Division by zero.\n' % (filename1, filename2) + ) + assert stderr == expected + +def test_absolute_path(): + args = [ + '--template=cppcheck1', + __proj_dir + ] + ret, stdout, stderr = cppcheck(args) + filename1 = os.path.join(__proj_dir, 'app', 'app.cpp') + filename2 = os.path.join(__proj_dir, 'lib', 'lib.cpp') + assert ret == 0, stdout + expected = ( + '[%s:5]: (error) Division by zero.\n' + '[%s:7]: (error) Division by zero.\n' % (filename1, filename2) + ) + assert stderr == expected From 0adacee38e123b9f5cc7b47d6af5d11e8f57f975 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 2 Jul 2026 14:05:21 -0400 Subject: [PATCH 7/8] remove unused imports --- test/cli/slnx-folders_test.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/cli/slnx-folders_test.py b/test/cli/slnx-folders_test.py index 8dc42c780d5..8d7ef91e373 100644 --- a/test/cli/slnx-folders_test.py +++ b/test/cli/slnx-folders_test.py @@ -3,14 +3,8 @@ import os import re -import glob -import json -import shutil -import xml.etree.ElementTree as ET -import pytest - -from testutils import create_gui_project_file, cppcheck +from testutils import cppcheck __script_dir = os.path.dirname(os.path.abspath(__file__)) __proj_dir = os.path.join(__script_dir, 'slnx-folders') From 3c6916a8352c1fe6b2e62898225bb07e24399885 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 2 Jul 2026 14:32:42 -0400 Subject: [PATCH 8/8] make the results no be order dependent --- test/cli/slnx-folders_test.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/cli/slnx-folders_test.py b/test/cli/slnx-folders_test.py index 8d7ef91e373..b9dd5f09c92 100644 --- a/test/cli/slnx-folders_test.py +++ b/test/cli/slnx-folders_test.py @@ -9,6 +9,8 @@ __script_dir = os.path.dirname(os.path.abspath(__file__)) __proj_dir = os.path.join(__script_dir, 'slnx-folders') +def get_lines(s): + return sorted(s.split('\n')) # Get Visual Studio configurations checking a file # Checking {file} {config}... @@ -38,7 +40,7 @@ def test_relative_path(): '[%s:5]: (error) Division by zero.\n' '[%s:7]: (error) Division by zero.\n' % (filename1, filename2) ) - assert stderr == expected + assert get_lines(stderr) == get_lines(expected) def test_local_path(): args = [ @@ -53,7 +55,7 @@ def test_local_path(): '[%s:5]: (error) Division by zero.\n' '[%s:7]: (error) Division by zero.\n' % (filename1, filename2) ) - assert stderr == expected + assert get_lines(stderr) == get_lines(expected) def test_absolute_path(): args = [ @@ -68,4 +70,4 @@ def test_absolute_path(): '[%s:5]: (error) Division by zero.\n' '[%s:7]: (error) Division by zero.\n' % (filename1, filename2) ) - assert stderr == expected + assert get_lines(stderr) == get_lines(expected)