Skip to content

Commit b8e2140

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

File tree

6 files changed

+19
-0
lines changed

6 files changed

+19
-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.)
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/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)