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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "clangtidyclazyrunner.h"
|
|
|
|
|
|
2018-05-07 15:40:14 +02:00
|
|
|
#include "clangtoolssettings.h"
|
|
|
|
|
|
2019-01-11 15:32:12 +01:00
|
|
|
#include <cpptools/compileroptionsbuilder.h>
|
2018-01-17 15:08:30 +01:00
|
|
|
#include <cpptools/cppcodemodelsettings.h>
|
|
|
|
|
#include <cpptools/cpptoolsreuse.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/synchronousprocess.h>
|
2018-05-07 15:40:14 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2018-01-17 15:08:30 +01:00
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
|
2018-10-12 09:33:30 +03:00
|
|
|
static Q_LOGGING_CATEGORY(LOG, "qtc.clangtools.runner", QtWarningMsg)
|
2018-01-17 15:08:30 +01:00
|
|
|
|
2019-08-01 14:54:15 +02:00
|
|
|
using namespace CppTools;
|
|
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
namespace ClangTools {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2019-08-01 14:54:15 +02:00
|
|
|
static QStringList commonArguments(const QStringList &options,
|
|
|
|
|
const QString &logFile,
|
|
|
|
|
const ClangDiagnosticConfig diagnosticConfig)
|
2018-01-17 15:08:30 +01:00
|
|
|
{
|
|
|
|
|
QStringList arguments;
|
|
|
|
|
if (LOG().isDebugEnabled())
|
2019-01-11 15:32:12 +01:00
|
|
|
arguments << QLatin1String("-v");
|
|
|
|
|
|
2019-08-01 14:54:15 +02:00
|
|
|
const QStringList serializeArgs{"-serialize-diagnostics", logFile};
|
2019-01-11 15:32:12 +01:00
|
|
|
if (options.contains("--driver-mode=cl"))
|
|
|
|
|
arguments << clangArgsForCl(serializeArgs);
|
|
|
|
|
else
|
|
|
|
|
arguments << serializeArgs;
|
2018-01-17 15:08:30 +01:00
|
|
|
|
2019-01-11 15:32:12 +01:00
|
|
|
arguments << ClangDiagnosticConfigsModel::globalDiagnosticOptions()
|
2019-08-01 14:54:15 +02:00
|
|
|
<< diagnosticConfig.clangOptions();
|
|
|
|
|
|
|
|
|
|
return arguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QStringList tidyPluginArguments(const ClangDiagnosticConfig diagnosticConfig)
|
|
|
|
|
{
|
|
|
|
|
QStringList arguments;
|
2018-01-17 15:08:30 +01:00
|
|
|
|
2019-08-01 14:54:15 +02:00
|
|
|
const ClangDiagnosticConfig::TidyMode tidyMode = diagnosticConfig.clangTidyMode();
|
2018-01-17 15:08:30 +01:00
|
|
|
if (tidyMode != ClangDiagnosticConfig::TidyMode::Disabled) {
|
2019-01-11 15:32:12 +01:00
|
|
|
arguments << XclangArgs({"-add-plugin", "clang-tidy"});
|
2018-01-17 15:08:30 +01:00
|
|
|
if (tidyMode != ClangDiagnosticConfig::TidyMode::File) {
|
2019-08-01 14:54:15 +02:00
|
|
|
const QString tidyChecks = diagnosticConfig.clangTidyChecks();
|
2019-01-11 15:32:12 +01:00
|
|
|
arguments << XclangArgs({"-plugin-arg-clang-tidy", "-checks=" + tidyChecks});
|
2018-01-17 15:08:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 14:54:15 +02:00
|
|
|
return arguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QStringList clazyPluginArguments(const ClangDiagnosticConfig diagnosticConfig)
|
|
|
|
|
{
|
|
|
|
|
QStringList arguments;
|
|
|
|
|
|
|
|
|
|
const QString clazyChecks = diagnosticConfig.clazyChecks();
|
2018-01-17 15:08:30 +01:00
|
|
|
if (!clazyChecks.isEmpty()) {
|
2019-01-11 15:32:12 +01:00
|
|
|
arguments << XclangArgs({"-add-plugin",
|
2019-04-04 14:50:10 +02:00
|
|
|
"clazy",
|
|
|
|
|
"-plugin-arg-clazy",
|
2019-01-11 15:32:12 +01:00
|
|
|
"enable-all-fixits",
|
2019-04-04 14:50:10 +02:00
|
|
|
"-plugin-arg-clazy",
|
2019-01-11 15:32:12 +01:00
|
|
|
"no-autowrite-fixits",
|
2019-04-04 14:50:10 +02:00
|
|
|
"-plugin-arg-clazy",
|
2019-08-01 14:54:15 +02:00
|
|
|
diagnosticConfig.clazyChecks()});
|
2018-01-17 15:08:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arguments;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 15:18:32 +02:00
|
|
|
ClangTidyRunner::ClangTidyRunner(const ClangDiagnosticConfig &config, QObject *parent)
|
2019-08-01 14:54:15 +02:00
|
|
|
: ClangToolRunner(parent)
|
|
|
|
|
{
|
2019-08-01 15:18:32 +02:00
|
|
|
setName(tr("Clang-Tidy"));
|
2019-08-01 14:54:15 +02:00
|
|
|
setArgsCreator([this, config](const QStringList &baseOptions) {
|
|
|
|
|
return commonArguments(baseOptions, m_logFile, config)
|
|
|
|
|
<< tidyPluginArguments(config)
|
|
|
|
|
<< baseOptions
|
|
|
|
|
<< QDir::toNativeSeparators(filePath());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 15:18:32 +02:00
|
|
|
ClazyRunner::ClazyRunner(const ClangDiagnosticConfig &config, QObject *parent)
|
|
|
|
|
: ClangToolRunner(parent)
|
|
|
|
|
{
|
|
|
|
|
setName(tr("Clazy"));
|
|
|
|
|
setArgsCreator([this, config](const QStringList &baseOptions) {
|
|
|
|
|
return commonArguments(baseOptions, m_logFile, config)
|
|
|
|
|
<< clazyPluginArguments(config) << baseOptions
|
|
|
|
|
<< QDir::toNativeSeparators(filePath());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClangTools
|