GUI: Allow that platform is selected in project dialog

This commit is contained in:
Daniel Marjamäki 2018-03-13 13:07:10 +01:00
parent af4181f4d1
commit 9800e82d13
6 changed files with 376 additions and 211 deletions

View File

@ -850,6 +850,21 @@ Settings MainWindow::getCppcheckSettings()
result.buildDir = (prjpath + '/' + buildDir).toStdString();
}
}
const QString platform = mProjectFile->getPlatform();
if (platform.endsWith(".xml")) {
const QString applicationFilePath = QCoreApplication::applicationFilePath();
const QString appPath = QFileInfo(applicationFilePath).canonicalPath();
result.loadPlatformFile(appPath.toStdString().c_str(), platform.toStdString());
} else {
for (int i = cppcheck::Platform::Native; i <= cppcheck::Platform::Unix64; i++) {
const cppcheck::Platform::PlatformType p = (cppcheck::Platform::PlatformType)i;
if (platform == cppcheck::Platform::platformString(p)) {
result.platform(p);
break;
}
}
}
}
// Include directories (and files) are searched in listed order.
@ -878,7 +893,8 @@ Settings MainWindow::getCppcheckSettings()
result.jobs = mSettings->value(SETTINGS_CHECK_THREADS, 1).toInt();
result.inlineSuppressions = mSettings->value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool();
result.inconclusive = mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool();
result.platformType = (Settings::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
if (result.platformType == cppcheck::Platform::Unspecified)
result.platform((cppcheck::Platform::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
if (mSettings->value(SETTINGS_STD_CPP03, false).toBool())
result.standards.cpp = Standards::CPP03;
else if (mSettings->value(SETTINGS_STD_CPP11, false).toBool())
@ -894,7 +910,7 @@ Settings MainWindow::getCppcheckSettings()
if (result.standards.posix)
posix = tryLoadLibrary(&result.library, "posix.cfg");
bool windows = true;
if (result.platformType == Settings::Win32A || result.platformType == Settings::Win32W || result.platformType == Settings::Win64)
if (result.isWindowsPlatform())
windows = tryLoadLibrary(&result.library, "windows.cfg");
if (!std || !posix || !windows)

View File

@ -50,6 +50,7 @@ static const char ExcludePathName[] = "path";
static const char ExcludePathNameAttrib[] = "name";
static const char LibrariesElementName[] = "libraries";
static const char LibraryElementName[] = "library";
static const char PlatformElementName[] = "platform";
static const char SuppressionsElementName[] = "suppressions";
static const char SuppressionElementName[] = "suppression";
static const char AddonElementName[] = "addon";
@ -84,6 +85,7 @@ void ProjectFile::clear()
mPaths.clear();
mExcludedPaths.clear();
mLibraries.clear();
mPlatform.clear();
mSuppressions.clear();
mAddons.clear();
mClangAnalyzer = mClangTidy = false;
@ -149,6 +151,9 @@ bool ProjectFile::read(const QString &filename)
if (insideProject && xmlReader.name() == LibrariesElementName)
readStringList(mLibraries, xmlReader,LibraryElementName);
if (insideProject && xmlReader.name() == PlatformElementName)
readPlatform(xmlReader);
// Find suppressions list from inside project element
if (insideProject && xmlReader.name() == SuppressionsElementName)
readStringList(mSuppressions, xmlReader,SuppressionElementName);
@ -434,6 +439,30 @@ void ProjectFile::readExcludes(QXmlStreamReader &reader)
} while (!allRead);
}
void ProjectFile::readPlatform(QXmlStreamReader &reader)
{
do {
const QXmlStreamReader::TokenType type = reader.readNext();
switch (type) {
case QXmlStreamReader::Characters:
mPlatform = reader.text().toString();
case QXmlStreamReader::EndElement:
return;
// Not handled
case QXmlStreamReader::StartElement:
case QXmlStreamReader::NoToken:
case QXmlStreamReader::Invalid:
case QXmlStreamReader::StartDocument:
case QXmlStreamReader::EndDocument:
case QXmlStreamReader::Comment:
case QXmlStreamReader::DTD:
case QXmlStreamReader::EntityReference:
case QXmlStreamReader::ProcessingInstruction:
break;
}
} while (1);
}
void ProjectFile::readStringList(QStringList &stringlist, QXmlStreamReader &reader, const char elementname[])
{
@ -498,6 +527,11 @@ void ProjectFile::setLibraries(const QStringList &libraries)
mLibraries = libraries;
}
void ProjectFile::setPlatform(const QString &platform)
{
mPlatform = platform;
}
void ProjectFile::setSuppressions(const QStringList &suppressions)
{
mSuppressions = suppressions;
@ -535,6 +569,12 @@ bool ProjectFile::write(const QString &filename)
xmlWriter.writeEndElement();
}
if (!mPlatform.isEmpty()) {
xmlWriter.writeStartElement(PlatformElementName);
xmlWriter.writeCharacters(mPlatform);
xmlWriter.writeEndElement();
}
if (!mImportProject.isEmpty()) {
xmlWriter.writeStartElement(ImportProjectElementName);
xmlWriter.writeCharacters(mImportProject);

View File

@ -106,6 +106,14 @@ public:
return mLibraries;
}
/**
* @brief Get platform.
* @return Current platform. If it ends with .xml then it is a file. Otherwise it must match one of the return values from @sa cppcheck::Platform::platformString() ("win32A", "unix32", ..)
*/
QString getPlatform() const {
return mPlatform;
}
/**
* @brief Get list suppressions.
* @return list of suppressions.
@ -206,6 +214,12 @@ public:
*/
void setLibraries(const QStringList &libraries);
/**
* @brief Set platform.
* @param platform platform.
*/
void setPlatform(const QString &platform);
/**
* @brief Set list of suppressions.
* @param suppressions List of suppressions.
@ -282,6 +296,12 @@ protected:
*/
void readExcludes(QXmlStreamReader &reader);
/**
* @brief Read platform text.
* @param reader XML stream reader.
*/
void readPlatform(QXmlStreamReader &reader);
/**
* @brief Read string list
* @param stringlist destination string list
@ -359,6 +379,11 @@ private:
*/
QStringList mLibraries;
/**
* @brief Platform
*/
QString mPlatform;
/**
* @brief List of suppressions.
*/

View File

@ -33,6 +33,19 @@
#include "library.h"
#include "cppcheck.h"
#include "errorlogger.h"
#include "platforms.h"
/** Platforms shown in the platform combobox */
static const cppcheck::Platform::PlatformType builtinPlatforms[] = {
cppcheck::Platform::Native,
cppcheck::Platform::Win32A,
cppcheck::Platform::Win32W,
cppcheck::Platform::Win64,
cppcheck::Platform::Unix32,
cppcheck::Platform::Unix64
};
static const int numberOfBuiltinPlatforms = sizeof(builtinPlatforms) / sizeof(builtinPlatforms[0]);
ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent)
: QDialog(parent)
@ -94,6 +107,32 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent)
mLibraryCheckboxes << checkbox;
}
// Platforms..
Platforms p;
for (int i = 0; i < numberOfBuiltinPlatforms; i++)
mUI.mComboBoxPlatform->addItem(p.get(builtinPlatforms[i]).mTitle);
QStringList platformFiles;
foreach (QString sp, searchPaths) {
if (sp.endsWith("/cfg"))
sp = sp.mid(0,sp.length()-3) + "platforms";
QDir dir(sp);
dir.setSorting(QDir::Name);
dir.setNameFilters(QStringList("*.xml"));
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
foreach (QFileInfo item, dir.entryInfoList()) {
const QString platformFile = item.fileName();
cppcheck::Platform p;
if (!p.loadPlatformFile(appPath.toStdString().c_str(), platformFile.toStdString()))
continue;
if (platformFiles.indexOf(platformFile) == -1)
platformFiles << platformFile;
}
}
qSort(platformFiles);
mUI.mComboBoxPlatform->addItems(platformFiles);
mUI.mEditTags->setValidator(new QRegExpValidator(QRegExp("[a-zA-Z0-9 ;]*"),this));
connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &ProjectFileDialog::ok);
@ -156,6 +195,33 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
mUI.mChkAllVsConfigs->setChecked(projectFile->getAnalyzeAllVsConfigs());
setExcludedPaths(projectFile->getExcludedPaths());
setLibraries(projectFile->getLibraries());
const QString platform = projectFile->getPlatform();
if (platform.endsWith(".xml")) {
int i;
for (i = numberOfBuiltinPlatforms; i < mUI.mComboBoxPlatform->count(); ++i) {
if (mUI.mComboBoxPlatform->itemText(i) == platform)
break;
}
if (i < mUI.mComboBoxPlatform->count())
mUI.mComboBoxPlatform->setCurrentIndex(i);
else {
mUI.mComboBoxPlatform->addItem(platform);
mUI.mComboBoxPlatform->setCurrentIndex(i);
}
} else {
int i;
for (i = 0; i < numberOfBuiltinPlatforms; ++i) {
const cppcheck::Platform::PlatformType p = builtinPlatforms[i];
if (platform == cppcheck::Platform::platformString(p))
break;
}
if (i < numberOfBuiltinPlatforms)
mUI.mComboBoxPlatform->setCurrentIndex(i);
else
mUI.mComboBoxPlatform->setCurrentIndex(-1);
}
mUI.mComboBoxPlatform->setCurrentText(projectFile->getPlatform());
setSuppressions(projectFile->getSuppressions());
QSettings settings;
@ -193,6 +259,15 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
projectFile->setCheckPaths(getCheckPaths());
projectFile->setExcludedPaths(getExcludedPaths());
projectFile->setLibraries(getLibraries());
if (mUI.mComboBoxPlatform->currentText().endsWith(".xml"))
projectFile->setPlatform(mUI.mComboBoxPlatform->currentText());
else {
int i = mUI.mComboBoxPlatform->currentIndex();
if (i < numberOfBuiltinPlatforms)
projectFile->setPlatform(cppcheck::Platform::platformString(builtinPlatforms[i]));
else
projectFile->setPlatform(QString());
}
projectFile->setSuppressions(getSuppressions());
QStringList list;
if (mUI.mAddonThreadSafety->isChecked())

View File

@ -268,35 +268,11 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="mTabProject">
<widget class="QWidget" name="mTabChecking">
<attribute name="title">
<string>Project</string>
<string>Checking</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Root path:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
<item>
<widget class="QLineEdit" name="mEditProjectRoot"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Warning tags (separated by semicolon)</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="mEditTags"/>
</item>
</layout>
</widget>
</item>
<layout class="QVBoxLayout" name="verticalLayout_15">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
@ -316,6 +292,18 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Platform</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<widget class="QComboBox" name="mComboBoxPlatform"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
@ -339,7 +327,7 @@
</widget>
</item>
<item>
<spacer name="verticalSpacer_9">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -353,20 +341,41 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="mTabExclude">
<widget class="QWidget" name="mTabWarningOptions">
<attribute name="title">
<string>Exclude</string>
<string>Warning options</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_9">
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QLabel" name="labelExcludePaths">
<property name="text">
<string>Paths:</string>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Root path:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
<item>
<widget class="QLineEdit" name="mEditProjectRoot"/>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layoutExcludePaths">
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Warning tags (separated by semicolon)</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="mEditTags"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>Exclude paths</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QListWidget" name="mListExcludedPaths"/>
</item>
@ -409,39 +418,19 @@
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="mTabSuppressions">
<attribute name="title">
<string>Suppressions</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
</item>
<item>
<widget class="QLabel" name="labelSuppressions">
<property name="text">
<string>Suppression list:</string>
<widget class="QGroupBox" name="groupBox_8">
<property name="title">
<string>Suppressions</string>
</property>
</widget>
</item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QListWidget" name="mListSuppressions"/>
</item>
<item>
<layout class="QHBoxLayout" name="layoutSuppressionButtons">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QPushButton" name="mBtnAddSuppression">
<property name="text">
@ -456,15 +445,50 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_10">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="mTabAddons">
</item>
<item>
<spacer name="verticalSpacer_9">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>96</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="mTabAddonsAndTools">
<attribute name="title">
<string>Addons</string>
<string>Addons and tools</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QGroupBox" name="mGroupBoxAddons">
<property name="title">
<string>Addons</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="mAddonY2038">
<property name="text">
@ -500,30 +524,19 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>368</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="mTabTools">
<attribute name="title">
<string>Extra Tools</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_12">
</item>
<item>
<widget class="QLabel" name="label_3">
<widget class="QGroupBox" name="mGroupBoxTools">
<property name="title">
<string>External tools</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="mToolClangTidy">
<property name="text">
<string>It is common best practice to use several tools.</string>
<string>Clang-tidy</string>
</property>
</widget>
</item>
@ -534,22 +547,18 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mToolClangTidy">
<property name="text">
<string>Clang-tidy</string>
</property>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_7">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>310</height>
<height>368</height>
</size>
</property>
</spacer>
@ -572,10 +581,6 @@
</widget>
<tabstops>
<tabstop>mButtons</tabstop>
<tabstop>mListExcludedPaths</tabstop>
<tabstop>mBtnAddIgnorePath</tabstop>
<tabstop>mBtnEditIgnorePath</tabstop>
<tabstop>mBtnRemoveIgnorePath</tabstop>
</tabstops>
<resources/>
<connections>

View File

@ -122,7 +122,11 @@ namespace cppcheck {
}
const char *platformString() const {
switch (platformType) {
return platformString(platformType);
}
static const char *platformString(PlatformType pt) {
switch (pt) {
case Unspecified:
return "Unspecified";
case Native: