2014-09-25 11:11:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-14 10:59:10 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-09-25 11:11:58 +02:00
|
|
|
**
|
2016-01-14 10:59:10 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-09-25 11:11:58 +02:00
|
|
|
**
|
2016-01-14 10:59:10 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
2014-09-25 11:11:58 +02:00
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-14 10:59:10 +01:00
|
|
|
** 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.
|
2014-09-25 11:11:58 +02:00
|
|
|
**
|
2016-01-14 10:59:10 +01:00
|
|
|
** 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.
|
2014-09-25 11:11:58 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
#include "clangtoolsutils.h"
|
2014-09-25 11:11:58 +02:00
|
|
|
|
2019-06-25 11:10:00 +02:00
|
|
|
#include "clangtool.h"
|
2019-08-28 08:56:22 +02:00
|
|
|
#include "clangtoolsconstants.h"
|
2018-01-17 15:08:30 +01:00
|
|
|
#include "clangtoolsdiagnostic.h"
|
|
|
|
|
#include "clangtoolssettings.h"
|
2014-09-25 11:11:58 +02:00
|
|
|
|
2018-04-30 15:26:36 +02:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
2015-07-07 15:24:47 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
|
2019-06-25 11:10:00 +02:00
|
|
|
#include <utils/checkablemessagebox.h>
|
2014-09-25 11:11:58 +02:00
|
|
|
#include <utils/environment.h>
|
2019-06-25 11:10:00 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2016-07-12 18:50:47 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
2014-09-25 11:11:58 +02:00
|
|
|
|
2015-02-26 15:14:29 +01:00
|
|
|
#include <QCoreApplication>
|
2014-09-25 11:11:58 +02:00
|
|
|
#include <QFileInfo>
|
2016-07-12 18:50:47 +02:00
|
|
|
#include <QRegularExpression>
|
2014-09-25 11:11:58 +02:00
|
|
|
|
2018-03-14 12:58:12 +01:00
|
|
|
namespace ClangTools {
|
2014-09-25 11:11:58 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
QString createFullLocationString(const Debugger::DiagnosticLocation &location)
|
2014-09-25 11:11:58 +02:00
|
|
|
{
|
2018-01-17 15:08:30 +01:00
|
|
|
return location.filePath + QLatin1Char(':') + QString::number(location.line)
|
|
|
|
|
+ QLatin1Char(':') + QString::number(location.column);
|
2014-09-25 11:11:58 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-25 11:10:00 +02:00
|
|
|
QString hintAboutBuildBeforeAnalysis()
|
|
|
|
|
{
|
|
|
|
|
return ClangTool::tr(
|
|
|
|
|
"In general, the project should be built before starting the analysis to ensure that the "
|
|
|
|
|
"code to analyze is valid.<br/><br/>"
|
|
|
|
|
"Building the project might also run code generators that update the source files as "
|
|
|
|
|
"necessary.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void showHintAboutBuildBeforeAnalysis()
|
|
|
|
|
{
|
|
|
|
|
Utils::CheckableMessageBox::doNotShowAgainInformation(
|
|
|
|
|
Core::ICore::dialogParent(),
|
|
|
|
|
ClangTool::tr("Info About Build the Project Before Analysis"),
|
|
|
|
|
hintAboutBuildBeforeAnalysis(),
|
|
|
|
|
Core::ICore::settings(),
|
|
|
|
|
"ClangToolsDisablingBuildBeforeAnalysisHint");
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-28 08:56:22 +02:00
|
|
|
bool isFileExecutable(const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
if (filePath.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const QFileInfo fileInfo(filePath);
|
|
|
|
|
return fileInfo.isFile() && fileInfo.isExecutable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString shippedClangTidyExecutable()
|
|
|
|
|
{
|
|
|
|
|
const QString shippedExecutable = Core::ICore::clangTidyExecutable(CLANG_BINDIR);
|
|
|
|
|
if (isFileExecutable(shippedExecutable))
|
|
|
|
|
return shippedExecutable;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString shippedClazyStandaloneExecutable()
|
|
|
|
|
{
|
|
|
|
|
const QString shippedExecutable = Core::ICore::clazyStandaloneExecutable(CLANG_BINDIR);
|
|
|
|
|
if (isFileExecutable(shippedExecutable))
|
|
|
|
|
return shippedExecutable;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString fullPath(const QString &executable)
|
|
|
|
|
{
|
|
|
|
|
const QString hostExeSuffix = QLatin1String(QTC_HOST_EXE_SUFFIX);
|
|
|
|
|
const Qt::CaseSensitivity caseSensitivity = Utils::HostOsInfo::fileNameCaseSensitivity();
|
|
|
|
|
|
|
|
|
|
QString candidate = executable;
|
|
|
|
|
const bool hasSuffix = candidate.endsWith(hostExeSuffix, caseSensitivity);
|
|
|
|
|
|
|
|
|
|
const QFileInfo fileInfo = QFileInfo(candidate);
|
|
|
|
|
if (fileInfo.isAbsolute()) {
|
|
|
|
|
if (!hasSuffix)
|
|
|
|
|
candidate.append(hostExeSuffix);
|
|
|
|
|
} else {
|
|
|
|
|
const Utils::Environment environment = Utils::Environment::systemEnvironment();
|
|
|
|
|
const QString expandedPath = environment.searchInPath(candidate).toString();
|
|
|
|
|
if (!expandedPath.isEmpty())
|
|
|
|
|
candidate = expandedPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return candidate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString findValidExecutable(const QStringList &candidates)
|
|
|
|
|
{
|
|
|
|
|
for (QString candidate : candidates) {
|
|
|
|
|
const QString expandedPath = fullPath(candidate);
|
|
|
|
|
if (isFileExecutable(expandedPath))
|
|
|
|
|
return expandedPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString clangTidyExecutable()
|
|
|
|
|
{
|
|
|
|
|
const QString fromSettings = ClangToolsSettings::instance()->clangTidyExecutable();
|
|
|
|
|
if (!fromSettings.isEmpty())
|
|
|
|
|
return fullPath(fromSettings);
|
|
|
|
|
|
|
|
|
|
return findValidExecutable({
|
|
|
|
|
shippedClangTidyExecutable(),
|
|
|
|
|
Constants::CLANG_TIDY_EXECUTABLE_NAME,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString clazyStandaloneExecutable()
|
|
|
|
|
{
|
|
|
|
|
const QString fromSettings = ClangToolsSettings::instance()->clazyStandaloneExecutable();
|
|
|
|
|
if (!fromSettings.isEmpty())
|
|
|
|
|
return fullPath(fromSettings);
|
|
|
|
|
|
|
|
|
|
return findValidExecutable({
|
|
|
|
|
shippedClazyStandaloneExecutable(),
|
|
|
|
|
qEnvironmentVariable("QTC_USE_CLAZY_STANDALONE_PATH"),
|
|
|
|
|
Constants::CLAZY_STANDALONE_EXECUTABLE_NAME,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-25 11:11:58 +02:00
|
|
|
} // namespace Internal
|
2018-03-14 12:58:12 +01:00
|
|
|
} // namespace ClangTools
|