diff --git a/Makefile b/Makefile index 188529d82a9..50f593a105e 100644 --- a/Makefile +++ b/Makefile @@ -150,6 +150,7 @@ ifeq ($(HAVE_RULES),yes) else LIBS=$(shell $(PCRE_CONFIG) --libs) endif + $(warning The usage of rules has been deprecated and will be removed in a future Cppcheck version. Please use addons instead.) else ifneq ($(HAVE_RULES),) $(error invalid HAVE_RULES value '$(HAVE_RULES)') endif diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 2c879daa904..c8ee1bdba9f 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -59,6 +59,10 @@ #ifdef HAVE_RULES // xml is used for rules #include "xml.h" + +#ifdef _MSC_VER +#pragma message("The usage of rules is deprecated and will be removed in a future Cppcheck version. Please use addons instead.") +#endif #endif static bool addFilesToList(const std::string& fileList, std::vector& pathNames) @@ -1258,6 +1262,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a return Result::Fail; } + mLogger.printMessage("'--rule' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead."); + mSettings.rules.emplace_back(std::move(rule)); #else mLogger.printError("Option --rule cannot be used as Cppcheck has not been built with rules support."); @@ -1342,6 +1348,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a mSettings.rules.emplace_back(std::move(rule)); } + + mLogger.printMessage("'--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead."); } else { mLogger.printError("unable to load rule-file '" + ruleFile + "' (" + tinyxml2::XMLDocument::ErrorIDToName(err) + ")."); return Result::Fail; diff --git a/cmake/options.cmake b/cmake/options.cmake index f388c90e173..75bb10efb32 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -80,6 +80,9 @@ if(NOT BUILD_GUI) endif() option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF) +if(HAVE_RULES) + message(WARNING "The usage of rules has been deprecated and will be removed in a future Cppcheck version. Please use addons instead.") +endif() option(USE_BUNDLED_TINYXML2 "Usage of bundled TinyXML2 library" ON) if(BUILD_CORE_DLL AND NOT USE_BUNDLED_TINYXML2) message(FATAL_ERROR "Cannot use external TinyXML2 library when building lib as DLL") diff --git a/releasenotes.txt b/releasenotes.txt index 4d3da24ef28..14087e9c07b 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -16,6 +16,7 @@ Deprecations: - Support for building with Qt 5 will be removed in Cppcheck 2.19. - The platform 'unix32-unsigned' has been deprecated and will be removed in Cppcheck 2.19. Please use '--platform=unix32 --funsigned-char' instead. - The platform 'unix64-unsigned' has been deprecated and will be removed in Cppcheck 2.19. Please use '--platform=unix64 --funsigned-char' instead. +- The usage of rules has been deprecated and will be removed in a future Cppcheck version. Please use addons instead. - Other: diff --git a/test/cli/other_test.py b/test/cli/other_test.py index e430dc3fd06..7ca6a296ebe 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -1445,6 +1445,7 @@ def test_rule_file_define_multiple(tmpdir): assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ + "cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: DEF_1', 'Processing rule: DEF_2', @@ -1479,6 +1480,7 @@ def test_rule_file_define(tmpdir): assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ + "cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: DEF_.', 'Checking {}: DEF_3=1...'.format(test_file) @@ -1512,6 +1514,7 @@ def test_rule_file_normal(tmpdir): assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ + "cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: int', ] @@ -1544,6 +1547,7 @@ def test_rule_file_raw(tmpdir): assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ + "cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: i32', ] @@ -1567,6 +1571,7 @@ def test_rule(tmpdir): assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ + "cppcheck: '--rule' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: f', ] diff --git a/test/cli/rules_test.py b/test/cli/rules_test.py index 241cdf34c51..4c27bc9e71f 100644 --- a/test/cli/rules_test.py +++ b/test/cli/rules_test.py @@ -32,6 +32,7 @@ def test_empty_catch_block(tmp_path): ret, stdout, stderr = cppcheck(args) assert ret == 0 assert stdout.splitlines() == [ + "cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: \\}\\s*catch\\s*\\(.*\\)\\s*\\{\\s*\\}' ] @@ -61,6 +62,7 @@ def test_show_all_defines(tmp_path): ret, stdout, stderr = cppcheck(args) assert ret == 0 assert stdout.splitlines() == [ + "cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: .*', 'Checking {}: DEF_2=1...'.format(test_file) @@ -95,6 +97,7 @@ def test_stl(tmp_path): ret, stdout, stderr = cppcheck(args) assert ret == 0 assert stdout.splitlines() == [ + "cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: \\. find \\( "[^"]+?" \\) == \\d+ ' ] @@ -124,6 +127,7 @@ def test_strlen_empty_str(tmp_path): ret, stdout, stderr = cppcheck(args) assert ret == 0 assert stdout.splitlines() == [ + "cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: if \\( ([!] )*?(strlen) \\( \\w+? \\) ([>] [0] )*?\\) { ' ] @@ -151,6 +155,7 @@ def test_suggest_nullptr(tmp_path): ret, stdout, stderr = cppcheck(args) assert ret == 0 assert stdout.splitlines() == [ + "cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: (\\b\\w+\\b) \\* (\\b\\w+\\b) = 0 ;' ] @@ -178,6 +183,7 @@ def test_unused_deref(tmp_path): ret, stdout, stderr = cppcheck(args) assert ret == 0 assert stdout.splitlines() == [ + "cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.", 'Checking {} ...'.format(test_file), 'Processing rule: [;{}] [*] \\w+? (\\+\\+|\\-\\-) ; ' ] diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index c0c0dde9786..304880cb20b 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -2491,6 +2491,7 @@ class TestCmdlineParser : public TestFixture { ASSERT_EQUALS(1, settings->rules.size()); auto it = settings->rules.cbegin(); ASSERT_EQUALS(".+", it->pattern); + ASSERT_EQUALS("cppcheck: '--rule' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.\n", logger->str()); } void ruleMissingPattern() { @@ -2547,6 +2548,7 @@ class TestCmdlineParser : public TestFixture { ASSERT_EQUALS_ENUM(Severity::warning, it->severity); ASSERT_EQUALS("ruleId2", it->id); ASSERT_EQUALS("ruleSummary2", it->summary); + ASSERT_EQUALS("cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.\n", logger->str()); } void ruleFileSingle() { @@ -2570,6 +2572,7 @@ class TestCmdlineParser : public TestFixture { ASSERT_EQUALS_ENUM(Severity::error, it->severity); ASSERT_EQUALS("ruleId", it->id); ASSERT_EQUALS("ruleSummary", it->summary); + ASSERT_EQUALS("cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.\n", logger->str()); } void ruleFileEmpty() { @@ -2594,12 +2597,14 @@ class TestCmdlineParser : public TestFixture { ASSERT_EQUALS("cppcheck: error: unable to load rule-file 'rule.xml' (XML_ERROR_EMPTY_DOCUMENT).\n", logger->str()); } + // TODO: bail out instead? void ruleFileNoRoot() { REDIRECT; ScopedFile file("rule.xml", ""); const char * const argv[] = {"cppcheck", "--rule-file=rule.xml", "file.cpp"}; ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); ASSERT_EQUALS(0, settings->rules.size()); + ASSERT_EQUALS("cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.\n", logger->str()); } void ruleFileEmptyElements1() { diff --git a/tools/dmake/dmake.cpp b/tools/dmake/dmake.cpp index f54907c3759..c50c95a9748 100644 --- a/tools/dmake/dmake.cpp +++ b/tools/dmake/dmake.cpp @@ -746,6 +746,7 @@ int main(int argc, char **argv) << " else\n" << " LIBS=$(shell $(PCRE_CONFIG) --libs)\n" << " endif\n" + << " $(warning The usage of rules has been deprecated and will be removed in a future Cppcheck version. Please use addons instead.)\n" << "else ifneq ($(HAVE_RULES),)\n" << " $(error invalid HAVE_RULES value '$(HAVE_RULES)')\n" << "endif\n\n";