Pass defines flags when calling clang (#2651)

This commit is contained in:
Ken-Patrick Lehrmann 2020-05-20 14:56:55 +02:00 committed by GitHub
parent 5a0b5139a0
commit 79d3f488da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -233,6 +233,14 @@ static std::string executeAddon(const AddonInfo &addonInfo,
return result;
}
static std::string getDefinesFlags(const std::string &semicolonSeparatedString)
{
std::string flags;
for (const std::string &d: split(semicolonSeparatedString, ";"))
flags += "-D" + d + " ";
return flags;
}
CppCheck::CppCheck(ErrorLogger &errorLogger,
bool useGlobalSuppressions,
std::function<bool(std::string,std::vector<std::string>,std::string,std::string*)> executeCommand)
@ -350,6 +358,9 @@ unsigned int CppCheck::check(const std::string &path)
for (const std::string &i: mSettings.includePaths)
flags += "-I" + i + " ";
flags += getDefinesFlags(mSettings.userDefines);
const std::string args2 = "-cc1 -ast-dump " + flags + path;
const std::string redirect2 = analyzerInfo.empty() ? std::string("2>&1") : ("2> " + clangStderr);
if (!mSettings.buildDir.empty()) {
@ -1407,16 +1418,11 @@ void CppCheck::getErrorMessages()
void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings)
{
std::string allIncludes = "";
std::string allDefines = "-D"+fileSettings.defines;
for (const std::string &inc : fileSettings.includePaths) {
allIncludes = allIncludes + "-I\"" + inc + "\" ";
}
std::string::size_type pos = 0u;
while ((pos = allDefines.find(";", pos)) != std::string::npos) {
allDefines.replace(pos, 1, " -D");
pos += 3;
}
const std::string allDefines = getDefinesFlags(fileSettings.defines);
#ifdef _WIN32
const char exe[] = "clang-tidy.exe";