Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/selfcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
- name: Self check (unusedFunction / no test / no gui)
run: |
supprs="--suppress=unusedFunction:lib/errorlogger.h:197 --suppress=unusedFunction:lib/importproject.cpp:1660 --suppress=unusedFunction:lib/importproject.cpp:1684"
supprs="--suppress=unusedFunction:lib/errorlogger.h:197 --suppress=unusedFunction:lib/importproject.cpp:1665 --suppress=unusedFunction:lib/importproject.cpp:1689"
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr $supprs
env:
DISABLE_VALUEFLOW: 1
Expand Down
2 changes: 2 additions & 0 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,8 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
for (const QString& undefine : undefines)
settings.userUndefs.insert(undefine.toStdString());

settings.userIncludes.push_back(mProjectFile->getUserInclude().toStdString());

const QStringList libraries = mProjectFile->getLibraries();
for (const QString& library : libraries) {
settings.libraries.emplace_back(library.toStdString());
Expand Down
22 changes: 14 additions & 8 deletions gui/projectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void ProjectFile::clear()
mIncludeDirs.clear();
mDefines.clear();
mUndefines.clear();
mUserInclude.clear();
mPaths.clear();
mExcludedPaths.clear();
mLibraries.clear();
Expand Down Expand Up @@ -166,6 +167,9 @@ bool ProjectFile::read(const QString &filename)
if (xmlReader.name() == QString(CppcheckXml::UndefinesElementName))
readStringList(mUndefines, xmlReader, CppcheckXml::UndefineName);

if (xmlReader.name() == QString(CppcheckXml::UserIncludeElementName))
mUserInclude = readString(xmlReader);

// Find exclude list from inside project element
if (xmlReader.name() == QString(CppcheckXml::ExcludeElementName))
readExcludes(xmlReader);
Expand Down Expand Up @@ -347,15 +351,13 @@ bool ProjectFile::readBool(QXmlStreamReader &reader)

int ProjectFile::readInt(QXmlStreamReader &reader, int defaultValue)
{
int ret = defaultValue;
do {
const QXmlStreamReader::TokenType type = reader.readNext();
switch (type) {
case QXmlStreamReader::Characters:
ret = reader.text().toString().toInt();
FALLTHROUGH;
return reader.text().toString().toInt();
case QXmlStreamReader::EndElement:
return ret;
return defaultValue;
// Not handled
case QXmlStreamReader::StartElement:
case QXmlStreamReader::NoToken:
Expand All @@ -373,15 +375,13 @@ int ProjectFile::readInt(QXmlStreamReader &reader, int defaultValue)

QString ProjectFile::readString(QXmlStreamReader &reader)
{
QString ret;
do {
const QXmlStreamReader::TokenType type = reader.readNext();
switch (type) {
case QXmlStreamReader::Characters:
ret = reader.text().toString();
FALLTHROUGH;
return reader.text().toString();
case QXmlStreamReader::EndElement:
return ret;
return {};
// Not handled
case QXmlStreamReader::StartElement:
case QXmlStreamReader::NoToken:
Expand Down Expand Up @@ -910,6 +910,12 @@ bool ProjectFile::write(const QString &filename)
xmlWriter.writeEndElement();
}

if (!mUserInclude.isEmpty()) {
xmlWriter.writeStartElement(CppcheckXml::UserIncludeElementName);
xmlWriter.writeCharacters(mUserInclude);
xmlWriter.writeEndElement();
}

if (!mVsConfigurations.isEmpty()) {
writeStringList(xmlWriter,
mVsConfigurations,
Expand Down
11 changes: 11 additions & 0 deletions gui/projectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ class ProjectFile : public QObject {
return mUndefines;
}

const QString& getUserInclude() const {
return mUserInclude;
}

void setUserInclude(const QString& userInclude) {
mUserInclude = userInclude;
}

/**
* @brief Get list of paths to check.
* @return list of paths.
Expand Down Expand Up @@ -601,6 +609,9 @@ class ProjectFile : public QObject {
*/
QStringList mUndefines;

/** @brief --include file */
QString mUserInclude;

/**
* @brief List of paths to check.
*/
Expand Down
68 changes: 48 additions & 20 deletions gui/projectfile.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>940</width>
<height>701</height>
<height>741</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -80,7 +80,7 @@
<item>
<spacer name="verticalSpacer_11">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -95,7 +95,7 @@
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -117,7 +117,7 @@
<item>
<spacer name="verticalSpacer_12">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -151,7 +151,7 @@
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -199,7 +199,7 @@
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -269,7 +269,7 @@
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -284,7 +284,7 @@
<item>
<widget class="QListWidget" name="mListIncludeDirs">
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
<enum>QAbstractItemView::SelectionBehavior::SelectRows</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -314,7 +314,7 @@
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -342,10 +342,38 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="mLayoutDefines_2">
<item>
<widget class="QLabel" name="mLabelDefines_2">
<property name="text">
<string>Include file</string>
</property>
<property name="buddy">
<cstring>mEditUserInclude</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mEditUserInclude">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-family:'monospace'; color:#000000; background-color:#ffffff;&quot;&gt;Force inclusion of a header file&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mBtnBrowseUserInclude">
<property name="text">
<string>Browse..</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -552,7 +580,7 @@
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -586,7 +614,7 @@
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -701,7 +729,7 @@
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -744,7 +772,7 @@
<item>
<spacer name="verticalSpacer_10">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -769,7 +797,7 @@
<item>
<spacer name="verticalSpacer_9">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -856,7 +884,7 @@
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -919,7 +947,7 @@
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -1018,7 +1046,7 @@
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -1035,10 +1063,10 @@
<item>
<widget class="QDialogButtonBox" name="mButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
Expand Down
18 changes: 18 additions & 0 deletions gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
connect(mUI->mBtnBrowseBuildDir, &QPushButton::clicked, this, &ProjectFileDialog::browseBuildDir);
connect(mUI->mBtnClearImportProject, &QPushButton::clicked, this, &ProjectFileDialog::clearImportProject);
connect(mUI->mBtnBrowseImportProject, &QPushButton::clicked, this, &ProjectFileDialog::browseImportProject);
connect(mUI->mBtnBrowseUserInclude, &QPushButton::clicked, this, &ProjectFileDialog::browseUserInclude);
connect(mUI->mBtnAddCheckPath, SIGNAL(clicked()), this, SLOT(addCheckPath()));
connect(mUI->mBtnEditCheckPath, &QPushButton::clicked, this, &ProjectFileDialog::editCheckPath);
connect(mUI->mBtnRemoveCheckPath, &QPushButton::clicked, this, &ProjectFileDialog::removeCheckPath);
Expand Down Expand Up @@ -303,6 +304,7 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
setIncludepaths(projectFile->getIncludeDirs());
setDefines(projectFile->getDefines());
setUndefines(projectFile->getUndefines());
mUI->mEditUserInclude->setText(projectFile->getUserInclude());
setCheckPaths(projectFile->getCheckPaths());
setImportProject(projectFile->getImportProject());
mUI->mChkAllVsConfigs->setChecked(projectFile->getAnalyzeAllVsConfigs());
Expand Down Expand Up @@ -481,6 +483,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
projectFile->setIncludes(getIncludePaths());
projectFile->setDefines(getDefines());
projectFile->setUndefines(getUndefines());
projectFile->setUserInclude(mUI->mEditUserInclude->text());
projectFile->setCheckPaths(getCheckPaths());
projectFile->setExcludedPaths(getExcludedPaths());
projectFile->setLibraries(getLibraries());
Expand Down Expand Up @@ -643,6 +646,21 @@ void ProjectFileDialog::browseImportProject()
}
}

void ProjectFileDialog::browseUserInclude()
{
const QFileInfo inf(mProjectFile->getFilename());
const QDir &dir = inf.absoluteDir();
QMap<QString,QString> filters;
filters[tr("C/C++ header")] = "*.h";
filters[tr("All files")] = "*.*";
QString fileName = QFileDialog::getOpenFileName(this, tr("Include file"),
dir.canonicalPath(),
toFilterString(filters));
if (!fileName.isEmpty()) {
mUI->mEditUserInclude->setText(dir.relativeFilePath(fileName));
}
}

QStringList ProjectFileDialog::getProjectConfigurations() const
{
QStringList configs;
Expand Down
5 changes: 5 additions & 0 deletions gui/projectfiledialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ private slots:
*/
void browseImportProject();

/**
* @brief Browse for include file
*/
void browseUserInclude();

/**
* @brief Add new path to check.
*/
Expand Down
5 changes: 5 additions & 0 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,10 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
else if (strcmp(name, CppcheckXml::UndefinesElementName) == 0) {
for (const std::string &u : readXmlStringList(node, "", CppcheckXml::UndefineName, nullptr))
temp.userUndefs.insert(u);
} else if (strcmp(name, CppcheckXml::UserIncludeElementName) == 0) {
const char* i = node->GetText();
if (i)
temp.userIncludes.emplace_back(i);
} else if (strcmp(name, CppcheckXml::ImportProjectElementName) == 0) {
const std::string t_str = empty_if_null(node->GetText());
if (!t_str.empty())
Expand Down Expand Up @@ -1605,6 +1609,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
settings.includePaths = temp.includePaths; // TODO: append instead of overwrite
settings.userDefines = temp.userDefines; // TODO: append instead of overwrite
settings.userUndefs = temp.userUndefs; // TODO: append instead of overwrite
settings.userIncludes = temp.userIncludes; // TODO: append instead of overwrite
for (const std::string &addon : temp.addons)
settings.addons.emplace(addon);
settings.clang = temp.clang;
Expand Down
Loading
Loading