GUI: Select parser; Cppcheck or Clang

This commit is contained in:
Daniel Marjamäki 2020-02-02 10:45:42 +01:00
parent 103ecb0257
commit 632dc0f141
9 changed files with 55 additions and 4 deletions

View File

@ -921,8 +921,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
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";
std::ofstream fout1(mSettings->buildDir + "/__temp__.c");
fout1 << "int x;\n";
std::ofstream fout2(mSettings->buildDir + "/__temp__.cpp");
fout2 << "int x;\n";
}

View File

@ -839,6 +839,8 @@ Settings MainWindow::getCppcheckSettings()
result.userDefines += define.toStdString();
}
result.clang = mProjectFile->clangParser;
const QStringList undefines = mProjectFile->getUndefines();
foreach (QString undefine, undefines)
result.userUndefs.insert(undefine.toStdString());

View File

@ -45,6 +45,7 @@ ProjectFile::ProjectFile(const QString &filename, QObject *parent) :
void ProjectFile::clear()
{
clangParser = false;
mRootPath.clear();
mBuildDir.clear();
mImportProject.clear();
@ -111,6 +112,9 @@ bool ProjectFile::read(const QString &filename)
if (xmlReader.name() == CppcheckXml::AnalyzeAllVsConfigsElementName)
mAnalyzeAllVsConfigs = readBool(xmlReader);
if (xmlReader.name() == CppcheckXml::Parser)
clangParser = true;
if (xmlReader.name() == CppcheckXml::CheckHeadersElementName)
mCheckHeaders = readBool(xmlReader);
@ -709,6 +713,12 @@ bool ProjectFile::write(const QString &filename)
xmlWriter.writeCharacters(mAnalyzeAllVsConfigs ? "true" : "false");
xmlWriter.writeEndElement();
if (clangParser) {
xmlWriter.writeStartElement(CppcheckXml::Parser);
xmlWriter.writeCharacters("clang");
xmlWriter.writeEndElement();
}
xmlWriter.writeStartElement(CppcheckXml::CheckHeadersElementName);
xmlWriter.writeCharacters(mCheckHeaders ? "true" : "false");
xmlWriter.writeEndElement();

View File

@ -363,6 +363,9 @@ public:
mCheckUnknownFunctionReturn = s;
}
/** Use Clang parser */
bool clangParser;
protected:
/**

View File

@ -260,6 +260,10 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
mUI.mCheckHeaders->setChecked(projectFile->getCheckHeaders());
mUI.mCheckUnusedTemplates->setChecked(projectFile->getCheckUnusedTemplates());
mUI.mMaxCtuDepth->setValue(projectFile->getMaxCtuDepth());
if (projectFile->clangParser)
mUI.mBtnClangParser->setChecked(true);
else
mUI.mBtnCppcheckParser->setChecked(true);
setExcludedPaths(projectFile->getExcludedPaths());
setLibraries(projectFile->getLibraries());
const QString platform = projectFile->getPlatform();
@ -361,6 +365,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
projectFile->setCheckPaths(getCheckPaths());
projectFile->setExcludedPaths(getExcludedPaths());
projectFile->setLibraries(getLibraries());
projectFile->clangParser = mUI.mBtnClangParser->isChecked();
if (mUI.mComboBoxPlatform->currentText().endsWith(".xml"))
projectFile->setPlatform(mUI.mComboBoxPlatform->currentText());
else {

View File

@ -344,6 +344,32 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_10">
<property name="title">
<string>Parser</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<widget class="QRadioButton" name="mBtnCppcheckParser">
<property name="text">
<string>Cppcheck (built in)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mBtnClangParser">
<property name="text">
<string>Clang</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">

View File

@ -254,14 +254,14 @@ 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 temp = mSettings.buildDir + (Path::isCPP(path) ? "/__temp__.cpp" : "/__temp__.c");
const std::string clangcmd = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, "") + ".clang-cmd";
const std::string clangStderr = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, "") + ".clang-stderr";
const std::string cmd1 = clang + " -v -fsyntax-only " + temp + " 2>&1";
const std::pair<bool, std::string> &result1 = executeCommand(cmd1);
if (!result1.first || result1.second.find(" -cc1 ") == std::string::npos) {
std::cerr << "Failed to execute '" + cmd1 + "'" << std::endl;
mErrorLogger.reportOut("Failed to execute '" + cmd1 + "':" + result1.second);
return 0;
}
std::istringstream details(result1.second);

View File

@ -1039,6 +1039,8 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
guiProject.platform = node->GetText();
else if (strcmp(node->Name(), CppcheckXml::AnalyzeAllVsConfigsElementName) == 0)
guiProject.analyzeAllVsConfigs = node->GetText();
else if (strcmp(node->Name(), CppcheckXml::Parser) == 0)
temp.clang = true;
else if (strcmp(node->Name(), CppcheckXml::AddonsElementName) == 0)
temp.addons = readXmlStringList(node, "", CppcheckXml::AddonElementName, nullptr);
else if (strcmp(node->Name(), CppcheckXml::TagsElementName) == 0)

View File

@ -122,6 +122,7 @@ namespace CppcheckXml {
const char BuildDirElementName[] = "builddir";
const char ImportProjectElementName[] = "importproject";
const char AnalyzeAllVsConfigsElementName[] = "analyze-all-vs-configs";
const char Parser[] = "parser";
const char IncludeDirElementName[] = "includedir";
const char DirElementName[] = "dir";
const char DirNameAttrib[] = "name";