2018-01-17 15:08:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-05-02 14:51:05 +02:00
|
|
|
#include "clangfileinfo.h"
|
2019-09-13 10:49:14 +02:00
|
|
|
#include "clangtoolssettings.h"
|
2018-05-02 14:51:05 +02:00
|
|
|
|
2019-08-29 15:00:03 +02:00
|
|
|
#include <cpptools/clangdiagnosticconfig.h>
|
2018-01-17 15:08:30 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
2019-08-29 15:00:03 +02:00
|
|
|
#include <projectexplorer/runcontrol.h>
|
2018-01-17 15:08:30 +01:00
|
|
|
#include <utils/environment.h>
|
2018-06-05 10:37:42 +02:00
|
|
|
#include <utils/temporarydirectory.h>
|
2018-01-17 15:08:30 +01:00
|
|
|
|
2019-11-29 09:24:05 +01:00
|
|
|
#include <QElapsedTimer>
|
2018-01-17 15:08:30 +01:00
|
|
|
#include <QFutureInterface>
|
2019-08-01 14:50:59 +02:00
|
|
|
#include <QSet>
|
2018-01-17 15:08:30 +01:00
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
|
|
namespace ClangTools {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class ClangToolRunner;
|
|
|
|
|
class ProjectBuilder;
|
|
|
|
|
|
|
|
|
|
struct AnalyzeUnit {
|
|
|
|
|
AnalyzeUnit(const QString &file, const QStringList &options)
|
|
|
|
|
: file(file), arguments(options) {}
|
|
|
|
|
|
|
|
|
|
QString file;
|
|
|
|
|
QStringList arguments; // without file itself and "-o somePath"
|
|
|
|
|
};
|
2018-11-04 22:30:54 +01:00
|
|
|
using AnalyzeUnits = QList<AnalyzeUnit>;
|
2018-01-17 15:08:30 +01:00
|
|
|
|
2019-08-01 14:50:59 +02:00
|
|
|
using RunnerCreator = std::function<ClangToolRunner*()>;
|
|
|
|
|
|
|
|
|
|
struct QueueItem {
|
|
|
|
|
AnalyzeUnit unit;
|
|
|
|
|
RunnerCreator runnerCreator;
|
|
|
|
|
};
|
|
|
|
|
using QueueItems = QList<QueueItem>;
|
|
|
|
|
|
2019-08-27 11:28:48 +02:00
|
|
|
class ClangToolRunWorker : public ProjectExplorer::RunWorker
|
2018-01-17 15:08:30 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2019-08-27 11:28:48 +02:00
|
|
|
ClangToolRunWorker(ProjectExplorer::RunControl *runControl,
|
2019-09-13 10:49:14 +02:00
|
|
|
const RunSettings &runSettings,
|
2019-09-25 15:46:15 +02:00
|
|
|
const CppTools::ClangDiagnosticConfig &diagnosticConfig,
|
2019-08-23 15:25:57 +02:00
|
|
|
const FileInfos &fileInfos,
|
2019-10-28 16:25:07 +01:00
|
|
|
bool buildBeforeAnalysis);
|
2018-01-17 15:08:30 +01:00
|
|
|
|
2019-10-28 16:25:07 +01:00
|
|
|
int filesAnalyzed() const { return m_filesAnalyzed.size(); }
|
|
|
|
|
int filesNotAnalyzed() const { return m_filesNotAnalyzed.size(); }
|
|
|
|
|
int totalFilesToAnalyze() const { return m_fileInfos.size(); }
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void buildFailed();
|
|
|
|
|
void runnerFinished();
|
|
|
|
|
void startFailed();
|
|
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
protected:
|
2018-05-31 15:20:35 +02:00
|
|
|
void onRunnerFinishedWithSuccess(const QString &filePath);
|
2018-01-17 15:08:30 +01:00
|
|
|
void onRunnerFinishedWithFailure(const QString &errorMessage, const QString &errorDetails);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void start() final;
|
|
|
|
|
void stop() final;
|
|
|
|
|
|
2019-08-29 15:00:03 +02:00
|
|
|
QList<RunnerCreator> runnerCreators();
|
|
|
|
|
template <class T> ClangToolRunner *createRunner();
|
|
|
|
|
|
2018-08-07 15:21:20 +02:00
|
|
|
AnalyzeUnits unitsToAnalyze();
|
2018-01-17 15:08:30 +01:00
|
|
|
void analyzeNextFile();
|
|
|
|
|
|
|
|
|
|
void handleFinished();
|
|
|
|
|
|
|
|
|
|
void onProgressCanceled();
|
|
|
|
|
void updateProgressValue();
|
|
|
|
|
|
|
|
|
|
void finalize();
|
|
|
|
|
|
|
|
|
|
private:
|
2019-09-13 10:49:14 +02:00
|
|
|
RunSettings m_runSettings;
|
2019-08-29 15:00:03 +02:00
|
|
|
CppTools::ClangDiagnosticConfig m_diagnosticConfig;
|
2018-05-02 14:51:05 +02:00
|
|
|
FileInfos m_fileInfos;
|
2018-01-17 15:08:30 +01:00
|
|
|
|
2019-09-13 10:49:14 +02:00
|
|
|
ProjectBuilder *m_projectBuilder = nullptr;
|
|
|
|
|
Utils::Environment m_environment;
|
|
|
|
|
Utils::TemporaryDirectory m_temporaryDir;
|
|
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
CppTools::ProjectInfo m_projectInfoBeforeBuild;
|
|
|
|
|
CppTools::ProjectInfo m_projectInfo;
|
|
|
|
|
QString m_targetTriple;
|
|
|
|
|
Core::Id m_toolChainType;
|
|
|
|
|
|
|
|
|
|
QFutureInterface<void> m_progress;
|
2019-08-01 14:50:59 +02:00
|
|
|
QueueItems m_queue;
|
2019-07-09 12:42:07 +02:00
|
|
|
QSet<Utils::FilePath> m_projectFiles;
|
2018-01-17 15:08:30 +01:00
|
|
|
QSet<ClangToolRunner *> m_runners;
|
2019-08-01 14:50:59 +02:00
|
|
|
int m_initialQueueSize = 0;
|
|
|
|
|
QSet<QString> m_filesAnalyzed;
|
|
|
|
|
QSet<QString> m_filesNotAnalyzed;
|
2019-11-29 09:24:05 +01:00
|
|
|
|
|
|
|
|
QElapsedTimer m_elapsed;
|
2018-01-17 15:08:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClangTools
|