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