Merge pull request #126 from SimonKagstrom/for-upstream
Misc fixes for the --include= option
This commit is contained in:
commit
8491df31ca
|
@ -420,7 +420,6 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
path = Path::fromNativeSeparators(path);
|
path = Path::fromNativeSeparators(path);
|
||||||
|
|
||||||
_settings->userIncludes.push_back(path);
|
_settings->userIncludes.push_back(path);
|
||||||
_settings->userDefines += ";";
|
|
||||||
} else if (std::strncmp(argv[i], "--includes-file=", 16) == 0) {
|
} else if (std::strncmp(argv[i], "--includes-file=", 16) == 0) {
|
||||||
// open this file and read every input file (1 file name per line)
|
// open this file and read every input file (1 file name per line)
|
||||||
AddInclPathsToList(16 + argv[i], _settings->_includePaths);
|
AddInclPathsToList(16 + argv[i], _settings->_includePaths);
|
||||||
|
@ -780,9 +779,11 @@ void CmdLineParser::PrintHelp()
|
||||||
" files first. If paths are relative to source files,\n"
|
" files first. If paths are relative to source files,\n"
|
||||||
" this is not needed.\n"
|
" this is not needed.\n"
|
||||||
" --include=<file>\n"
|
" --include=<file>\n"
|
||||||
" Force inclusion of a file. Can be used for example when\n"
|
" Force inclusion of a file before the checked file. Can\n"
|
||||||
" checking the Linux kernel, where autoconf.h needs to be\n"
|
" be used for example when checking the Linux kernel,\n"
|
||||||
" included for every file compiled.\n"
|
" where autoconf.h needs to be included for every file\n"
|
||||||
|
" compiled. Works the same way as the GCC -include"
|
||||||
|
" option.\n"
|
||||||
" -i <dir or file> Give a source file or source file directory to exclude\n"
|
" -i <dir or file> Give a source file or source file directory to exclude\n"
|
||||||
" from the check. This applies only to source files so\n"
|
" from the check. This applies only to source files so\n"
|
||||||
" header files included by source files are not matched.\n"
|
" header files included by source files are not matched.\n"
|
||||||
|
|
13
lib/path.cpp
13
lib/path.cpp
|
@ -104,6 +104,19 @@ std::string Path::simplifyPath(const char *originalPath)
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Path::getPathFromFilename(const std::string &filename)
|
||||||
|
{
|
||||||
|
std::string path = "";
|
||||||
|
|
||||||
|
std::size_t pos = filename.find_last_of("\\/");
|
||||||
|
|
||||||
|
if (pos != std::string::npos)
|
||||||
|
path = filename.substr(0, 1 + pos);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Path::sameFileName(const std::string &fname1, const std::string &fname2)
|
bool Path::sameFileName(const std::string &fname1, const std::string &fname2)
|
||||||
{
|
{
|
||||||
#if defined(__linux__) || defined(__sun) || defined(__hpux)
|
#if defined(__linux__) || defined(__sun) || defined(__hpux)
|
||||||
|
|
|
@ -56,6 +56,13 @@ public:
|
||||||
*/
|
*/
|
||||||
static std::string simplifyPath(const char *originalPath);
|
static std::string simplifyPath(const char *originalPath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Lookup the path part from a filename (e.g., '/tmp/a.h' -> '/tmp/', 'a.h' -> '')
|
||||||
|
* @param filename filename to lookup, must have / -separators.
|
||||||
|
* @return path part of the filename
|
||||||
|
*/
|
||||||
|
static std::string getPathFromFilename(const std::string &filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compare filenames to see if they are the same.
|
* @brief Compare filenames to see if they are the same.
|
||||||
* On Linux the comparison is case-sensitive. On Windows it is case-insensitive.
|
* On Linux the comparison is case-sensitive. On Windows it is case-insensitive.
|
||||||
|
|
|
@ -815,15 +815,8 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe
|
||||||
fin.open(cur.c_str());
|
fin.open(cur.c_str());
|
||||||
if (!fin.is_open()) {
|
if (!fin.is_open()) {
|
||||||
if (_settings && !_settings->nomsg.isSuppressed("missingInclude", cur, 1)) {
|
if (_settings && !_settings->nomsg.isSuppressed("missingInclude", cur, 1)) {
|
||||||
std::string path = "";
|
|
||||||
|
|
||||||
std::size_t pos = cur.find_last_of("\\/");
|
|
||||||
|
|
||||||
if (pos != std::string::npos)
|
|
||||||
path = cur.substr(0, 1 + pos);
|
|
||||||
|
|
||||||
missingIncludeFlag = true;
|
missingIncludeFlag = true;
|
||||||
missingInclude(Path::toNativeSeparators(path),
|
missingInclude(Path::toNativeSeparators(Path::getPathFromFilename(cur)),
|
||||||
1,
|
1,
|
||||||
cur,
|
cur,
|
||||||
true);
|
true);
|
||||||
|
@ -834,7 +827,6 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe
|
||||||
|
|
||||||
fin.close();
|
fin.close();
|
||||||
|
|
||||||
//handleIncludes("#include \"" + cur + "\"\n", cur, includePaths, defs);
|
|
||||||
forcedIncludes =
|
forcedIncludes =
|
||||||
forcedIncludes +
|
forcedIncludes +
|
||||||
"#file \"" + cur + "\"\n" +
|
"#file \"" + cur + "\"\n" +
|
||||||
|
@ -2131,7 +2123,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
// filename contains now a file name e.g. "menu.h"
|
// filename contains now a file name e.g. "menu.h"
|
||||||
std::string processedFile;
|
std::string processedFile;
|
||||||
std::string filepath;
|
std::string filepath;
|
||||||
if (headerType == UserHeader)
|
if (headerType == UserHeader && !paths.empty())
|
||||||
filepath = paths.back();
|
filepath = paths.back();
|
||||||
std::ifstream fin;
|
std::ifstream fin;
|
||||||
const bool fileOpened(openHeader(filename, includePaths, filepath, fin));
|
const bool fileOpened(openHeader(filename, includePaths, filepath, fin));
|
||||||
|
|
|
@ -33,6 +33,7 @@ private:
|
||||||
TEST_CASE(getRelative);
|
TEST_CASE(getRelative);
|
||||||
TEST_CASE(is_c);
|
TEST_CASE(is_c);
|
||||||
TEST_CASE(is_cpp);
|
TEST_CASE(is_cpp);
|
||||||
|
TEST_CASE(get_path_from_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplify_path() const {
|
void simplify_path() const {
|
||||||
|
@ -117,6 +118,13 @@ private:
|
||||||
ASSERT(Path::isCPP("C:\\foo\\index.cpp"));
|
ASSERT(Path::isCPP("C:\\foo\\index.cpp"));
|
||||||
ASSERT(Path::isCPP("C:\\foo\\index.Cpp"));
|
ASSERT(Path::isCPP("C:\\foo\\index.Cpp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_path_from_filename() const {
|
||||||
|
ASSERT_EQUALS("", Path::getPathFromFilename("index.h"));
|
||||||
|
ASSERT_EQUALS("/tmp/", Path::getPathFromFilename("/tmp/index.h"));
|
||||||
|
ASSERT_EQUALS("a/b/c/", Path::getPathFromFilename("a/b/c/index.h"));
|
||||||
|
ASSERT_EQUALS("a/b/c/", Path::getPathFromFilename("a/b/c/"));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestPath)
|
REGISTER_TEST(TestPath)
|
||||||
|
|
Loading…
Reference in New Issue