GUI: Working on Clang support on Windows

This commit is contained in:
Daniel Marjamäki 2017-08-04 20:08:01 +02:00
parent c2bb9890e9
commit 7f1db7b716
5 changed files with 33 additions and 17 deletions

View File

@ -117,26 +117,28 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS
if (!fileSettings) if (!fileSettings)
continue; continue;
QString args; QStringList args;
if (addon == CLANG)
args << "--analyze";
else
args << "-checks=*,-clang*,-llvm*" << fileName << "--";
for (std::list<std::string>::const_iterator I = fileSettings->includePaths.begin(); I != fileSettings->includePaths.end(); ++I) for (std::list<std::string>::const_iterator I = fileSettings->includePaths.begin(); I != fileSettings->includePaths.end(); ++I)
args += " -I" + QString::fromStdString(*I); args << ("-I" + QString::fromStdString(*I));
for (std::list<std::string>::const_iterator i = fileSettings->systemIncludePaths.begin(); i != fileSettings->systemIncludePaths.end(); ++i) for (std::list<std::string>::const_iterator i = fileSettings->systemIncludePaths.begin(); i != fileSettings->systemIncludePaths.end(); ++i)
args += " -isystem " + QString::fromStdString(*i); args << "-isystem" << QString::fromStdString(*i);
foreach (QString D, QString::fromStdString(fileSettings->defines).split(";")) { foreach (QString D, QString::fromStdString(fileSettings->defines).split(";")) {
args += " -D" + D; args << ("-D" + D);
} }
if (!fileSettings->standard.empty()) if (!fileSettings->standard.empty())
args += " -std=" + QString::fromStdString(fileSettings->standard); args << (" -std=" + QString::fromStdString(fileSettings->standard));
QString cmd;
if (addon == CLANG) if (addon == CLANG)
cmd = addon + " --analyze" + args + ' ' + fileName; args << fileName;
else
cmd = addon + " -checks=*,-clang*,-llvm* " + fileName + " -- " + args; const QString cmd(mClangPath.isEmpty() ? addon : (mClangPath + '/' + addon + ".exe"));
qDebug() << cmd; qDebug() << cmd << args;
QProcess process; QProcess process;
process.start(cmd); process.start(cmd, args);
process.waitForFinished(600*1000); process.waitForFinished(600*1000);
if (addon == CLANG) if (addon == CLANG)
parseClangErrors(process.readAllStandardError()); parseClangErrors(process.readAllStandardError());
@ -231,7 +233,7 @@ void CheckThread::parseClangErrors(QString err)
QTextStream in(&err, QIODevice::ReadOnly); QTextStream in(&err, QIODevice::ReadOnly);
while (!in.atEnd()) { while (!in.atEnd()) {
QString line = in.readLine(); QString line = in.readLine();
QRegExp r("([^:]+):([0-9]+):[0-9]+: (warning|error|fatal error): (.*)"); QRegExp r("(.+):([0-9]+):[0-9]+: (warning|error|fatal error): (.*)");
if (!r.exactMatch(line)) if (!r.exactMatch(line))
continue; continue;
const std::string filename = r.cap(1).toStdString(); const std::string filename = r.cap(1).toStdString();

View File

@ -60,6 +60,10 @@ public:
mDataDir = dataDir; mDataDir = dataDir;
} }
void setClangPath(const QString &p) {
mClangPath = p;
}
/** /**
* @brief method that is run in a thread * @brief method that is run in a thread
* *
@ -117,6 +121,7 @@ private:
bool mAnalyseWholeProgram; bool mAnalyseWholeProgram;
QStringList mAddons; QStringList mAddons;
QString mDataDir; QString mDataDir;
QString mClangPath;
}; };
/// @} /// @}
#endif // CHECKTHREAD_H #endif // CHECKTHREAD_H

View File

@ -412,8 +412,14 @@ void MainWindow::doAnalyzeProject(ImportProject p)
} }
//mThread->SetanalyzeProject(true); //mThread->SetanalyzeProject(true);
if (mProjectFile) if (mProjectFile) {
mThread->setAddons(mProjectFile->getAddons()); mThread->setAddons(mProjectFile->getAddons());
#ifdef Q_OS_WIN
// Try to autodetect clang
if (QFileInfo("C:/Program Files/LLVM/bin/clang.exe").exists())
mThread->setClangPath("C:/Program Files/LLVM/bin");
#endif
}
mThread->setProject(p); mThread->setProject(p);
mThread->check(checkSettings); mThread->check(checkSettings);
} }

View File

@ -93,6 +93,7 @@ void ThreadHandler::check(const Settings &settings)
for (int i = 0; i < mRunningThreadCount; i++) { for (int i = 0; i < mRunningThreadCount; i++) {
mThreads[i]->setAddons(mAddons); mThreads[i]->setAddons(mAddons);
mThreads[i]->setClangPath(mClangPath);
mThreads[i]->setDataDir(mDataDir); mThreads[i]->setDataDir(mDataDir);
mThreads[i]->check(settings); mThreads[i]->check(settings);
} }

View File

@ -75,6 +75,10 @@ public:
mAddons = addons; mAddons = addons;
} }
void setClangPath(const QString &p) {
mClangPath = p;
}
void setDataDir(const QString &dataDir) { void setDataDir(const QString &dataDir) {
mDataDir = dataDir; mDataDir = dataDir;
} }
@ -183,9 +187,6 @@ public slots:
*/ */
void stop(); void stop();
protected slots: protected slots:
/** /**
* @brief Slot that a single thread is done * @brief Slot that a single thread is done
* *
@ -245,6 +246,7 @@ protected:
bool mAnalyseWholeProgram; bool mAnalyseWholeProgram;
QStringList mAddons; QStringList mAddons;
QString mClangPath;
QString mDataDir; QString mDataDir;
private: private: