GUI: Disable addons that are not found
This commit is contained in:
parent
2a6f63d995
commit
74fc6485d2
|
@ -16,6 +16,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
@ -74,13 +75,11 @@ void CheckThread::run()
|
|||
return;
|
||||
}
|
||||
|
||||
const QString addonPath = getAddonPath();
|
||||
|
||||
QString file = mResult.getNextFile();
|
||||
while (!file.isEmpty() && mState == Running) {
|
||||
qDebug() << "Checking file" << file;
|
||||
mCppcheck.check(file.toStdString());
|
||||
runAddonsAndTools(addonPath, nullptr, file);
|
||||
runAddonsAndTools(nullptr, file);
|
||||
emit fileChecked(file);
|
||||
|
||||
if (mState == Running)
|
||||
|
@ -92,7 +91,7 @@ void CheckThread::run()
|
|||
file = QString::fromStdString(fileSettings.filename);
|
||||
qDebug() << "Checking file" << file;
|
||||
mCppcheck.check(fileSettings);
|
||||
runAddonsAndTools(addonPath, &fileSettings, QString::fromStdString(fileSettings.filename));
|
||||
runAddonsAndTools(&fileSettings, QString::fromStdString(fileSettings.filename));
|
||||
emit fileChecked(file);
|
||||
|
||||
if (mState == Running)
|
||||
|
@ -107,7 +106,7 @@ void CheckThread::run()
|
|||
emit done();
|
||||
}
|
||||
|
||||
void CheckThread::runAddonsAndTools(const QString &addonPath, const ImportProject::FileSettings *fileSettings, const QString &fileName)
|
||||
void CheckThread::runAddonsAndTools(const ImportProject::FileSettings *fileSettings, const QString &fileName)
|
||||
{
|
||||
QString dumpFile;
|
||||
|
||||
|
@ -263,13 +262,12 @@ void CheckThread::runAddonsAndTools(const QString &addonPath, const ImportProjec
|
|||
|
||||
parseClangErrors(addon, fileName, errout);
|
||||
} else {
|
||||
QString a;
|
||||
if (QFileInfo(addonPath + '/' + addon + ".py").exists())
|
||||
a = addonPath + '/' + addon + ".py";
|
||||
else if (QFileInfo(addonPath + '/' + addon + '/' + addon + ".py").exists())
|
||||
a = addonPath + '/' + addon + '/' + addon + ".py";
|
||||
else
|
||||
continue;
|
||||
QString a = CheckThread::getAddonFilePath(mDataDir, addon + ".py");
|
||||
if (a.isEmpty()) {
|
||||
a = CheckThread::getAddonFilePath(QApplication::applicationDirPath(), addon + ".py");
|
||||
if (a.isEmpty())
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dumpFile.isEmpty()) {
|
||||
const std::string buildDir = mCppcheck.settings().buildDir;
|
||||
|
@ -321,21 +319,6 @@ void CheckThread::stop()
|
|||
mCppcheck.terminate();
|
||||
}
|
||||
|
||||
QString CheckThread::getAddonPath() const
|
||||
{
|
||||
if (QFileInfo(mDataDir + "/threadsafety.py").exists())
|
||||
return mDataDir;
|
||||
else if (QDir(mDataDir + "/addons").exists())
|
||||
return mDataDir + "/addons";
|
||||
else if (QDir(mDataDir + "/../addons").exists())
|
||||
return mDataDir + "/../addons";
|
||||
else if (mDataDir.endsWith("/cfg")) {
|
||||
if (QDir(mDataDir.mid(0,mDataDir.size()-3) + "addons").exists())
|
||||
return mDataDir.mid(0,mDataDir.size()-3) + "addons";
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void CheckThread::parseAddonErrors(QString err, QString tool)
|
||||
{
|
||||
Q_UNUSED(tool);
|
||||
|
@ -447,3 +430,16 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
|
|||
mResult.reportErr(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
QString CheckThread::getAddonFilePath(const QString &dataDir, const QString &addonFile)
|
||||
{
|
||||
if (dataDir.isEmpty())
|
||||
return QString();
|
||||
if (QFileInfo(dataDir + '/' + addonFile).exists())
|
||||
return dataDir + '/' + addonFile;
|
||||
if (QFileInfo(dataDir + "/addons/" + addonFile).exists())
|
||||
return dataDir + "/addons/" + addonFile;
|
||||
if (QFileInfo(dataDir + "/../addons/" + addonFile).exists())
|
||||
return dataDir + "/../addons/" + addonFile;
|
||||
return QString();
|
||||
}
|
||||
|
|
|
@ -84,6 +84,7 @@ public:
|
|||
|
||||
void stop();
|
||||
|
||||
static QString getAddonFilePath(const QString &dataDir, const QString &addonFile);
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -122,9 +123,7 @@ protected:
|
|||
CppCheck mCppcheck;
|
||||
|
||||
private:
|
||||
QString getAddonPath() const;
|
||||
|
||||
void runAddonsAndTools(const QString &addonPath, const ImportProject::FileSettings *fileSettings, const QString &fileName);
|
||||
void runAddonsAndTools(const ImportProject::FileSettings *fileSettings, const QString &fileName);
|
||||
|
||||
void parseAddonErrors(QString err, QString tool);
|
||||
void parseClangErrors(const QString &tool, const QString &file0, QString err);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <QProcess>
|
||||
#include "common.h"
|
||||
#include "projectfiledialog.h"
|
||||
#include "checkthread.h"
|
||||
#include "projectfile.h"
|
||||
#include "library.h"
|
||||
#include "cppcheck.h"
|
||||
|
@ -160,6 +161,16 @@ void ProjectFileDialog::saveSettings() const
|
|||
settings.setValue(SETTINGS_PROJECT_DIALOG_HEIGHT, size().height());
|
||||
}
|
||||
|
||||
static void updateAddonCheckBox(QCheckBox *cb, const ProjectFile *projectFile, const QString &dataDir, const QString &addon)
|
||||
{
|
||||
cb->setChecked(projectFile->getAddons().contains(addon));
|
||||
const QString appPath = QApplication::applicationDirPath();
|
||||
if (CheckThread::getAddonFilePath(dataDir, addon + ".py").isEmpty() && CheckThread::getAddonFilePath(appPath, addon + ".py").isEmpty()) {
|
||||
cb->setEnabled(false);
|
||||
cb->setText(cb->text() + QObject::tr(" (Not found)"));
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
|
||||
{
|
||||
setRootPath(projectFile->getRootPath());
|
||||
|
@ -172,7 +183,13 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
|
|||
setExcludedPaths(projectFile->getExcludedPaths());
|
||||
setLibraries(projectFile->getLibraries());
|
||||
setSuppressions(projectFile->getSuppressions());
|
||||
mUI.mAddonThreadSafety->setChecked(projectFile->getAddons().contains("threadsafety"));
|
||||
|
||||
QSettings settings;
|
||||
const QString dataDir = settings.value("DATADIR", QString()).toString();
|
||||
updateAddonCheckBox(mUI.mAddonThreadSafety, projectFile, dataDir, "threadsafety");
|
||||
updateAddonCheckBox(mUI.mAddonY2038, projectFile, dataDir, "y2038");
|
||||
updateAddonCheckBox(mUI.mAddonCert, projectFile, dataDir, "cert");
|
||||
|
||||
mUI.mAddonY2038->setChecked(projectFile->getAddons().contains("y2038"));
|
||||
mUI.mAddonCert->setChecked(projectFile->getAddons().contains("cert"));
|
||||
mUI.mToolClangAnalyzer->setChecked(projectFile->getClangAnalyzer());
|
||||
|
|
Loading…
Reference in New Issue