Skip to content
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

fixed #12811 - added CLI option --filesdir to show the built-in FILESDIR / added TODOs #7200

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
10 changes: 9 additions & 1 deletion cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,18 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
return Result::Exit;
}

if (std::strcmp(argv[i], "--filesdir") == 0) {
#ifdef FILESDIR
mLogger.printRaw(FILESDIR); // TODO: should not include newline
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 should not include the newline because that means you can simply assign this to a variable but you always have to strip the newline which is extremely annoying in a shell environment.

Copy link
Owner

Choose a reason for hiding this comment

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

It makes sense to me that the newline is added. But maybe the name can be clarified instead.

#endif
return Result::Exit;
}

if (std::strcmp(argv[i], "--version") == 0) {
if (!loadCppcheckCfg())
return Result::Fail;
const std::string version = getVersion();
mLogger.printRaw(version);
mLogger.printRaw(version); // TODO: should not include newline
return Result::Exit;
}
}
Expand Down Expand Up @@ -1727,6 +1734,7 @@ void CmdLineParser::printHelp() const
" --file-list=<file> Specify the files to check in a text file. Add one\n"
" filename per line. When file is '-,' the file list will\n"
" be read from standard input.\n"
" --filesdir Print the built-in FILESDIR.\n"
Copy link
Owner

Choose a reason for hiding this comment

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

hmm.. nobody has asked for this as far as I know. why do you add it?

Copy link
Owner

Choose a reason for hiding this comment

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

The interface of some linux tools is not very nice. Lots of options. I don't want to end up with 100's of options.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm.. nobody has asked for this as far as I know.

Most of the issue we uncover have not been reported by the users. Would that be a reason not to fix them.

why do you add it?

Because outside of some debug messages (and that only recently) that path is not visible unless you dump all the strings used in the executable.

Also it is an absolute(!) path hard-coded by the packager(!) which a normal user cannot control.

And see the ticket for more reasoning.

" -f, --force Force checking of all configurations in files. If used\n"
" together with '--max-configs=', the last option is the\n"
" one that is effective.\n"
Expand Down
2 changes: 1 addition & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ namespace {

void printRaw(const std::string &message) override
{
std::cout << message << std::endl;
std::cout << message << std::endl; // TODO: should not append newline
Copy link
Collaborator Author

@firewave firewave Jan 9, 2025

Choose a reason for hiding this comment

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

It is a bit of a misnomer right now since it is not raw (it has been an awkward name to begin with) as it adds to it.

I have not changed it because it would have ripple effect beyond the actual change.

}
};

Expand Down
11 changes: 11 additions & 0 deletions man/cppcheck.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<arg choice="opt">
<option>--file-list=&lt;file&gt;</option>
</arg>
<arg choice="opt">
<option>--filesdir</option>
</arg>
<arg choice="opt">
<option>--force</option>
</arg>
Expand Down Expand Up @@ -356,6 +359,14 @@ Example: '-UDEBUG'</para>
<para>Specify the files to check in a text file. One filename per line. When file is -, the file list will be read from standard input.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--filesdir</option>
</term>
<listitem>
<para>Print the built-in FILESDIR.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-f</option>
Expand Down
14 changes: 13 additions & 1 deletion test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class TestCmdlineParser : public TestFixture {

void printRaw(const std::string &message) override
{
printInternal(message + '\n');
printInternal(message + '\n'); // TODO: should not append newline
}

std::string str()
Expand Down Expand Up @@ -440,6 +440,7 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(debugClangOutput);
TEST_CASE(debugXmlMultiple);
TEST_CASE(debugNormalXmlMultiple);
TEST_CASE(filesdir);

TEST_CASE(ignorepaths1);
TEST_CASE(ignorepaths2);
Expand Down Expand Up @@ -2974,6 +2975,17 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS("cppcheck: error: printing debug output in XML format does not support multiple input files.\n", logger->str());
}

void filesdir() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--filesdir"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Exit, parseFromArgs(argv));
#ifdef FILESDIR
ASSERT_EQUALS(std::string(FILESDIR) + '\n', logger->str());
#else
ASSERT_EQUALS("", logger->str());
#endif
}

void ignorepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
Expand Down
Loading