diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 4478f1b762d..8c08df0474a 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -630,33 +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_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/lib/cppcheck.cpp b/lib/cppcheck.cpp index 9490f62475d..e89c8f989a3 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1043,11 +1043,22 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str } if (mSettings.checkConfiguration) { - for (const std::string &config : configurations) + 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); + } (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); @@ -1187,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; @@ -1687,6 +1699,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) @@ -1697,6 +1729,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; diff --git a/selfcheck.sh b/selfcheck.sh new file mode 100644 index 00000000000..ae9800f61f4 --- /dev/null +++ b/selfcheck.sh @@ -0,0 +1,31 @@ +#!/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 + +if [ -n "$1" ]; then + selfcheck_options="$selfcheck_options $1" +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 + +rm -rf b2 +rm -rf b1 + +exit $ec \ No newline at end of file