Skip to content

fixed #14000 - deprecated the usage of rules #7657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +63 to +65
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for the case when you compile it through the provided Visual Studio project which utilized neither CMake nor make.

#endif

static bool addFilesToList(const std::string& fileList, std::vector<std::string>& pathNames)
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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',
]
Expand Down Expand Up @@ -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',
]
Expand All @@ -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',
]
Expand Down
6 changes: 6 additions & 0 deletions test/cli/rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*\\}'
]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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+ '
]
Expand Down Expand Up @@ -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] )*?\\) { '
]
Expand Down Expand Up @@ -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 ;'
]
Expand Down Expand Up @@ -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+? (\\+\\+|\\-\\-) ; '
]
Expand Down
5 changes: 5 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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", "<?xml version=\"1.0\"?>");
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() {
Expand Down
1 change: 1 addition & 0 deletions tools/dmake/dmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down