Fixed #2409 (print a warning if provided path (commandline option -I [PATH]) does not exist)

This commit is contained in:
Daniel Marjamäki 2011-01-09 09:29:38 +01:00
parent 68beffca04
commit d316f6005f
7 changed files with 48 additions and 3 deletions

View File

@ -233,7 +233,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
}
// Include paths
else if (strcmp(argv[i], "-I") == 0 || strncmp(argv[i], "-I", 2) == 0)
else if (strncmp(argv[i], "-I", 2) == 0)
{
std::string path;
@ -252,8 +252,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// "-Ipath/"
else
{
path = argv[i];
path = path.substr(2);
path = 2 + argv[i];
}
// If path doesn't end with / or \, add it

View File

@ -56,6 +56,21 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
}
}
// Check that all include paths exist
{
std::list<std::string>::const_iterator iter;
for (iter = _settings._includePaths.begin();
iter != _settings._includePaths.end();
++iter)
{
if (!getFileLister()->isDirectory(iter->c_str()))
{
std::cout << "cppcheck: error: Couldn't find path given by -I '" + *iter + "'" << std::endl;
return false;
}
}
}
std::vector<std::string> pathnames = parser.GetPathNames();
std::vector<std::string> filenames;

View File

@ -66,6 +66,11 @@ public:
*/
virtual bool acceptFile(const std::string &filename);
/**
* @brief Is given path a directory?
* @return returns true if the path is a directory
*/
virtual bool isDirectory(const std::string &path) = 0;
};
/** @brief get filelister (platform dependent implementation) */

View File

@ -103,4 +103,23 @@ bool FileListerUnix::sameFileName(const std::string &fname1, const std::string &
#endif
}
bool FileListerUnix::isDirectory(const std::string &path)
{
bool ret = false;
glob_t glob_results;
glob(path.c_str(), GLOB_MARK, 0, &glob_results);
if (glob_results.gl_pathc == 1)
{
const std::string glob_path = glob_results.gl_pathv[0];
if (!glob_path.empty() && glob_path[glob_path.size() - 1] == '/')
{
ret = true;
}
}
globfree(&glob_results);
return ret;
}
#endif // _WIN32

View File

@ -33,6 +33,7 @@ public:
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path);
virtual bool sameFileName(const std::string &fname1, const std::string &fname2);
// virtual static bool acceptFile(const std::string &filename);
virtual bool isDirectory(const std::string &path);
private:
#ifndef _WIN32
void recursiveAddFiles2(std::vector<std::string> &relative,

View File

@ -205,4 +205,9 @@ bool FileListerWin32::sameFileName(const std::string &fname1, const std::string
#endif
}
bool FileListerWin32::isDirectory(const std::string &path)
{
return (MyIsDirectory(path) != FALSE);
}
#endif // _WIN32

View File

@ -32,6 +32,7 @@ class FileListerWin32 : public FileLister
public:
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path);
virtual bool sameFileName(const std::string &fname1, const std::string &fname2);
virtual bool isDirectory(const std::string &path);
private:
};