From 327650ae4a878e8f66c0694e79742172fc0b76aa Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 5 Dec 2025 09:58:03 +0100 Subject: [PATCH 1/8] extracted selfcheck into script --- .github/workflows/CI-unixish.yml | 29 +---------------------------- selfcheck.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 selfcheck.sh diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 4478f1b762d..3f5fd0748f7 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -632,31 +632,4 @@ jobs: - name: Self check run: | - selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=file-total -D__GNUC__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=gnu --inconclusive --enable=style,performance,portability,warning,missingInclude,information --exception-handling --debug-warnings --check-level=exhaustive" - cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2" - gui_options="-DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=68 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt" - ec=0 - - # TODO: add --check-config - - # early exit - if [ $ec -eq 1 ]; then - exit $ec - fi - - # self check externals - ./cppcheck $selfcheck_options externals || ec=1 - # self check lib/cli - mkdir b1 - ./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json frontend || ec=1 - ./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json -Ifrontend cli || ec=1 - ./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json --enable=internal lib || ec=1 - # check gui with qt settings - mkdir b2 - ./cppcheck $selfcheck_options $cppcheck_options $gui_options --cppcheck-build-dir=b2 --addon=naming.json --suppress=simplifyUsing:*/moc_*.cpp -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui || ec=1 - # self check test and tools - ./cppcheck $selfcheck_options $cppcheck_options -Ifrontend -Icli test/*.cpp || ec=1 - ./cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1 - # triage - ./cppcheck $selfcheck_options $cppcheck_options $gui_options -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage || ec=1 - exit $ec + ./selfcheck.sh diff --git a/selfcheck.sh b/selfcheck.sh new file mode 100644 index 00000000000..5602075e2be --- /dev/null +++ b/selfcheck.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=file-total -D__GNUC__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=gnu --inconclusive --enable=style,performance,portability,warning,missingInclude,information --exception-handling --debug-warnings --check-level=exhaustive" +cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2" +gui_options="-DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=68 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt" +ec=0 + +# TODO: add --check-config + +# early exit +if [ $ec -eq 1 ]; then + exit $ec +fi + +# self check externals +./cppcheck $selfcheck_options externals || ec=1 +# self check lib/cli +mkdir b1 +./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json frontend || ec=1 +./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json -Ifrontend cli || ec=1 +./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json --enable=internal lib || ec=1 +# check gui with qt settings +mkdir b2 +./cppcheck $selfcheck_options $cppcheck_options $gui_options --cppcheck-build-dir=b2 --addon=naming.json --suppress=simplifyUsing:*/moc_*.cpp -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui || ec=1 +# self check test and tools +./cppcheck $selfcheck_options $cppcheck_options -Ifrontend -Icli test/*.cpp || ec=1 +./cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1 +# triage +./cppcheck $selfcheck_options $cppcheck_options $gui_options -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage || ec=1 +exit $ec \ No newline at end of file From b0c4dca2e12340e15c6950d44258a0e501223163 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 5 Dec 2025 09:58:48 +0100 Subject: [PATCH 2/8] selfcheck.sh: remove generated folders --- selfcheck.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/selfcheck.sh b/selfcheck.sh index 5602075e2be..b3ba998038f 100644 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -27,4 +27,8 @@ mkdir b2 ./cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1 # triage ./cppcheck $selfcheck_options $cppcheck_options $gui_options -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage || ec=1 + +rm -rf b2 +rm -rf b1 + exit $ec \ No newline at end of file From 7d254d205f53777b986eb2734138cdd5c0ecc4ad Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 5 Dec 2025 09:59:30 +0100 Subject: [PATCH 3/8] selfcheck.sh: removed unnecessary early exit --- selfcheck.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/selfcheck.sh b/selfcheck.sh index b3ba998038f..f12feb2a389 100644 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -7,11 +7,6 @@ ec=0 # TODO: add --check-config -# early exit -if [ $ec -eq 1 ]; then - exit $ec -fi - # self check externals ./cppcheck $selfcheck_options externals || ec=1 # self check lib/cli From 772bfa03206339b59d15ace372078757fe76cf90 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 5 Dec 2025 10:01:28 +0100 Subject: [PATCH 4/8] selfcheck.sh: make it possible to pass additional flags --- selfcheck.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/selfcheck.sh b/selfcheck.sh index f12feb2a389..ae9800f61f4 100644 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -5,7 +5,9 @@ cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppchec gui_options="-DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=68 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt" ec=0 -# TODO: add --check-config +if [ -n "$1" ]; then + selfcheck_options="$selfcheck_options $1" +fi # self check externals ./cppcheck $selfcheck_options externals || ec=1 From a3afd1f913b386c1bd51c8d8cb3f5dc748028bd0 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 5 Dec 2025 10:01:50 +0100 Subject: [PATCH 5/8] CI-unixish.yml: run --check-config --- .github/workflows/CI-unixish.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 3f5fd0748f7..8c08df0474a 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -630,6 +630,10 @@ jobs: make -C cmake.output autogen make -C cmake.output gui-build-deps triage-build-ui-deps + - name: Check Config + run: | + ./selfcheck.sh "--check-config" + - name: Self check run: | ./selfcheck.sh From 55066942a1d232831211b78e69c3c4fbd281c18d Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 5 Dec 2025 10:02:24 +0100 Subject: [PATCH 6/8] print configurations with `--check-config` --- lib/cppcheck.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 9490f62475d..2508caa482b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1043,8 +1043,13 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str } if (mSettings.checkConfiguration) { - for (const std::string &config : configurations) + for (const std::string &config : configurations) { + if (!mSettings.quiet && (!config.empty() && configurations.size() > 1)) { + std::string fixedpath = Path::toNativeSeparators(file.spath()); + mErrorLogger.reportOut("Checking " + fixedpath + ": " + config + "...", Color::FgGreen); + } (void)preprocessor.getcode(config, files, false); + } if (configurations.size() > maxConfigs) tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size()); From cb5dd37b5ae9f007cd989e60f2fcc6107a6b3e24 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 5 Dec 2025 10:13:03 +0100 Subject: [PATCH 7/8] added message about skipped configurations with `--check-config` --- lib/cppcheck.cpp | 29 +++++++++++++++++++++++++++-- lib/cppcheck.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 2508caa482b..1f983b0a67b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1043,16 +1043,20 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str } if (mSettings.checkConfiguration) { + std::string fixedpath = Path::toNativeSeparators(file.spath()); + int checkConfig = 0; for (const std::string &config : configurations) { if (!mSettings.quiet && (!config.empty() && configurations.size() > 1)) { - std::string fixedpath = Path::toNativeSeparators(file.spath()); mErrorLogger.reportOut("Checking " + fixedpath + ": " + config + "...", Color::FgGreen); } (void)preprocessor.getcode(config, files, false); + if (++checkConfig > maxConfigs) { + skippedConfigurationMessage(fixedpath, config); + } } if (configurations.size() > maxConfigs) - tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size()); + tooManyConfigsError(fixedpath, configurations.size()); if (analyzerInformation) mLogger->setAnalyzerInfo(nullptr); @@ -1692,6 +1696,26 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st mErrorLogger.reportErr(errmsg); } +void CppCheck::skippedConfigurationMessage(const std::string &file, const std::string& configuration) +{ + if (mSettings.severity.isEnabled(Severity::information) && file.empty()) + return; + + std::list loclist; + if (!file.empty()) { + loclist.emplace_back(file, 0, 0); + } + + ErrorMessage errmsg(std::move(loclist), + "", + Severity::information, + "The configuration '" + configuration + "' was not checked because it exceeded the threshold for maximum configuration to be checked.", + "skippedConfiguration", + Certainty::normal); + + mErrorLogger.reportErr(errmsg); +} + //--------------------------------------------------------------------------- void CppCheck::getErrorMessages(ErrorLogger &errorlogger) @@ -1702,6 +1726,7 @@ void CppCheck::getErrorMessages(ErrorLogger &errorlogger) CppCheck cppcheck(settings, supprs, errorlogger, true, nullptr); cppcheck.purgedConfigurationMessage("",""); + cppcheck.skippedConfigurationMessage("",""); cppcheck.tooManyConfigsError("",0U); // TODO: add functions to get remaining error messages diff --git a/lib/cppcheck.h b/lib/cppcheck.h index b001749ded7..bc71fefbde6 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -147,6 +147,7 @@ class CPPCHECKLIB CppCheck { private: void purgedConfigurationMessage(const std::string &file, const std::string& configuration); + void skippedConfigurationMessage(const std::string &file, const std::string& configuration); bool isPremiumCodingStandardId(const std::string& id) const; From 45b47a613bf55e2a1ed51a53b5c50a8a2912a34a Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 5 Dec 2025 10:13:41 +0100 Subject: [PATCH 8/8] s [skip ci] --- lib/cppcheck.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 1f983b0a67b..e89c8f989a3 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1045,6 +1045,8 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str if (mSettings.checkConfiguration) { std::string fixedpath = Path::toNativeSeparators(file.spath()); int checkConfig = 0; + // TODO: this logic differs from the actual one during analysis + // TODO: print invalid configurations for (const std::string &config : configurations) { if (!mSettings.quiet && (!config.empty() && configurations.size() > 1)) { mErrorLogger.reportOut("Checking " + fixedpath + ": " + config + "...", Color::FgGreen); @@ -1196,6 +1198,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str if (!tokenizer.tokens()) continue; + // TODO: unreachable // skip rest of iteration if just checking configuration if (mSettings.checkConfiguration) continue;