--clang; require that --cppcheck-build-dir. output files are needed.

This commit is contained in:
Daniel Marjamäki 2020-01-19 12:33:17 +01:00
parent 7d4bd57cc5
commit 0eccffe8e3
2 changed files with 14 additions and 5 deletions

View File

@ -916,6 +916,16 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
}
}
if (mSettings->clang) {
if (mSettings->buildDir.empty()) {
printMessage("If --clang is used then --cppcheck-build-dir must be specified also");
return false;
}
std::ofstream fout(mSettings->buildDir + "/__temp__.c");
fout << "int x;\n";
}
// Default template format..
if (mSettings->templateFormat.empty()) {
mSettings->templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\\n{code}";

View File

@ -254,12 +254,11 @@ unsigned int CppCheck::check(const std::string &path)
mErrorLogger.reportOut(std::string("Checking ") + path + "...");
const std::string clang = Path::isCPP(path) ? "clang++" : "clang";
const std::string temp = mSettings.buildDir + "/__temp__.c";
const std::string stderr = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, "") + ".clang-stderr";
/* Experimental: import clang ast dump */
std::ofstream fout("__temp__.c");
fout << "int x;\n";
fout.close();
const std::string cmd1 = clang + " -v -fsyntax-only __temp__.c 2>&1";
const std::string cmd1 = clang + " -v -fsyntax-only " + temp + " 2>&1";
const std::pair<bool, std::string> res1 = executeCommand(cmd1);
if (!res1.first) {
std::cerr << "Failed to execute '" + cmd1 + "'" << std::endl;
@ -285,7 +284,7 @@ unsigned int CppCheck::check(const std::string &path)
for (const std::string &i: mSettings.includePaths)
flags += "-I" + i + " ";
const std::string cmd = clang + " -cc1 -ast-dump " + flags + path;
const std::string cmd = clang + " -cc1 -ast-dump " + flags + path + " 2> " + stderr;
std::pair<bool, std::string> res = executeCommand(cmd);
if (!res.first) {
std::cerr << "Failed to execute '" + cmd + "'" << std::endl;