Skip to content

Commit 5405f94

Browse files
committed
split list of libraries early in CLI
1 parent ec7e0cc commit 5405f94

File tree

4 files changed

+8
-25
lines changed

4 files changed

+8
-25
lines changed

cli/cmdlineparser.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,11 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
870870

871871
// --library
872872
else if (std::strncmp(argv[i], "--library=", 10) == 0) {
873-
mSettings.libraries.emplace_back(argv[i] + 10);
873+
// TODO: bail out on empty library
874+
std::list<std::string> libs = splitString(argv[i] + 10, ',');
875+
for (auto& l : libs) {
876+
mSettings.libraries.emplace_back(std::move(l));
877+
}
874878
}
875879

876880
// Set maximum number of #ifdef configurations to check

lib/library.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,8 @@ static void gettokenlistfromvalid(const std::string& valid, bool cpp, TokenList&
6666

6767
Library::Error Library::load(const char exename[], const char path[], bool debug)
6868
{
69-
// TODO: extract split into helper function
70-
// TODO: remove handling of multiple libraries at once?
7169
if (std::strchr(path,',') != nullptr) {
72-
if (debug)
73-
std::cout << "handling multiple libraries '" + std::string(path) + "'" << std::endl;
74-
std::string p(path);
75-
for (;;) {
76-
const std::string::size_type pos = p.find(',');
77-
if (pos == std::string::npos)
78-
break;
79-
const Error &e = load(exename, p.substr(0,pos).c_str(), debug);
80-
if (e.errorcode != ErrorCode::OK)
81-
return e;
82-
p = p.substr(pos+1);
83-
}
84-
if (!p.empty())
85-
return load(exename, p.c_str(), debug);
86-
return Error();
70+
throw std::runtime_error("handling of multiple libraries not supported");
8771
}
8872

8973
const bool is_abs_path = Path::isAbsolute(path);

test/cli/other_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,6 @@ def test_lib_lookup_multi(tmpdir):
17421742
assert exitcode == 0, stdout
17431743
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
17441744
assert lines == [
1745-
"handling multiple libraries 'posix,gnu'",
17461745
"looking for library 'posix'",
17471746
"looking for library 'posix.cfg'",
17481747
"looking for library '{}/posix.cfg'".format(exepath),

test/testcmdlineparser.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,28 +2454,24 @@ class TestCmdlineParser : public TestFixture {
24542454
REDIRECT;
24552455
const char * const argv[] = {"cppcheck", "--library=posix,gnu", "file.cpp"};
24562456
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
2457-
TODO_ASSERT_EQUALS(2, 1, settings->libraries.size());
2458-
ASSERT_EQUALS("posix,gnu", *settings->libraries.cbegin());
2459-
/*
24602457
ASSERT_EQUALS(2, settings->libraries.size());
24612458
auto it = settings->libraries.cbegin();
24622459
ASSERT_EQUALS("posix", *it++);
24632460
ASSERT_EQUALS("gnu", *it);
2464-
*/
24652461
}
24662462

24672463
void libraryMultipleEmpty() {
24682464
REDIRECT;
24692465
const char * const argv[] = {"cppcheck", "--library=posix,,gnu", "file.cpp"};
24702466
ASSERT_EQUALS(false, parser->fillSettingsFromArgs(3, argv));
2471-
ASSERT_EQUALS("cppcheck: Failed to load library configuration file 'posix,,gnu'. File not found\n", logger->str());
2467+
ASSERT_EQUALS("cppcheck: Failed to load library configuration file ''. File not found\n", logger->str());
24722468
}
24732469

24742470
void libraryMultipleEmpty2() {
24752471
REDIRECT;
24762472
const char * const argv[] = {"cppcheck", "--library=posix,gnu,", "file.cpp"};
24772473
ASSERT_EQUALS(false, parser->fillSettingsFromArgs(3, argv));
2478-
TODO_ASSERT_EQUALS("cppcheck: Failed to load library configuration file 'posix,gnu,'. File not found\n", "cppcheck: error: could not find or open any of the paths given.\n", logger->str());
2474+
ASSERT_EQUALS("cppcheck: Failed to load library configuration file ''. File not found\n", logger->str());
24792475
}
24802476

24812477
void suppressXml() {

0 commit comments

Comments
 (0)