Skip to content

Commit 7f9fe9c

Browse files
committed
fixed #14000 - deprecated the usage of rules
1 parent 8f3d36a commit 7f9fe9c

File tree

8 files changed

+30
-0
lines changed

8 files changed

+30
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ ifeq ($(HAVE_RULES),yes)
150150
else
151151
LIBS=$(shell $(PCRE_CONFIG) --libs)
152152
endif
153+
$(warning The usage of rules has been deprecated and will be removed in a future Cppcheck version. Please use addons instead.)
153154
else ifneq ($(HAVE_RULES),)
154155
$(error invalid HAVE_RULES value '$(HAVE_RULES)')
155156
endif

cli/cmdlineparser.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
#ifdef HAVE_RULES
6060
// xml is used for rules
6161
#include "xml.h"
62+
63+
#ifdef _MSC_VER
64+
#pragma message("The usage of rules is deprecated and will be removed in a future Cppcheck version. Please use addons instead.")
65+
#endif
6266
#endif
6367

6468
static bool addFilesToList(const std::string& fileList, std::vector<std::string>& pathNames)
@@ -1258,6 +1262,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
12581262
return Result::Fail;
12591263
}
12601264

1265+
mLogger.printMessage("'--rule' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.");
1266+
12611267
mSettings.rules.emplace_back(std::move(rule));
12621268
#else
12631269
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
13421348

13431349
mSettings.rules.emplace_back(std::move(rule));
13441350
}
1351+
1352+
mLogger.printMessage("'--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.");
13451353
} else {
13461354
mLogger.printError("unable to load rule-file '" + ruleFile + "' (" + tinyxml2::XMLDocument::ErrorIDToName(err) + ").");
13471355
return Result::Fail;

cmake/options.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ if(NOT BUILD_GUI)
8080
endif()
8181

8282
option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF)
83+
if(HAVE_RULES)
84+
message(WARNING "The usage of rules has been deprecated and will be removed in a future Cppcheck version. Please use addons instead.")
85+
endif()
8386
option(USE_BUNDLED_TINYXML2 "Usage of bundled TinyXML2 library" ON)
8487
if(BUILD_CORE_DLL AND NOT USE_BUNDLED_TINYXML2)
8588
message(FATAL_ERROR "Cannot use external TinyXML2 library when building lib as DLL")

releasenotes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Deprecations:
1616
- Support for building with Qt 5 will be removed in Cppcheck 2.19.
1717
- The platform 'unix32-unsigned' has been deprecated and will be removed in Cppcheck 2.19. Please use '--platform=unix32 --funsigned-char' instead.
1818
- The platform 'unix64-unsigned' has been deprecated and will be removed in Cppcheck 2.19. Please use '--platform=unix64 --funsigned-char' instead.
19+
- The usage of rules has been deprecated and will be removed in a future Cppcheck version. Please use addons instead.
1920
-
2021

2122
Other:

test/cli/other_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ def test_rule_file_define_multiple(tmpdir):
14451445
assert exitcode == 0, stdout if stdout else stderr
14461446
lines = stdout.splitlines()
14471447
assert lines == [
1448+
"cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
14481449
'Checking {} ...'.format(test_file),
14491450
'Processing rule: DEF_1',
14501451
'Processing rule: DEF_2',
@@ -1479,6 +1480,7 @@ def test_rule_file_define(tmpdir):
14791480
assert exitcode == 0, stdout if stdout else stderr
14801481
lines = stdout.splitlines()
14811482
assert lines == [
1483+
"cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
14821484
'Checking {} ...'.format(test_file),
14831485
'Processing rule: DEF_.',
14841486
'Checking {}: DEF_3=1...'.format(test_file)
@@ -1512,6 +1514,7 @@ def test_rule_file_normal(tmpdir):
15121514
assert exitcode == 0, stdout if stdout else stderr
15131515
lines = stdout.splitlines()
15141516
assert lines == [
1517+
"cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
15151518
'Checking {} ...'.format(test_file),
15161519
'Processing rule: int',
15171520
]
@@ -1544,6 +1547,7 @@ def test_rule_file_raw(tmpdir):
15441547
assert exitcode == 0, stdout if stdout else stderr
15451548
lines = stdout.splitlines()
15461549
assert lines == [
1550+
"cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
15471551
'Checking {} ...'.format(test_file),
15481552
'Processing rule: i32',
15491553
]
@@ -1567,6 +1571,7 @@ def test_rule(tmpdir):
15671571
assert exitcode == 0, stdout if stdout else stderr
15681572
lines = stdout.splitlines()
15691573
assert lines == [
1574+
"cppcheck: '--rule' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
15701575
'Checking {} ...'.format(test_file),
15711576
'Processing rule: f',
15721577
]

test/cli/rules_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_empty_catch_block(tmp_path):
3232
ret, stdout, stderr = cppcheck(args)
3333
assert ret == 0
3434
assert stdout.splitlines() == [
35+
"cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
3536
'Checking {} ...'.format(test_file),
3637
'Processing rule: \\}\\s*catch\\s*\\(.*\\)\\s*\\{\\s*\\}'
3738
]
@@ -61,6 +62,7 @@ def test_show_all_defines(tmp_path):
6162
ret, stdout, stderr = cppcheck(args)
6263
assert ret == 0
6364
assert stdout.splitlines() == [
65+
"cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
6466
'Checking {} ...'.format(test_file),
6567
'Processing rule: .*',
6668
'Checking {}: DEF_2=1...'.format(test_file)
@@ -95,6 +97,7 @@ def test_stl(tmp_path):
9597
ret, stdout, stderr = cppcheck(args)
9698
assert ret == 0
9799
assert stdout.splitlines() == [
100+
"cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
98101
'Checking {} ...'.format(test_file),
99102
'Processing rule: \\. find \\( "[^"]+?" \\) == \\d+ '
100103
]
@@ -124,6 +127,7 @@ def test_strlen_empty_str(tmp_path):
124127
ret, stdout, stderr = cppcheck(args)
125128
assert ret == 0
126129
assert stdout.splitlines() == [
130+
"cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
127131
'Checking {} ...'.format(test_file),
128132
'Processing rule: if \\( ([!] )*?(strlen) \\( \\w+? \\) ([>] [0] )*?\\) { '
129133
]
@@ -151,6 +155,7 @@ def test_suggest_nullptr(tmp_path):
151155
ret, stdout, stderr = cppcheck(args)
152156
assert ret == 0
153157
assert stdout.splitlines() == [
158+
"cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
154159
'Checking {} ...'.format(test_file),
155160
'Processing rule: (\\b\\w+\\b) \\* (\\b\\w+\\b) = 0 ;'
156161
]
@@ -178,6 +183,7 @@ def test_unused_deref(tmp_path):
178183
ret, stdout, stderr = cppcheck(args)
179184
assert ret == 0
180185
assert stdout.splitlines() == [
186+
"cppcheck: '--rule-file' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.",
181187
'Checking {} ...'.format(test_file),
182188
'Processing rule: [;{}] [*] \\w+? (\\+\\+|\\-\\-) ; '
183189
]

test/testcmdlineparser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,6 +2491,7 @@ class TestCmdlineParser : public TestFixture {
24912491
ASSERT_EQUALS(1, settings->rules.size());
24922492
auto it = settings->rules.cbegin();
24932493
ASSERT_EQUALS(".+", it->pattern);
2494+
ASSERT_EQUALS("cppcheck: '--rule' has been deprecated and will be removed in a future Cppcheck version. Please use an addon instead.\n", logger->str());
24942495
}
24952496

24962497
void ruleMissingPattern() {
@@ -2547,6 +2548,7 @@ class TestCmdlineParser : public TestFixture {
25472548
ASSERT_EQUALS_ENUM(Severity::warning, it->severity);
25482549
ASSERT_EQUALS("ruleId2", it->id);
25492550
ASSERT_EQUALS("ruleSummary2", it->summary);
2551+
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());
25502552
}
25512553

25522554
void ruleFileSingle() {
@@ -2570,6 +2572,7 @@ class TestCmdlineParser : public TestFixture {
25702572
ASSERT_EQUALS_ENUM(Severity::error, it->severity);
25712573
ASSERT_EQUALS("ruleId", it->id);
25722574
ASSERT_EQUALS("ruleSummary", it->summary);
2575+
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());
25732576
}
25742577

25752578
void ruleFileEmpty() {
@@ -2594,12 +2597,14 @@ class TestCmdlineParser : public TestFixture {
25942597
ASSERT_EQUALS("cppcheck: error: unable to load rule-file 'rule.xml' (XML_ERROR_EMPTY_DOCUMENT).\n", logger->str());
25952598
}
25962599

2600+
// TODO: bail out instead?
25972601
void ruleFileNoRoot() {
25982602
REDIRECT;
25992603
ScopedFile file("rule.xml", "<?xml version=\"1.0\"?>");
26002604
const char * const argv[] = {"cppcheck", "--rule-file=rule.xml", "file.cpp"};
26012605
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
26022606
ASSERT_EQUALS(0, settings->rules.size());
2607+
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());
26032608
}
26042609

26052610
void ruleFileEmptyElements1() {

tools/dmake/dmake.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ int main(int argc, char **argv)
746746
<< " else\n"
747747
<< " LIBS=$(shell $(PCRE_CONFIG) --libs)\n"
748748
<< " endif\n"
749+
<< " $(warning The usage of rules has been deprecated and will be removed in a future Cppcheck version. Please use addons instead.)\n"
749750
<< "else ifneq ($(HAVE_RULES),)\n"
750751
<< " $(error invalid HAVE_RULES value '$(HAVE_RULES)')\n"
751752
<< "endif\n\n";

0 commit comments

Comments
 (0)