Accept include paths ending with backslash.
Convert include path to use internal path separators when parsing command line. Convert back to native separators when using paths. Ticket #2448 (Error in handling -I command line parameter)
This commit is contained in:
parent
79e52a8c45
commit
846d3dae99
|
@ -25,6 +25,7 @@
|
|||
#include "timer.h"
|
||||
#include "settings.h"
|
||||
#include "cmdlineparser.h"
|
||||
#include "path.h"
|
||||
|
||||
// xml is used in rules
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
@ -254,9 +255,10 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
{
|
||||
path = 2 + argv[i];
|
||||
}
|
||||
path = Path::fromNativeSeparators(path);
|
||||
|
||||
// If path doesn't end with / or \, add it
|
||||
if (path[path.length()-1] != '/' && path[path.length()-1] != '\\')
|
||||
if (path[path.length()-1] != '/')
|
||||
path += '/';
|
||||
|
||||
_settings->_includePaths.push_back(path);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE
|
||||
#include "cmdlineparser.h"
|
||||
#include "filelister.h"
|
||||
#include "path.h"
|
||||
|
||||
CppCheckExecutor::CppCheckExecutor()
|
||||
{
|
||||
|
@ -63,9 +64,10 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
|||
iter != _settings._includePaths.end();
|
||||
++iter)
|
||||
{
|
||||
if (!getFileLister()->isDirectory(iter->c_str()))
|
||||
const std::string path(Path::toNativeSeparators(*iter));
|
||||
if (!getFileLister()->isDirectory(path.c_str()))
|
||||
{
|
||||
std::cout << "cppcheck: error: Couldn't find path given by -I '" + *iter + "'" << std::endl;
|
||||
std::cout << "cppcheck: error: Couldn't find path given by -I '" + path + "'" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1537,10 +1537,11 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
|||
includePaths2.push_front("");
|
||||
for (std::list<std::string>::const_iterator iter = includePaths2.begin(); iter != includePaths2.end(); ++iter)
|
||||
{
|
||||
fin.open((*iter + filename).c_str());
|
||||
const std::string path(Path::toNativeSeparators(*iter));
|
||||
fin.open((path + filename).c_str());
|
||||
if (fin.is_open())
|
||||
{
|
||||
filename = *iter + filename;
|
||||
filename = path + filename;
|
||||
fileOpened = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -51,6 +51,9 @@ private:
|
|||
TEST_CASE(defines3);
|
||||
TEST_CASE(includesnopath);
|
||||
TEST_CASE(includes);
|
||||
TEST_CASE(includesslash);
|
||||
TEST_CASE(includesbackslash);
|
||||
TEST_CASE(includesnospace);
|
||||
TEST_CASE(includes2);
|
||||
TEST_CASE(enabledAll);
|
||||
TEST_CASE(enabledStyle);
|
||||
|
@ -276,6 +279,36 @@ private:
|
|||
ASSERT_EQUALS(" include/", settings._includePaths.front());
|
||||
}
|
||||
|
||||
void includesslash()
|
||||
{
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I include/", "file.cpp"};
|
||||
Settings settings;
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(" include/", settings._includePaths.front());
|
||||
}
|
||||
|
||||
void includesbackslash()
|
||||
{
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-I include\\", "file.cpp"};
|
||||
Settings settings;
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS(" include/", settings._includePaths.front());
|
||||
}
|
||||
|
||||
void includesnospace()
|
||||
{
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"};
|
||||
Settings settings;
|
||||
CmdLineParser parser(&settings);
|
||||
ASSERT(parser.ParseFromArgs(3, argv));
|
||||
ASSERT_EQUALS("include/", settings._includePaths.front());
|
||||
}
|
||||
|
||||
void includes2()
|
||||
{
|
||||
REDIRECT;
|
||||
|
|
Loading…
Reference in New Issue