#3244 'Get include pathes from file'

Signed-off-by: Günther Makulik <g-makulik@t-online.de>
This commit is contained in:
unknown 2011-10-22 21:24:23 +02:00
parent 20179673ce
commit 597a37cc32
2 changed files with 43 additions and 0 deletions

View File

@ -63,6 +63,33 @@ static void AddFilesToList(const std::string& FileList, std::vector<std::string>
}
}
static void AddInclPathsToList(const std::string& FileList, std::list<std::string>& PathNames)
{
// to keep things initially simple, if the file can't be opened, just be
// silent and move on
// ideas : we could also require this should be an xml file, with the filenames
// specified in an xml structure
// we could elaborate this then, to also include the I-paths, ...
// basically for everything that makes the command line very long
// xml is a bonus then, since we can easily extend it
// we need a good parser then -> suggestion : TinyXml
// drawback : creates a dependency
std::ifstream Files(FileList.c_str());
if (Files)
{
std::string PathName;
while (std::getline(Files, PathName)) // next line
{
if (!PathName.empty())
{
PathName = Path::fromNativeSeparators(PathName);
PathName = Path::removeQuotationMarks(PathName);
PathNames.push_back(PathName);
}
}
}
}
CmdLineParser::CmdLineParser(Settings *settings)
: _settings(settings)
, _showHelp(false)
@ -330,6 +357,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
_settings->_includePaths.push_back(path);
}
else if (strncmp(argv[i], "--includes-file=", 16) == 0)
{
// open this file and read every input file (1 file name per line)
AddInclPathsToList(16 + argv[i], _settings->_includePaths);
}
// file list specified
else if (strncmp(argv[i], "--file-list=", 12) == 0) {

View File

@ -56,6 +56,7 @@ private:
TEST_CASE(includesbackslash);
TEST_CASE(includesnospace);
TEST_CASE(includes2);
TEST_CASE(includesFile);
TEST_CASE(enabledAll);
TEST_CASE(enabledStyle);
TEST_CASE(enabledPerformance);
@ -365,6 +366,16 @@ private:
ASSERT_EQUALS("framework/", settings._includePaths.front());
}
void includesFile()
{
// TODO: Fails since cannot open the file
REDIRECT;
const char *argv[] = {"cppcheck", "--includes-file=inclpaths.txt", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
}
void enabledAll() {
REDIRECT;
const char *argv[] = {"cppcheck", "--enable=all", "file.cpp"};