GUI: Refactoring pythonCmd lookup
This commit is contained in:
parent
d4a435a520
commit
120a7dd42e
|
@ -258,8 +258,12 @@ void CheckThread::runAddonsAndTools(const ImportProject::FileSettings *fileSetti
|
|||
|
||||
parseClangErrors(addon, fileName, errout);
|
||||
} else {
|
||||
const QString a = CheckThread::getAddonFilePath(mDataDir, addon + ".py");
|
||||
if (a.isEmpty())
|
||||
const QString python = CheckThread::pythonCmd();
|
||||
if (python.isEmpty())
|
||||
continue;
|
||||
|
||||
const QString addonFilePath = CheckThread::getAddonFilePath(mDataDir, addon + ".py");
|
||||
if (addonFilePath.isEmpty())
|
||||
continue;
|
||||
|
||||
if (dumpFile.isEmpty()) {
|
||||
|
@ -281,15 +285,14 @@ void CheckThread::runAddonsAndTools(const ImportProject::FileSettings *fileSetti
|
|||
mCppcheck.settings().buildDir = buildDir;
|
||||
}
|
||||
|
||||
const QString python = mPythonPath.isEmpty() ? QString("python") : mPythonPath;
|
||||
QStringList args;
|
||||
args << a << dumpFile;
|
||||
args << addonFilePath << dumpFile;
|
||||
qDebug() << python << args;
|
||||
|
||||
QProcess process;
|
||||
QProcessEnvironment env = process.processEnvironment();
|
||||
if (!env.contains("PYTHONHOME") && !mPythonPath.isEmpty()) {
|
||||
env.insert("PYTHONHOME", QFileInfo(mPythonPath).canonicalPath());
|
||||
if (!env.contains("PYTHONHOME") && !python.startsWith("python")) {
|
||||
env.insert("PYTHONHOME", QFileInfo(python).canonicalPath());
|
||||
process.setProcessEnvironment(env);
|
||||
}
|
||||
process.start(python, args);
|
||||
|
@ -474,6 +477,26 @@ QString CheckThread::clangTidyCmd()
|
|||
return QString();
|
||||
}
|
||||
|
||||
QString CheckThread::pythonCmd()
|
||||
{
|
||||
QString path = QSettings().value(SETTINGS_PYTHON_PATH).toString();
|
||||
if (!path.isEmpty())
|
||||
return path;
|
||||
|
||||
path = "python";
|
||||
#ifdef Q_OS_WIN
|
||||
path += ".exe";
|
||||
#endif
|
||||
|
||||
QProcess process;
|
||||
process.start(path, QStringList() << "--version");
|
||||
process.waitForFinished();
|
||||
if (process.exitCode() == 0)
|
||||
return path;
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString CheckThread::getAddonFilePath(const QString &dataDir, const QString &addonFile)
|
||||
{
|
||||
const QStringList paths = QStringList() << "/" << "/addons/" << "/../addons/";
|
||||
|
|
|
@ -56,10 +56,6 @@ public:
|
|||
mAddonsAndTools = addonsAndTools;
|
||||
}
|
||||
|
||||
void setPythonPath(const QString &p) {
|
||||
mPythonPath = p;
|
||||
}
|
||||
|
||||
void setDataDir(const QString &dataDir) {
|
||||
mDataDir = dataDir;
|
||||
}
|
||||
|
@ -81,17 +77,23 @@ public:
|
|||
void stop();
|
||||
|
||||
/**
|
||||
* Loop for clang and return path
|
||||
* \return path to clang if found, empty if it is not found
|
||||
* Determine command to run clang
|
||||
* \return Command to run clang, empty if it is not found
|
||||
*/
|
||||
static QString clangCmd();
|
||||
|
||||
/**
|
||||
* Loop for clang-tidy and return path
|
||||
* \return path to clang-tidy if found, empty if it is not found
|
||||
* Determine command to run clang-tidy
|
||||
* \return Command to run clang-tidy, empty if it is not found
|
||||
*/
|
||||
static QString clangTidyCmd();
|
||||
|
||||
/**
|
||||
* Determine command to run python
|
||||
* \return Command to run python, empty if it is not found
|
||||
*/
|
||||
static QString pythonCmd();
|
||||
|
||||
/**
|
||||
* Look for addon and return path
|
||||
* \return path to addon if found, empty if it is not found
|
||||
|
@ -143,7 +145,6 @@ private:
|
|||
QStringList mFiles;
|
||||
bool mAnalyseWholeProgram;
|
||||
QStringList mAddonsAndTools;
|
||||
QString mPythonPath;
|
||||
QString mDataDir;
|
||||
QStringList mClangIncludePaths;
|
||||
QStringList mSuppressions;
|
||||
|
|
|
@ -457,7 +457,6 @@ void MainWindow::doAnalyzeProject(ImportProject p)
|
|||
//mThread->SetanalyzeProject(true);
|
||||
if (mProjectFile) {
|
||||
mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools());
|
||||
mThread->setPythonPath(mSettings->value(SETTINGS_PYTHON_PATH).toString());
|
||||
QString clangHeaders = mSettings->value(SETTINGS_VS_INCLUDE_PATHS).toString();
|
||||
mThread->setClangIncludePaths(clangHeaders.split(";"));
|
||||
mThread->setSuppressions(mProjectFile->getSuppressions());
|
||||
|
|
|
@ -94,7 +94,6 @@ void ThreadHandler::check(const Settings &settings)
|
|||
|
||||
for (int i = 0; i < mRunningThreadCount; i++) {
|
||||
mThreads[i]->setAddonsAndTools(mAddonsAndTools);
|
||||
mThreads[i]->setPythonPath(mPythonPath);
|
||||
mThreads[i]->setSuppressions(mSuppressions);
|
||||
mThreads[i]->setClangIncludePaths(mClangIncludePaths);
|
||||
mThreads[i]->setDataDir(mDataDir);
|
||||
|
|
|
@ -79,10 +79,6 @@ public:
|
|||
mSuppressions = s;
|
||||
}
|
||||
|
||||
void setPythonPath(const QString &p) {
|
||||
mPythonPath = p;
|
||||
}
|
||||
|
||||
void setClangIncludePaths(const QStringList &s) {
|
||||
mClangIncludePaths = s;
|
||||
}
|
||||
|
@ -259,7 +255,6 @@ protected:
|
|||
|
||||
QStringList mAddonsAndTools;
|
||||
QStringList mSuppressions;
|
||||
QString mPythonPath;
|
||||
QStringList mClangIncludePaths;
|
||||
|
||||
QString mDataDir;
|
||||
|
|
Loading…
Reference in New Issue