ClangTools: Merge ClangTidyClazyRunControl into ClangToolsRunControl

Change-Id: I162bbb9374fda0bbfc7f3db8fa245f3b5d6e73ad
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Nikolai Kosjar
2019-08-29 15:00:03 +02:00
parent 342679292c
commit 58a724b489
8 changed files with 68 additions and 182 deletions

View File

@@ -14,7 +14,6 @@ add_qtc_plugin(ClangTools
clangfileinfo.h
clangfixitsrefactoringchanges.cpp clangfixitsrefactoringchanges.h
clangselectablefilesdialog.cpp clangselectablefilesdialog.h clangselectablefilesdialog.ui
clangtidyclazyruncontrol.cpp clangtidyclazyruncontrol.h
clangtidyclazyrunner.cpp clangtidyclazyrunner.h
clangtidyclazytool.cpp clangtidyclazytool.h
clangtool.cpp clangtool.h

View File

@@ -1,84 +0,0 @@
/****************************************************************************
**
** 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.
**
****************************************************************************/
#include "clangtidyclazyruncontrol.h"
#include "clangtidyclazyrunner.h"
#include "clangtidyclazytool.h"
using namespace ProjectExplorer;
namespace ClangTools {
namespace Internal {
ClangTidyClazyRunWorker::ClangTidyClazyRunWorker(
RunControl *runControl,
const CppTools::ClangDiagnosticConfig &diagnosticConfig,
const FileInfos &fileInfos,
bool preventBuild)
: ClangToolRunWorker(runControl, fileInfos, preventBuild)
, m_diagnosticConfig(diagnosticConfig)
{
setId("ClangTidyClazyRunner");
init();
}
QList<RunnerCreator> ClangTidyClazyRunWorker::runnerCreators()
{
QList<RunnerCreator> creators;
if (m_diagnosticConfig.clangTidyMode() != CppTools::ClangDiagnosticConfig::TidyMode::Disabled)
creators << [this]() { return createRunner<ClangTidyRunner>(); };
if (!m_diagnosticConfig.clazyChecks().isEmpty()) {
if (!qEnvironmentVariable("QTC_USE_CLAZY_STANDALONE_PATH").isEmpty())
creators << [this]() { return createRunner<ClazyStandaloneRunner>(); };
else
creators << [this]() { return createRunner<ClazyPluginRunner>(); };
}
return creators;
}
template <class T>
ClangToolRunner *ClangTidyClazyRunWorker::createRunner()
{
auto runner = new T(m_diagnosticConfig, this);
runner->init(m_temporaryDir.path(), m_environment);
connect(runner, &ClangToolRunner::finishedWithSuccess,
this, &ClangTidyClazyRunWorker::onRunnerFinishedWithSuccess);
connect(runner, &ClangToolRunner::finishedWithFailure,
this, &ClangTidyClazyRunWorker::onRunnerFinishedWithFailure);
return runner;
}
ClangTool *ClangTidyClazyRunWorker::tool()
{
return ClangTidyClazyTool::instance();
}
} // namespace Internal
} // namespace ClangTools

View File

@@ -1,57 +0,0 @@
/****************************************************************************
**
** 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
#include "clangtoolruncontrol.h"
#include <cpptools/clangdiagnosticconfig.h>
namespace ClangTools {
namespace Internal {
class ClangTidyClazyRunWorker final : public ClangToolRunWorker
{
Q_OBJECT
public:
ClangTidyClazyRunWorker(ProjectExplorer::RunControl *runControl,
const CppTools::ClangDiagnosticConfig &diagnosticConfig,
const FileInfos &fileInfos,
bool preventBuild);
protected:
QList<RunnerCreator> runnerCreators() final;
ClangTool *tool() final;
private:
template <class T> ClangToolRunner *createRunner();
private:
CppTools::ClangDiagnosticConfig m_diagnosticConfig;
};
} // namespace Internal
} // namespace ClangTools

View File

@@ -27,10 +27,10 @@
#include "clangfixitsrefactoringchanges.h"
#include "clangselectablefilesdialog.h"
#include "clangtoolruncontrol.h"
#include "clangtoolsconstants.h"
#include "clangtoolsdiagnosticmodel.h"
#include "clangtoolslogfilereader.h"
#include "clangtidyclazyruncontrol.h"
#include "clangtoolsdiagnosticview.h"
#include "clangtoolsprojectsettings.h"
#include "clangtoolssettings.h"
@@ -396,10 +396,10 @@ void ClangTidyClazyTool::startTool(FileSelection fileSelection)
return;
const bool preventBuild = fileSelection == FileSelection::CurrentFile;
auto clangTool = new ClangTidyClazyRunWorker(runControl,
getDiagnosticConfig(project),
fileInfos,
preventBuild);
auto clangTool = new ClangToolRunWorker(runControl,
getDiagnosticConfig(project),
fileInfos,
preventBuild);
m_stopAction->disconnect();
connect(m_stopAction, &QAction::triggered, runControl, [runControl] {

View File

@@ -25,12 +25,13 @@
#include "clangtoolruncontrol.h"
#include "clangtidyclazyrunner.h"
#include "clangtidyclazytool.h"
#include "clangtool.h"
#include "clangtoolslogfilereader.h"
#include "clangtoolsprojectsettings.h"
#include "clangtoolssettings.h"
#include "clangtoolsutils.h"
#include "clangtoolrunner.h"
#include <debugger/analyzer/analyzerconstants.h>
@@ -114,17 +115,21 @@ static QStringList extraClangToolsAppendOptions()
namespace ClangTools {
namespace Internal {
static ClangTool *tool()
{
return ClangTidyClazyTool::instance();
}
class ProjectBuilder : public RunWorker
{
public:
ProjectBuilder(RunControl *runControl, ClangToolRunWorker *parent)
: RunWorker(runControl), m_parent(parent)
ProjectBuilder(RunControl *runControl)
: RunWorker(runControl)
{
setId("ProjectBuilder");
}
void setEnabled(bool enabled) { m_enabled = enabled; }
bool success() const { return m_success; }
private:
@@ -145,7 +150,7 @@ private:
if (buildType == BuildConfiguration::Release) {
const QString wrongMode = ClangToolRunWorker::tr("Release");
const QString toolName = m_parent->tool()->name();
const QString toolName = tool()->name();
const QString title = ClangToolRunWorker::tr("Run %1 in %2 Mode?").arg(toolName, wrongMode);
const QString problem = ClangToolRunWorker::tr(
"You are trying to run the tool \"%1\" on an application in %2 mode. The tool is "
@@ -181,7 +186,6 @@ private:
}
private:
ClangToolRunWorker *m_parent;
bool m_enabled = true;
bool m_success = false;
};
@@ -229,30 +233,30 @@ static QDebug operator<<(QDebug debug, const AnalyzeUnits &analyzeUnits)
}
ClangToolRunWorker::ClangToolRunWorker(RunControl *runControl,
const ClangDiagnosticConfig &diagnosticConfig,
const FileInfos &fileInfos,
bool preventBuild)
: RunWorker(runControl)
, m_temporaryDir("clangtools-XXXXXX")
, m_diagnosticConfig(diagnosticConfig)
, m_fileInfos(fileInfos)
{
if (preventBuild)
return;
m_projectBuilder = new ProjectBuilder(runControl, this);
addStartDependency(m_projectBuilder);
ClangToolsProjectSettings *projectSettings = ClangToolsProjectSettingsManager::getSettings(
runControl->project());
if (projectSettings->useGlobalSettings())
m_projectBuilder->setEnabled(ClangToolsSettings::instance()->savedBuildBeforeAnalysis());
else
m_projectBuilder->setEnabled(projectSettings->buildBeforeAnalysis());
}
void ClangToolRunWorker::init()
{
setId("ClangTidyClazyRunner");
setSupportsReRunning(false);
Target *target = runControl()->target();
if (!preventBuild) {
m_projectBuilder = new ProjectBuilder(runControl);
addStartDependency(m_projectBuilder);
ClangToolsProjectSettings *projectSettings = ClangToolsProjectSettingsManager::getSettings(
runControl->project());
if (projectSettings->useGlobalSettings())
m_projectBuilder->setEnabled(ClangToolsSettings::instance()->savedBuildBeforeAnalysis());
else
m_projectBuilder->setEnabled(projectSettings->buildBeforeAnalysis());
}
Target *target = runControl->target();
m_projectInfoBeforeBuild = CppTools::CppModelManager::instance()->projectInfo(target->project());
BuildConfiguration *buildConfiguration = target->activeBuildConfiguration();
@@ -266,6 +270,23 @@ void ClangToolRunWorker::init()
m_toolChainType = toolChain->typeId();
}
QList<RunnerCreator> ClangToolRunWorker::runnerCreators()
{
QList<RunnerCreator> creators;
if (m_diagnosticConfig.clangTidyMode() != CppTools::ClangDiagnosticConfig::TidyMode::Disabled)
creators << [this]() { return createRunner<ClangTidyRunner>(); };
if (!m_diagnosticConfig.clazyChecks().isEmpty()) {
if (!qEnvironmentVariable("QTC_USE_CLAZY_STANDALONE_PATH").isEmpty())
creators << [this]() { return createRunner<ClazyStandaloneRunner>(); };
else
creators << [this]() { return createRunner<ClazyPluginRunner>(); };
}
return creators;
}
void ClangToolRunWorker::start()
{
TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID);
@@ -505,5 +526,17 @@ void ClangToolRunWorker::finalize()
runControl()->initiateStop();
}
template<class T>
ClangToolRunner *ClangToolRunWorker::createRunner()
{
auto runner = new T(m_diagnosticConfig, this);
runner->init(m_temporaryDir.path(), m_environment);
connect(runner, &ClangToolRunner::finishedWithSuccess,
this, &ClangToolRunWorker::onRunnerFinishedWithSuccess);
connect(runner, &ClangToolRunner::finishedWithFailure,
this, &ClangToolRunWorker::onRunnerFinishedWithFailure);
return runner;
}
} // namespace Internal
} // namespace ClangTools

View File

@@ -27,8 +27,9 @@
#include "clangfileinfo.h"
#include <projectexplorer/runcontrol.h>
#include <cpptools/clangdiagnosticconfig.h>
#include <cpptools/projectinfo.h>
#include <projectexplorer/runcontrol.h>
#include <utils/environment.h>
#include <utils/temporarydirectory.h>
@@ -39,7 +40,6 @@
namespace ClangTools {
namespace Internal {
class ClangTool;
class ClangToolRunner;
class ProjectBuilder;
@@ -66,18 +66,13 @@ class ClangToolRunWorker : public ProjectExplorer::RunWorker
public:
ClangToolRunWorker(ProjectExplorer::RunControl *runControl,
const CppTools::ClangDiagnosticConfig &diagnosticConfig,
const FileInfos &fileInfos,
bool preventBuild);
bool success() const { return m_success; } // For testing.
virtual ClangTool *tool() = 0;
protected:
void init();
virtual QList<RunnerCreator> runnerCreators() = 0;
void onRunnerFinishedWithSuccess(const QString &filePath);
void onRunnerFinishedWithFailure(const QString &errorMessage, const QString &errorDetails);
@@ -85,6 +80,9 @@ private:
void start() final;
void stop() final;
QList<RunnerCreator> runnerCreators();
template <class T> ClangToolRunner *createRunner();
AnalyzeUnits unitsToAnalyze();
void analyzeNextFile();
@@ -101,6 +99,7 @@ protected:
Utils::TemporaryDirectory m_temporaryDir;
private:
CppTools::ClangDiagnosticConfig m_diagnosticConfig;
FileInfos m_fileInfos;
CppTools::ProjectInfo m_projectInfoBeforeBuild;

View File

@@ -21,7 +21,6 @@ SOURCES += \
clangselectablefilesdialog.cpp \
clangtoolsdiagnosticview.cpp \
clangtoolsprojectsettingswidget.cpp \
clangtidyclazyruncontrol.cpp \
clangtidyclazyrunner.cpp \
clangtidyclazytool.cpp \
clangtool.cpp \
@@ -43,7 +42,6 @@ HEADERS += \
clangselectablefilesdialog.h \
clangtoolsdiagnosticview.h \
clangtoolsprojectsettingswidget.h \
clangtidyclazyruncontrol.h \
clangtidyclazyrunner.h \
clangtidyclazytool.h \
clangtool.h \

View File

@@ -40,8 +40,6 @@ QtcPlugin {
"clangselectablefilesdialog.cpp",
"clangselectablefilesdialog.h",
"clangselectablefilesdialog.ui",
"clangtidyclazyruncontrol.cpp",
"clangtidyclazyruncontrol.h",
"clangtidyclazyrunner.cpp",
"clangtidyclazyrunner.h",
"clangtidyclazytool.cpp",