GUI: Configuration of python path for the addons

This commit is contained in:
Daniel Marjamäki 2017-08-14 00:23:21 +02:00
parent 663beb6fd2
commit 71f52b77a4
10 changed files with 94 additions and 6 deletions

View File

@ -267,12 +267,32 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS
mCppcheck.settings().buildDir = buildDir;
}
QString cmd = "python " + a + ' ' + dumpFile;
qDebug() << cmd;
const QString python = mPythonPath.isEmpty() ? QString("python") : mPythonPath;
QStringList args;
args << a << dumpFile;
qDebug() << python << args;
QProcess process;
process.start(cmd);
if (!mPythonPath.isEmpty()) {
QStringList env(QProcess::systemEnvironment());
for (int i = 0; i < env.size(); ++i) {
if (env[i].startsWith("PYTHONHOME=")) {
env.removeAt(i);
process.setEnvironment(env);
break;
}
}
}
process.start(python, args);
process.waitForFinished();
parseAddonErrors(process.readAllStandardError(), addon);
const QString errout(process.readAllStandardError());
QFile f(dumpFile + '-' + addon + "-results");
if (f.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&f);
out << errout;
f.close();
}
parseAddonErrors(errout, addon);
}
}
}
@ -289,6 +309,8 @@ QString CheckThread::getAddonPath() const
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";

View File

@ -56,6 +56,10 @@ public:
mAddons = addons;
}
void setPythonPath(const QString &p) {
mPythonPath = p;
}
void setDataDir(const QString &dataDir) {
mDataDir = dataDir;
}
@ -128,6 +132,7 @@ private:
QStringList mFiles;
bool mAnalyseWholeProgram;
QStringList mAddons;
QString mPythonPath;
QString mDataDir;
QString mClangPath;
QStringList mClangIncludePaths;

View File

@ -80,6 +80,7 @@
#define SETTINGS_APPLICATION_DEFAULT "Default Application"
#define SETTINGS_LANGUAGE "Application language"
#define SETTINGS_GLOBAL_INCLUDE_PATHS "Global include paths"
#define SETTINGS_PYTHON_PATH "Python path"
#define SETTINGS_CLANG_PATH "Clang path"
#define SETTINGS_VS_INCLUDE_PATHS "VS include paths"
#define SETTINGS_INLINE_SUPPRESSIONS "Inline suppressions"

View File

@ -444,6 +444,7 @@ void MainWindow::doAnalyzeProject(ImportProject p)
//mThread->SetanalyzeProject(true);
if (mProjectFile) {
mThread->setAddons(mProjectFile->getAddons());
mThread->setPythonPath(mSettings->value(SETTINGS_PYTHON_PATH).toString());
QString clangHeaders = mSettings->value(SETTINGS_VS_INCLUDE_PATHS).toString();
mThread->setClangIncludePaths(clangHeaders.split(";"));
#ifdef Q_OS_WIN

View File

@ -961,7 +961,7 @@ void ResultsTree::suppressSelectedIds()
// delete all errors with selected message Ids
for (int i = 0; i < mModel.rowCount(); i++) {
QStandardItem * const file = mModel.item(i, 0);
for (int j = 0; j < file->rowCount(); ) {
for (int j = 0; j < file->rowCount();) {
QStandardItem *errorItem = file->child(j, 0);
QVariantMap userdata = errorItem->data().toMap();
if (selectedIds.contains(userdata["id"].toString())) {

View File

@ -66,7 +66,7 @@
</size>
</property>
<property name="inputMask">
<string notr="true">009; </string>
<string notr="true">009</string>
</property>
<property name="text">
<string notr="true"/>
@ -282,6 +282,45 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_5">
<attribute name="title">
<string>Addons</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Python binary (leave this empty to use python in the PATH)</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="mEditPythonPath"/>
</item>
<item>
<widget class="QPushButton" name="mBtnBrowsePythonPath">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>168</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="mTabClang">
<attribute name="title">
<string>Clang</string>

View File

@ -53,6 +53,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
mUI.mEnableInconclusive->setCheckState(boolToCheckState(settings.value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool()));
mUI.mShowStatistics->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_STATISTICS, false).toBool()));
mUI.mShowErrorId->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_ERROR_ID, false).toBool()));
mUI.mEditPythonPath->setText(settings.value(SETTINGS_PYTHON_PATH, QString()).toString());
#ifdef Q_OS_WIN
//mUI.mTabClang->setVisible(true);
@ -75,6 +76,8 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
connect(mUI.mListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
this, SLOT(editApplication()));
connect(mUI.mBtnBrowsePythonPath, &QPushButton::clicked, this, &SettingsDialog::browsePythonPath);
mUI.mListWidget->setSortingEnabled(false);
populateApplicationList();
@ -157,6 +160,7 @@ void SettingsDialog::saveSettingValues() const
saveCheckboxValue(&settings, mUI.mEnableInconclusive, SETTINGS_INCONCLUSIVE_ERRORS);
saveCheckboxValue(&settings, mUI.mShowStatistics, SETTINGS_SHOW_STATISTICS);
saveCheckboxValue(&settings, mUI.mShowErrorId, SETTINGS_SHOW_ERROR_ID);
settings.setValue(SETTINGS_PYTHON_PATH, mUI.mEditPythonPath->text());
#ifdef Q_OS_WIN
settings.setValue(SETTINGS_CLANG_PATH, mUI.mEditClangPath->text());
@ -295,6 +299,13 @@ bool SettingsDialog::showInconclusive() const
return checkStateToBool(mUI.mEnableInconclusive->checkState());
}
void SettingsDialog::browsePythonPath()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Select python binary"), QDir::rootPath());
if (fileName.contains("python", Qt::CaseInsensitive))
mUI.mEditPythonPath->setText(fileName);
}
void SettingsDialog::browseClangPath()
{
QString selectedDir = QFileDialog::getExistingDirectory(this,

View File

@ -124,6 +124,9 @@ protected slots:
*/
void defaultApplication();
/** @brief Slot for browsing for the python binary */
void browsePythonPath();
/** @brief Slot for browsing for the clang binary */
void browseClangPath();
protected:

View File

@ -94,6 +94,7 @@ void ThreadHandler::check(const Settings &settings)
for (int i = 0; i < mRunningThreadCount; i++) {
mThreads[i]->setAddons(mAddons);
mThreads[i]->setPythonPath(mPythonPath);
mThreads[i]->setSuppressions(mSuppressions);
mThreads[i]->setClangPath(mClangPath);
mThreads[i]->setClangIncludePaths(mClangIncludePaths);

View File

@ -79,6 +79,10 @@ public:
mSuppressions = s;
}
void setPythonPath(const QString &p) {
mPythonPath = p;
}
void setClangPath(const QString &p) {
mClangPath = p;
}
@ -255,6 +259,7 @@ protected:
QStringList mAddons;
QStringList mSuppressions;
QString mPythonPath;
QString mClangPath;
QStringList mClangIncludePaths;