forked from qt-creator/qt-creator
Make AnalyzeUnit a member of AnalyzeInputData
Get rid of run() arguments. Change-Id: I744da2a043136e579284eb2697b9b71f476b58a9 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -166,11 +166,11 @@ ClangToolRunWorker::ClangToolRunWorker(ClangTool *tool, RunControl *runControl,
|
||||
m_toolChainType = toolChain->typeId();
|
||||
}
|
||||
|
||||
QList<RunnerCreator> ClangToolRunWorker::runnerCreators()
|
||||
QList<RunnerCreator> ClangToolRunWorker::runnerCreators(const AnalyzeUnit &unit)
|
||||
{
|
||||
if (m_tool == ClangTidyTool::instance())
|
||||
return {[this] { return createRunner(ClangToolType::Tidy); }};
|
||||
return {[this] { return createRunner(ClangToolType::Clazy); }};
|
||||
return {[=] { return createRunner(ClangToolType::Tidy, unit); }};
|
||||
return {[=] { return createRunner(ClangToolType::Clazy, unit); }};
|
||||
}
|
||||
|
||||
void ClangToolRunWorker::start()
|
||||
@@ -228,12 +228,12 @@ void ClangToolRunWorker::start()
|
||||
<< clangIncludeDirAndVersion.first << clangIncludeDirAndVersion.second;
|
||||
qCDebug(LOG) << "Files to process:" << unitsToProcess;
|
||||
|
||||
m_queue.clear();
|
||||
m_runnerCreators.clear();
|
||||
for (const AnalyzeUnit &unit : unitsToProcess) {
|
||||
for (const RunnerCreator &creator : runnerCreators())
|
||||
m_queue << QueueItem{unit, creator};
|
||||
for (const RunnerCreator &creator : runnerCreators(unit))
|
||||
m_runnerCreators << creator;
|
||||
}
|
||||
m_initialQueueSize = m_queue.count();
|
||||
m_initialQueueSize = m_runnerCreators.count();
|
||||
m_filesAnalyzed.clear();
|
||||
m_filesNotAnalyzed.clear();
|
||||
|
||||
@@ -254,7 +254,7 @@ void ClangToolRunWorker::start()
|
||||
const int parallelRuns = m_runSettings.parallelJobs();
|
||||
QTC_ASSERT(parallelRuns >= 1, reportFailure(); return);
|
||||
|
||||
if (m_queue.isEmpty()) {
|
||||
if (m_runnerCreators.isEmpty()) {
|
||||
finalize();
|
||||
return;
|
||||
}
|
||||
@@ -262,7 +262,7 @@ void ClangToolRunWorker::start()
|
||||
reportStarted();
|
||||
m_elapsed.start();
|
||||
|
||||
while (m_runners.size() < parallelRuns && !m_queue.isEmpty())
|
||||
while (m_runners.size() < parallelRuns && !m_runnerCreators.isEmpty())
|
||||
analyzeNextFile();
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ void ClangToolRunWorker::stop()
|
||||
}
|
||||
m_projectFiles.clear();
|
||||
m_runners.clear();
|
||||
m_queue.clear();
|
||||
m_runnerCreators.clear();
|
||||
m_progress.reportFinished();
|
||||
|
||||
reportStopped();
|
||||
@@ -289,21 +289,19 @@ void ClangToolRunWorker::analyzeNextFile()
|
||||
if (m_progress.isFinished())
|
||||
return; // The previous call already reported that we are finished.
|
||||
|
||||
if (m_queue.isEmpty()) {
|
||||
if (m_runnerCreators.isEmpty()) {
|
||||
if (m_runners.isEmpty())
|
||||
finalize();
|
||||
return;
|
||||
}
|
||||
|
||||
const QueueItem queueItem = m_queue.takeFirst();
|
||||
const AnalyzeUnit unit = queueItem.unit;
|
||||
qCDebug(LOG) << "analyzeNextFile:" << unit.file;
|
||||
const RunnerCreator runnerCreator = m_runnerCreators.takeFirst();
|
||||
|
||||
ClangToolRunner *runner = queueItem.runnerCreator();
|
||||
ClangToolRunner *runner = runnerCreator();
|
||||
m_runners.insert(runner);
|
||||
|
||||
if (runner->run(unit.file, unit.arguments)) {
|
||||
const QString filePath = FilePath::fromString(unit.file).toUserOutput();
|
||||
if (runner->run()) {
|
||||
const QString filePath = FilePath::fromString(runner->fileToAnalyze()).toUserOutput();
|
||||
appendMessage(tr("Analyzing \"%1\" [%2].").arg(filePath, runner->name()),
|
||||
Utils::StdOutFormat);
|
||||
} else {
|
||||
@@ -380,7 +378,7 @@ void ClangToolRunWorker::onProgressCanceled()
|
||||
|
||||
void ClangToolRunWorker::updateProgressValue()
|
||||
{
|
||||
m_progress.setProgressValue(m_initialQueueSize - m_queue.size());
|
||||
m_progress.setProgressValue(m_initialQueueSize - m_runnerCreators.size());
|
||||
}
|
||||
|
||||
void ClangToolRunWorker::finalize()
|
||||
@@ -410,11 +408,11 @@ void ClangToolRunWorker::finalize()
|
||||
runControl()->initiateStop();
|
||||
}
|
||||
|
||||
ClangToolRunner *ClangToolRunWorker::createRunner(ClangToolType tool)
|
||||
ClangToolRunner *ClangToolRunWorker::createRunner(ClangToolType tool, const AnalyzeUnit &unit)
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
auto runner = new ClangToolRunner(
|
||||
{tool, m_diagnosticConfig, m_temporaryDir.path(), m_environment}, this);
|
||||
{tool, m_diagnosticConfig, m_temporaryDir.path(), m_environment, unit}, this);
|
||||
connect(runner, &ClangToolRunner::finishedWithSuccess, this,
|
||||
std::bind(&ClangToolRunWorker::onRunnerFinishedWithSuccess, this, runner, _1));
|
||||
connect(runner, &ClangToolRunner::finishedWithFailure, this,
|
||||
|
@@ -35,12 +35,6 @@ using AnalyzeUnits = QList<AnalyzeUnit>;
|
||||
|
||||
using RunnerCreator = std::function<ClangToolRunner*()>;
|
||||
|
||||
struct QueueItem {
|
||||
AnalyzeUnit unit;
|
||||
RunnerCreator runnerCreator;
|
||||
};
|
||||
using QueueItems = QList<QueueItem>;
|
||||
|
||||
class ClangToolRunWorker : public ProjectExplorer::RunWorker
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -71,8 +65,8 @@ private:
|
||||
void start() final;
|
||||
void stop() final;
|
||||
|
||||
QList<RunnerCreator> runnerCreators();
|
||||
ClangToolRunner *createRunner(CppEditor::ClangToolType tool);
|
||||
QList<RunnerCreator> runnerCreators(const AnalyzeUnit &unit);
|
||||
ClangToolRunner *createRunner(CppEditor::ClangToolType tool, const AnalyzeUnit &unit);
|
||||
|
||||
AnalyzeUnits unitsToAnalyze(const Utils::FilePath &clangIncludeDir,
|
||||
const QString &clangVersion);
|
||||
@@ -101,7 +95,7 @@ private:
|
||||
Utils::Id m_toolChainType;
|
||||
|
||||
QFutureInterface<void> m_progress;
|
||||
QueueItems m_queue;
|
||||
QList<RunnerCreator> m_runnerCreators;
|
||||
QSet<Utils::FilePath> m_projectFiles;
|
||||
QSet<ClangToolRunner *> m_runners;
|
||||
int m_initialQueueSize = 0;
|
||||
|
@@ -81,6 +81,7 @@ static QString finishedWithBadExitCode(const QString &name, int exitCode)
|
||||
|
||||
ClangToolRunner::ClangToolRunner(const AnalyzeInputData &input, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_input(input)
|
||||
{
|
||||
m_name = input.tool == ClangToolType::Tidy ? tr("Clang-Tidy") : tr("Clazy");
|
||||
m_executable = toolExecutable(input.tool);
|
||||
@@ -90,13 +91,11 @@ ClangToolRunner::ClangToolRunner(const AnalyzeInputData &input, QObject *parent)
|
||||
<< "--"
|
||||
<< clangArguments(input.config, baseOptions);
|
||||
};
|
||||
m_overlayFilePath = input.overlayFilePath;
|
||||
m_outputDirPath = input.outputDirPath;
|
||||
QTC_CHECK(!m_outputDirPath.isEmpty());
|
||||
QTC_CHECK(!m_input.outputDirPath.isEmpty());
|
||||
|
||||
m_process.setEnvironment(input.environment);
|
||||
m_process.setUseCtrlCStub(true);
|
||||
m_process.setWorkingDirectory(m_outputDirPath); // Current clang-cl puts log file into working dir.
|
||||
m_process.setWorkingDirectory(m_input.outputDirPath); // Current clang-cl puts log file into working dir.
|
||||
connect(&m_process, &QtcProcess::done, this, &ClangToolRunner::onProcessDone);
|
||||
}
|
||||
|
||||
@@ -104,9 +103,9 @@ QStringList ClangToolRunner::mainToolArguments() const
|
||||
{
|
||||
QStringList result;
|
||||
result << "-export-fixes=" + m_outputFilePath;
|
||||
if (!m_overlayFilePath.isEmpty() && supportsVFSOverlay())
|
||||
result << "--vfsoverlay=" + m_overlayFilePath;
|
||||
result << QDir::toNativeSeparators(m_fileToAnalyze);
|
||||
if (!m_input.overlayFilePath.isEmpty() && supportsVFSOverlay())
|
||||
result << "--vfsoverlay=" + m_input.overlayFilePath;
|
||||
result << QDir::toNativeSeparators(m_input.unit.file);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -138,20 +137,19 @@ static QString createOutputFilePath(const FilePath &dirPath, const QString &file
|
||||
return {};
|
||||
}
|
||||
|
||||
bool ClangToolRunner::run(const QString &fileToAnalyze, const QStringList &compilerOptions)
|
||||
bool ClangToolRunner::run()
|
||||
{
|
||||
QTC_ASSERT(!m_executable.isEmpty(), return false);
|
||||
QTC_CHECK(!compilerOptions.contains(QLatin1String("-o")));
|
||||
QTC_CHECK(!compilerOptions.contains(fileToAnalyze));
|
||||
QTC_CHECK(!m_input.unit.arguments.contains(QLatin1String("-o")));
|
||||
QTC_CHECK(!m_input.unit.arguments.contains(m_input.unit.file));
|
||||
QTC_ASSERT(FilePath::fromString(m_input.unit.file).exists(), return false);
|
||||
|
||||
m_fileToAnalyze = fileToAnalyze;
|
||||
|
||||
m_outputFilePath = createOutputFilePath(m_outputDirPath, fileToAnalyze);
|
||||
m_outputFilePath = createOutputFilePath(m_input.outputDirPath, m_input.unit.file);
|
||||
QTC_ASSERT(!m_outputFilePath.isEmpty(), return false);
|
||||
m_commandLine = {m_executable, m_argsCreator(compilerOptions)};
|
||||
const CommandLine commandLine = {m_executable, m_argsCreator(m_input.unit.arguments)};
|
||||
|
||||
qCDebug(LOG).noquote() << "Starting" << m_commandLine.toUserOutput();
|
||||
m_process.setCommand(m_commandLine);
|
||||
qCDebug(LOG).noquote() << "Starting" << commandLine.toUserOutput();
|
||||
m_process.setCommand(commandLine);
|
||||
m_process.start();
|
||||
return true;
|
||||
}
|
||||
@@ -162,7 +160,7 @@ void ClangToolRunner::onProcessDone()
|
||||
emit finishedWithFailure(generalProcessError(m_name), commandlineAndOutput());
|
||||
} else if (m_process.result() == ProcessResult::FinishedWithSuccess) {
|
||||
qCDebug(LOG).noquote() << "Output:\n" << m_process.cleanedStdOut();
|
||||
emit finishedWithSuccess(m_fileToAnalyze);
|
||||
emit finishedWithSuccess(m_input.unit.file);
|
||||
} else if (m_process.result() == ProcessResult::FinishedWithError) {
|
||||
emit finishedWithFailure(finishedWithBadExitCode(m_name, m_process.exitCode()),
|
||||
commandlineAndOutput());
|
||||
@@ -176,7 +174,7 @@ QString ClangToolRunner::commandlineAndOutput() const
|
||||
return tr("Command line: %1\n"
|
||||
"Process Error: %2\n"
|
||||
"Output:\n%3")
|
||||
.arg(m_commandLine.toUserOutput())
|
||||
.arg(m_process.commandLine().toUserOutput())
|
||||
.arg(m_process.error())
|
||||
.arg(m_process.cleanedStdOut());
|
||||
}
|
||||
|
@@ -3,9 +3,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "clangtoolruncontrol.h"
|
||||
|
||||
#include <cppeditor/clangdiagnosticconfig.h>
|
||||
|
||||
#include <utils/commandline.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
@@ -22,6 +23,7 @@ struct AnalyzeInputData
|
||||
CppEditor::ClangDiagnosticConfig config;
|
||||
Utils::FilePath outputDirPath;
|
||||
Utils::Environment environment;
|
||||
AnalyzeUnit unit;
|
||||
QString overlayFilePath = {};
|
||||
};
|
||||
class ClangToolRunner : public QObject
|
||||
@@ -33,14 +35,14 @@ public:
|
||||
|
||||
QString name() const { return m_name; }
|
||||
Utils::FilePath executable() const { return m_executable; }
|
||||
QString fileToAnalyze() const { return m_fileToAnalyze; }
|
||||
QString fileToAnalyze() const { return m_input.unit.file; }
|
||||
QString outputFilePath() const { return m_outputFilePath; }
|
||||
bool supportsVFSOverlay() const;
|
||||
|
||||
// compilerOptions is expected to contain everything except:
|
||||
// (1) file to analyze
|
||||
// (2) -o output-file
|
||||
bool run(const QString &fileToAnalyze, const QStringList &compilerOptions = {});
|
||||
bool run();
|
||||
|
||||
signals:
|
||||
void finishedWithSuccess(const QString &fileToAnalyze);
|
||||
@@ -53,17 +55,14 @@ private:
|
||||
QStringList mainToolArguments() const;
|
||||
QString commandlineAndOutput() const;
|
||||
|
||||
QString m_overlayFilePath;
|
||||
Utils::FilePath m_outputDirPath;
|
||||
const AnalyzeInputData m_input;
|
||||
Utils::QtcProcess m_process;
|
||||
|
||||
QString m_name;
|
||||
Utils::FilePath m_executable;
|
||||
ArgsCreator m_argsCreator;
|
||||
|
||||
QString m_fileToAnalyze;
|
||||
QString m_outputFilePath;
|
||||
Utils::CommandLine m_commandLine;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -193,20 +193,25 @@ void DocumentClangToolRunner::run()
|
||||
if (runSettings.analyzeOpenFiles()) {
|
||||
vfso().update();
|
||||
|
||||
ClangDiagnosticConfig config = diagnosticConfig(
|
||||
runSettings.diagnosticConfigId());
|
||||
const ClangDiagnosticConfig config
|
||||
= diagnosticConfig(runSettings.diagnosticConfigId());
|
||||
|
||||
Environment env = projectBuildEnvironment(project);
|
||||
if (config.isEnabled(ClangToolType::Tidy)) {
|
||||
m_runnerCreators << [this, env, config] {
|
||||
return createRunner(ClangToolType::Tidy, config, env);
|
||||
const Environment env = projectBuildEnvironment(project);
|
||||
const auto addClangTool = [this, config, env](ClangToolType tool) {
|
||||
if (!config.isEnabled(tool))
|
||||
return;
|
||||
const FilePath executable = toolExecutable(tool);
|
||||
const auto [includeDir, clangVersion]
|
||||
= getClangIncludeDirAndVersion(executable);
|
||||
if (executable.isEmpty() || includeDir.isEmpty() || clangVersion.isEmpty())
|
||||
return;
|
||||
const AnalyzeUnit unit(m_fileInfo, includeDir, clangVersion);
|
||||
m_runnerCreators << [this, tool, unit, config, env] {
|
||||
return createRunner(tool, unit, config, env);
|
||||
};
|
||||
}
|
||||
if (config.isEnabled(ClangToolType::Clazy)) {
|
||||
m_runnerCreators << [this, env, config] {
|
||||
return createRunner(ClangToolType::Clazy, config, env);
|
||||
};
|
||||
}
|
||||
};
|
||||
addClangTool(ClangToolType::Tidy);
|
||||
addClangTool(ClangToolType::Clazy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,19 +228,10 @@ void DocumentClangToolRunner::runNext()
|
||||
m_currentRunner.release()->deleteLater();
|
||||
m_currentRunner.reset(m_runnerCreators.isEmpty() ? nullptr : m_runnerCreators.takeFirst()());
|
||||
if (m_currentRunner) {
|
||||
const auto [clangIncludeDir, clangVersion] = getClangIncludeDirAndVersion(
|
||||
m_currentRunner->executable());
|
||||
qCDebug(LOG) << Q_FUNC_INFO << m_currentRunner->executable() << clangIncludeDir
|
||||
<< clangVersion << m_fileInfo.file;
|
||||
if (m_currentRunner->executable().isEmpty() || clangIncludeDir.isEmpty() || clangVersion.isEmpty()
|
||||
|| (m_document->isModified() && !m_currentRunner->supportsVFSOverlay())) {
|
||||
if (m_document->isModified() && !m_currentRunner->supportsVFSOverlay())
|
||||
runNext();
|
||||
else if (!m_currentRunner->run())
|
||||
runNext();
|
||||
} else {
|
||||
const AnalyzeUnit unit(m_fileInfo, clangIncludeDir, clangVersion);
|
||||
QTC_ASSERT(FilePath::fromString(unit.file).exists(), runNext(); return;);
|
||||
if (!m_currentRunner->run(unit.file, unit.arguments))
|
||||
runNext();
|
||||
}
|
||||
} else {
|
||||
finalize();
|
||||
}
|
||||
@@ -348,11 +344,11 @@ bool DocumentClangToolRunner::isSuppressed(const Diagnostic &diagnostic) const
|
||||
return Utils::anyOf(m_suppressed, equalsSuppressed);
|
||||
}
|
||||
|
||||
ClangToolRunner *DocumentClangToolRunner::createRunner(ClangToolType tool,
|
||||
ClangToolRunner *DocumentClangToolRunner::createRunner(ClangToolType tool, const AnalyzeUnit &unit,
|
||||
const ClangDiagnosticConfig &config,
|
||||
const Environment &env)
|
||||
{
|
||||
auto runner = new ClangToolRunner({tool, config, m_temporaryDir.path(), env,
|
||||
auto runner = new ClangToolRunner({tool, config, m_temporaryDir.path(), env, unit,
|
||||
vfso().overlayFilePath().toString()}, this);
|
||||
connect(runner, &ClangToolRunner::finishedWithSuccess,
|
||||
this, &DocumentClangToolRunner::onSuccess);
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "clangfileinfo.h"
|
||||
#include "clangtoolruncontrol.h"
|
||||
#include "clangtoolsdiagnostic.h"
|
||||
#include "clangtoolsprojectsettings.h"
|
||||
|
||||
@@ -48,7 +49,7 @@ private:
|
||||
|
||||
bool isSuppressed(const Diagnostic &diagnostic) const;
|
||||
|
||||
ClangToolRunner *createRunner(CppEditor::ClangToolType tool,
|
||||
ClangToolRunner *createRunner(CppEditor::ClangToolType tool, const AnalyzeUnit &unit,
|
||||
const CppEditor::ClangDiagnosticConfig &config,
|
||||
const Utils::Environment &env);
|
||||
|
||||
|
Reference in New Issue
Block a user