Fixed #2409 (print a warning if provided path (commandline option -I [PATH]) does not exist)
This commit is contained in:
parent
68beffca04
commit
d316f6005f
|
@ -233,7 +233,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include paths
|
// 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;
|
std::string path;
|
||||||
|
|
||||||
|
@ -252,8 +252,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
// "-Ipath/"
|
// "-Ipath/"
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
path = argv[i];
|
path = 2 + argv[i];
|
||||||
path = path.substr(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If path doesn't end with / or \, add it
|
// If path doesn't end with / or \, add it
|
||||||
|
|
|
@ -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> pathnames = parser.GetPathNames();
|
||||||
std::vector<std::string> filenames;
|
std::vector<std::string> filenames;
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool acceptFile(const std::string &filename);
|
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) */
|
/** @brief get filelister (platform dependent implementation) */
|
||||||
|
|
|
@ -103,4 +103,23 @@ bool FileListerUnix::sameFileName(const std::string &fname1, const std::string &
|
||||||
#endif
|
#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
|
#endif // _WIN32
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path);
|
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 sameFileName(const std::string &fname1, const std::string &fname2);
|
||||||
// virtual static bool acceptFile(const std::string &filename);
|
// virtual static bool acceptFile(const std::string &filename);
|
||||||
|
virtual bool isDirectory(const std::string &path);
|
||||||
private:
|
private:
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
void recursiveAddFiles2(std::vector<std::string> &relative,
|
void recursiveAddFiles2(std::vector<std::string> &relative,
|
||||||
|
|
|
@ -205,4 +205,9 @@ bool FileListerWin32::sameFileName(const std::string &fname1, const std::string
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileListerWin32::isDirectory(const std::string &path)
|
||||||
|
{
|
||||||
|
return (MyIsDirectory(path) != FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
|
@ -32,6 +32,7 @@ class FileListerWin32 : public FileLister
|
||||||
public:
|
public:
|
||||||
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path);
|
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 sameFileName(const std::string &fname1, const std::string &fname2);
|
||||||
|
virtual bool isDirectory(const std::string &path);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue