ClangTools: Proliferate use of FilePath

Change-Id: I3eb16546a729ab01c10e37572adac9aef83f5cd4
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-08-12 09:19:55 +02:00
parent a7e8ddd725
commit f29bc8c787
25 changed files with 136 additions and 145 deletions

View File

@@ -141,8 +141,7 @@ ClangModelManagerSupport::ClangModelManagerSupport()
claimNonProjectSources(fallbackClient); claimNonProjectSources(fallbackClient);
}); });
CppTools::ClangdSettings::setDefaultClangdPath(Utils::FilePath::fromString( CppTools::ClangdSettings::setDefaultClangdPath(Core::ICore::clangdExecutable(CLANG_BINDIR));
Core::ICore::clangdExecutable(CLANG_BINDIR)));
connect(&CppTools::ClangdSettings::instance(), &CppTools::ClangdSettings::changed, connect(&CppTools::ClangdSettings::instance(), &CppTools::ClangdSettings::changed,
this, &ClangModelManagerSupport::onClangdSettingsChanged); this, &ClangModelManagerSupport::onClangdSettingsChanged);
CppTools::CppCodeModelSettings *settings = CppTools::codeModelSettings(); CppTools::CppCodeModelSettings *settings = CppTools::codeModelSettings();

View File

@@ -76,7 +76,7 @@ public:
UseLanguageDefines::No, UseLanguageDefines::No,
useBuildSystemWarnings, useBuildSystemWarnings,
QString(CLANG_VERSION), QString(CLANG_VERSION),
QString(CLANG_INCLUDE_DIR)) FilePath(CLANG_INCLUDE_DIR))
{ {
} }

View File

@@ -896,12 +896,12 @@ static CheckResult canAnalyze()
{ {
const ClangDiagnosticConfig config = diagnosticConfig(runSettings().diagnosticConfigId()); const ClangDiagnosticConfig config = diagnosticConfig(runSettings().diagnosticConfigId());
if (config.isClangTidyEnabled() && !isFileExecutable(clangTidyExecutable())) { if (config.isClangTidyEnabled() && !clangTidyExecutable().isExecutableFile()) {
return {CheckResult::InvalidTidyExecutable, return {CheckResult::InvalidTidyExecutable,
ClangTool::tr("Set a valid Clang-Tidy executable.")}; ClangTool::tr("Set a valid Clang-Tidy executable.")};
} }
if (config.isClazyEnabled() && !isFileExecutable(clazyStandaloneExecutable())) { if (config.isClazyEnabled() && !clazyStandaloneExecutable().isExecutableFile()) {
return {CheckResult::InvalidClazyExecutable, return {CheckResult::InvalidClazyExecutable,
ClangTool::tr("Set a valid Clazy-Standalone executable.")}; ClangTool::tr("Set a valid Clazy-Standalone executable.")};
} }

View File

@@ -125,7 +125,7 @@ AnalyzeUnit::AnalyzeUnit(const FileInfo &fileInfo,
UseLanguageDefines::No, UseLanguageDefines::No,
UseBuildSystemWarnings::No, UseBuildSystemWarnings::No,
clangVersion, clangVersion,
clangIncludeDir.toString()); clangIncludeDir);
file = fileInfo.file.toString(); file = fileInfo.file.toString();
arguments = extraClangToolsPrependOptions(); arguments = extraClangToolsPrependOptions();
arguments.append(optionsBuilder.build(fileInfo.kind, CppTools::getPchUsage())); arguments.append(optionsBuilder.build(fileInfo.kind, CppTools::getPchUsage()));

View File

@@ -101,11 +101,11 @@ QStringList ClangToolRunner::mainToolArguments() const
bool ClangToolRunner::supportsVFSOverlay() const bool ClangToolRunner::supportsVFSOverlay() const
{ {
static QMap<QString, bool> vfsCapabilities; static QMap<FilePath, bool> vfsCapabilities;
auto it = vfsCapabilities.find(m_executable); auto it = vfsCapabilities.find(m_executable);
if (it == vfsCapabilities.end()) { if (it == vfsCapabilities.end()) {
QtcProcess p; QtcProcess p;
p.setCommand({FilePath::fromString(m_executable), {"--help"}}); p.setCommand({m_executable, {"--help"}});
p.runBlocking(); p.runBlocking();
it = vfsCapabilities.insert(m_executable, p.allOutput().contains("vfsoverlay")); it = vfsCapabilities.insert(m_executable, p.allOutput().contains("vfsoverlay"));
} }
@@ -137,7 +137,7 @@ bool ClangToolRunner::run(const QString &fileToAnalyze, const QStringList &compi
m_outputFilePath = createOutputFilePath(m_outputDirPath, fileToAnalyze); m_outputFilePath = createOutputFilePath(m_outputDirPath, fileToAnalyze);
QTC_ASSERT(!m_outputFilePath.isEmpty(), return false); QTC_ASSERT(!m_outputFilePath.isEmpty(), return false);
m_commandLine = {FilePath::fromString(m_executable), m_argsCreator(compilerOptions)}; m_commandLine = {m_executable, m_argsCreator(compilerOptions)};
qCDebug(LOG).noquote() << "Starting" << m_commandLine.toUserOutput(); qCDebug(LOG).noquote() << "Starting" << m_commandLine.toUserOutput();
m_process->setCommand(m_commandLine); m_process->setCommand(m_commandLine);

View File

@@ -46,13 +46,13 @@ public:
void init(const Utils::FilePath &outputDirPath, const Utils::Environment &environment); void init(const Utils::FilePath &outputDirPath, const Utils::Environment &environment);
void setName(const QString &name) { m_name = name; } void setName(const QString &name) { m_name = name; }
void setExecutable(const QString &executable) { m_executable = executable; } void setExecutable(const Utils::FilePath &executable) { m_executable = executable; }
void setArgsCreator(const ArgsCreator &argsCreator) { m_argsCreator = argsCreator; } void setArgsCreator(const ArgsCreator &argsCreator) { m_argsCreator = argsCreator; }
void setOutputFileFormat(const OutputFileFormat &format) { m_outputFileFormat = format; } void setOutputFileFormat(const OutputFileFormat &format) { m_outputFileFormat = format; }
void setVFSOverlay(const QString overlayFilePath) { m_overlayFilePath = overlayFilePath; } void setVFSOverlay(const QString overlayFilePath) { m_overlayFilePath = overlayFilePath; }
QString name() const { return m_name; } QString name() const { return m_name; }
QString executable() const { return m_executable; } Utils::FilePath executable() const { return m_executable; }
OutputFileFormat outputFileFormat() const { return m_outputFileFormat; } OutputFileFormat outputFileFormat() const { return m_outputFileFormat; }
QString fileToAnalyze() const { return m_fileToAnalyze; } QString fileToAnalyze() const { return m_fileToAnalyze; }
QString outputFilePath() const { return m_outputFilePath; } QString outputFilePath() const { return m_outputFilePath; }
@@ -83,7 +83,7 @@ private:
Utils::QtcProcess *m_process = nullptr; Utils::QtcProcess *m_process = nullptr;
QString m_name; QString m_name;
QString m_executable; Utils::FilePath m_executable;
ArgsCreator m_argsCreator; ArgsCreator m_argsCreator;
OutputFileFormat m_outputFileFormat = OutputFileFormat::Yaml; OutputFileFormat m_outputFileFormat = OutputFileFormat::Yaml;

View File

@@ -46,6 +46,7 @@ static const char analyzeOpenFilesKey[] = "AnalyzeOpenFiles";
static const char oldDiagnosticConfigIdKey[] = "diagnosticConfigId"; static const char oldDiagnosticConfigIdKey[] = "diagnosticConfigId";
using namespace CppTools; using namespace CppTools;
using namespace Utils;
namespace ClangTools { namespace ClangTools {
namespace Internal { namespace Internal {
@@ -151,8 +152,8 @@ void ClangToolsSettings::readSettings()
QSettings *s = Core::ICore::settings(); QSettings *s = Core::ICore::settings();
s->beginGroup(Constants::SETTINGS_ID); s->beginGroup(Constants::SETTINGS_ID);
m_clangTidyExecutable = s->value(clangTidyExecutableKey).toString(); m_clangTidyExecutable = FilePath::fromVariant(s->value(clangTidyExecutableKey));
m_clazyStandaloneExecutable = s->value(clazyStandaloneExecutableKey).toString(); m_clazyStandaloneExecutable = FilePath::fromVariant(s->value(clazyStandaloneExecutableKey));
m_diagnosticConfigs.append(diagnosticConfigsFromSettings(s)); m_diagnosticConfigs.append(diagnosticConfigsFromSettings(s));
QVariantMap map; QVariantMap map;
@@ -184,8 +185,8 @@ void ClangToolsSettings::writeSettings()
QSettings *s = Core::ICore::settings(); QSettings *s = Core::ICore::settings();
s->beginGroup(Constants::SETTINGS_ID); s->beginGroup(Constants::SETTINGS_ID);
s->setValue(clangTidyExecutableKey, m_clangTidyExecutable); s->setValue(clangTidyExecutableKey, m_clangTidyExecutable.toVariant());
s->setValue(clazyStandaloneExecutableKey, m_clazyStandaloneExecutable); s->setValue(clazyStandaloneExecutableKey, m_clazyStandaloneExecutable.toVariant());
diagnosticConfigsToSettings(s, m_diagnosticConfigs); diagnosticConfigsToSettings(s, m_diagnosticConfigs);
QVariantMap map; QVariantMap map;
@@ -198,24 +199,22 @@ void ClangToolsSettings::writeSettings()
emit changed(); emit changed();
} }
void ClangToolsSettings::setClangTidyExecutable(const QString &path) void ClangToolsSettings::setClangTidyExecutable(const FilePath &path)
{ {
m_clangTidyExecutable = path; m_clangTidyExecutable = path;
m_clangTidyVersion = {}; m_clangTidyVersion = {};
} }
void ClangTools::Internal::ClangToolsSettings::setClazyStandaloneExecutable(const QString &path) void ClangToolsSettings::setClazyStandaloneExecutable(const FilePath &path)
{ {
m_clazyStandaloneExecutable = path; m_clazyStandaloneExecutable = path;
m_clazyVersion = {}; m_clazyVersion = {};
} }
static QVersionNumber getVersionNumber(QVersionNumber &version, const QString &toolFilePath) static QVersionNumber getVersionNumber(QVersionNumber &version, const FilePath &toolFilePath)
{ {
if (version.isNull() && !toolFilePath.isEmpty()) { if (version.isNull() && !toolFilePath.isEmpty())
version = QVersionNumber::fromString(queryVersion(Utils::FilePath::fromString(toolFilePath), version = QVersionNumber::fromString(queryVersion(toolFilePath, QueryFailMode::Silent));
QueryFailMode::Silent));
};
return version; return version;
} }

View File

@@ -77,11 +77,11 @@ public:
static ClangToolsSettings *instance(); static ClangToolsSettings *instance();
void writeSettings(); void writeSettings();
QString clangTidyExecutable() const { return m_clangTidyExecutable; } Utils::FilePath clangTidyExecutable() const { return m_clangTidyExecutable; }
void setClangTidyExecutable(const QString &path); void setClangTidyExecutable(const Utils::FilePath &path);
QString clazyStandaloneExecutable() const { return m_clazyStandaloneExecutable; } Utils::FilePath clazyStandaloneExecutable() const { return m_clazyStandaloneExecutable; }
void setClazyStandaloneExecutable(const QString &path); void setClazyStandaloneExecutable(const Utils::FilePath &path);
CppTools::ClangDiagnosticConfigs diagnosticConfigs() const { return m_diagnosticConfigs; } CppTools::ClangDiagnosticConfigs diagnosticConfigs() const { return m_diagnosticConfigs; }
void setDiagnosticConfigs(const CppTools::ClangDiagnosticConfigs &configs) void setDiagnosticConfigs(const CppTools::ClangDiagnosticConfigs &configs)
@@ -101,8 +101,8 @@ private:
void readSettings(); void readSettings();
// Executables // Executables
QString m_clangTidyExecutable; Utils::FilePath m_clangTidyExecutable;
QString m_clazyStandaloneExecutable; Utils::FilePath m_clazyStandaloneExecutable;
// Diagnostic Configs // Diagnostic Configs
CppTools::ClangDiagnosticConfigs m_diagnosticConfigs; CppTools::ClangDiagnosticConfigs m_diagnosticConfigs;

View File

@@ -37,6 +37,7 @@
#include <utils/checkablemessagebox.h> #include <utils/checkablemessagebox.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/filepath.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
@@ -45,6 +46,7 @@
#include <cpptools/clangdiagnosticconfigsmodel.h> #include <cpptools/clangdiagnosticconfigsmodel.h>
using namespace CppTools; using namespace CppTools;
using namespace Utils;
namespace ClangTools { namespace ClangTools {
namespace Internal { namespace Internal {
@@ -170,46 +172,36 @@ void showHintAboutBuildBeforeAnalysis()
"ClangToolsDisablingBuildBeforeAnalysisHint"); "ClangToolsDisablingBuildBeforeAnalysisHint");
} }
bool isFileExecutable(const QString &filePath) FilePath shippedClangTidyExecutable()
{ {
if (filePath.isEmpty()) const FilePath shippedExecutable = Core::ICore::clangTidyExecutable(CLANG_BINDIR);
return false; if (shippedExecutable.isExecutableFile())
const QFileInfo fileInfo(filePath);
return fileInfo.exists() && fileInfo.isFile() && fileInfo.isExecutable();
}
QString shippedClangTidyExecutable()
{
const QString shippedExecutable = Core::ICore::clangTidyExecutable(CLANG_BINDIR);
if (isFileExecutable(shippedExecutable))
return shippedExecutable; return shippedExecutable;
return {}; return {};
} }
QString shippedClazyStandaloneExecutable() FilePath shippedClazyStandaloneExecutable()
{ {
const QString shippedExecutable = Core::ICore::clazyStandaloneExecutable(CLANG_BINDIR); const FilePath shippedExecutable = Core::ICore::clazyStandaloneExecutable(CLANG_BINDIR);
if (isFileExecutable(shippedExecutable)) if (shippedExecutable.isExecutableFile())
return shippedExecutable; return shippedExecutable;
return {}; return {};
} }
QString fullPath(const QString &executable) FilePath fullPath(const FilePath &executable)
{ {
const QString hostExeSuffix = QLatin1String(QTC_HOST_EXE_SUFFIX); const QString hostExeSuffix = QLatin1String(QTC_HOST_EXE_SUFFIX);
const Qt::CaseSensitivity caseSensitivity = Utils::HostOsInfo::fileNameCaseSensitivity(); const Qt::CaseSensitivity caseSensitivity = Utils::HostOsInfo::fileNameCaseSensitivity();
QString candidate = executable; FilePath candidate = executable;
const bool hasSuffix = candidate.endsWith(hostExeSuffix, caseSensitivity); const bool hasSuffix = candidate.toString().endsWith(hostExeSuffix, caseSensitivity);
const QFileInfo fileInfo = QFileInfo(candidate); if (candidate.isAbsolutePath()) {
if (fileInfo.isAbsolute()) {
if (!hasSuffix) if (!hasSuffix)
candidate.append(hostExeSuffix); candidate = candidate.withExecutableSuffix();
} else { } else {
const Utils::Environment environment = Utils::Environment::systemEnvironment(); const Environment environment = Environment::systemEnvironment();
const QString expandedPath = environment.searchInPath(candidate).toString(); const FilePath expandedPath = environment.searchInPath(candidate.toString());
if (!expandedPath.isEmpty()) if (!expandedPath.isEmpty())
candidate = expandedPath; candidate = expandedPath;
} }
@@ -217,18 +209,18 @@ QString fullPath(const QString &executable)
return candidate; return candidate;
} }
static QString findValidExecutable(const QStringList &candidates) static FilePath findValidExecutable(const FilePaths &candidates)
{ {
for (const QString &candidate : candidates) { for (const FilePath &candidate : candidates) {
const QString expandedPath = fullPath(candidate); const FilePath expandedPath = fullPath(candidate);
if (isFileExecutable(expandedPath)) if (expandedPath.isExecutableFile())
return expandedPath; return expandedPath;
} }
return {}; return {};
} }
QString clangTidyFallbackExecutable() FilePath clangTidyFallbackExecutable()
{ {
return findValidExecutable({ return findValidExecutable({
shippedClangTidyExecutable(), shippedClangTidyExecutable(),
@@ -236,15 +228,15 @@ QString clangTidyFallbackExecutable()
}); });
} }
QString clangTidyExecutable() FilePath clangTidyExecutable()
{ {
const QString fromSettings = ClangToolsSettings::instance()->clangTidyExecutable(); const FilePath fromSettings = ClangToolsSettings::instance()->clangTidyExecutable();
if (!fromSettings.isEmpty()) if (!fromSettings.isEmpty())
return fullPath(fromSettings); return fullPath(fromSettings);
return clangTidyFallbackExecutable(); return clangTidyFallbackExecutable();
} }
QString clazyStandaloneFallbackExecutable() FilePath clazyStandaloneFallbackExecutable()
{ {
return findValidExecutable({ return findValidExecutable({
shippedClazyStandaloneExecutable(), shippedClazyStandaloneExecutable(),
@@ -252,9 +244,9 @@ QString clazyStandaloneFallbackExecutable()
}); });
} }
QString clazyStandaloneExecutable() FilePath clazyStandaloneExecutable()
{ {
const QString fromSettings = ClangToolsSettings::instance()->clazyStandaloneExecutable(); const FilePath fromSettings = ClangToolsSettings::instance()->clazyStandaloneExecutable();
if (!fromSettings.isEmpty()) if (!fromSettings.isEmpty())
return fullPath(fromSettings); return fullPath(fromSettings);
return clazyStandaloneFallbackExecutable(); return clazyStandaloneFallbackExecutable();

View File

@@ -32,12 +32,9 @@
#include <QtGlobal> #include <QtGlobal>
QT_BEGIN_NAMESPACE
class QString;
QT_END_NAMESPACE
namespace CppTools { class ClangDiagnosticConfigsModel; } namespace CppTools { class ClangDiagnosticConfigsModel; }
namespace Debugger { class DiagnosticLocation; } namespace Debugger { class DiagnosticLocation; }
namespace Utils { class FilePath; }
namespace ClangTools { namespace ClangTools {
namespace Internal { namespace Internal {
@@ -68,17 +65,15 @@ QString createFullLocationString(const Debugger::DiagnosticLocation &location);
QString hintAboutBuildBeforeAnalysis(); QString hintAboutBuildBeforeAnalysis();
void showHintAboutBuildBeforeAnalysis(); void showHintAboutBuildBeforeAnalysis();
bool isFileExecutable(const QString &filePath); Utils::FilePath shippedClazyStandaloneExecutable();
Utils::FilePath clazyStandaloneExecutable();
Utils::FilePath clazyStandaloneFallbackExecutable();
QString shippedClazyStandaloneExecutable(); Utils::FilePath shippedClangTidyExecutable();
QString clazyStandaloneExecutable(); Utils::FilePath clangTidyExecutable();
QString clazyStandaloneFallbackExecutable(); Utils::FilePath clangTidyFallbackExecutable();
QString shippedClangTidyExecutable(); Utils::FilePath fullPath(const Utils::FilePath &executable);
QString clangTidyExecutable();
QString clangTidyFallbackExecutable();
QString fullPath(const QString &executable);
QString documentationUrl(const QString &checkName); QString documentationUrl(const QString &checkName);

View File

@@ -234,7 +234,7 @@ void DocumentClangToolRunner::run()
QPair<Utils::FilePath, QString> getClangIncludeDirAndVersion(ClangToolRunner *runner) QPair<Utils::FilePath, QString> getClangIncludeDirAndVersion(ClangToolRunner *runner)
{ {
static QMap<Utils::FilePath, QPair<Utils::FilePath, QString>> cache; static QMap<Utils::FilePath, QPair<Utils::FilePath, QString>> cache;
const Utils::FilePath tool = Utils::FilePath::fromString(runner->executable()); const Utils::FilePath tool = runner->executable();
auto it = cache.find(tool); auto it = cache.find(tool);
if (it == cache.end()) if (it == cache.end())
it = cache.insert(tool, getClangIncludeDirAndVersion(tool)); it = cache.insert(tool, getClangIncludeDirAndVersion(tool));

View File

@@ -158,17 +158,16 @@ static ClazyChecks querySupportedClazyChecks(const FilePath &executablePath)
return infos; return infos;
} }
ClangTidyInfo::ClangTidyInfo(const QString &executablePath) ClangTidyInfo::ClangTidyInfo(const FilePath &executablePath)
: defaultChecks(queryClangTidyChecks(FilePath::fromString(executablePath), {})) : defaultChecks(queryClangTidyChecks(executablePath, {}))
, supportedChecks(queryClangTidyChecks(FilePath::fromString(executablePath), "-checks=*")) , supportedChecks(queryClangTidyChecks(executablePath, "-checks=*"))
{} {}
ClazyStandaloneInfo::ClazyStandaloneInfo(const QString &executablePath) ClazyStandaloneInfo::ClazyStandaloneInfo(const FilePath &executablePath)
: defaultChecks(queryClangTidyChecks(FilePath::fromString(executablePath), {})) // Yup, behaves as clang-tidy. : defaultChecks(queryClangTidyChecks(executablePath, {})) // Yup, behaves as clang-tidy.
, supportedChecks(querySupportedClazyChecks(FilePath::fromString(executablePath))) , supportedChecks(querySupportedClazyChecks(executablePath))
{ {
QString output = runExecutable(CommandLine(FilePath::fromString(executablePath), {"--version"}), QString output = runExecutable({executablePath, {"--version"}}, QueryFailMode::Silent);
QueryFailMode::Silent);
QTextStream stream(&output); QTextStream stream(&output);
while (!stream.atEnd()) { while (!stream.atEnd()) {
// It's just "clazy version " right now, but let's be prepared for someone adding a colon // It's just "clazy version " right now, but let's be prepared for someone adding a colon

View File

@@ -25,7 +25,7 @@
#pragma once #pragma once
#include <utils/fileutils.h> #include <utils/filepath.h>
#include <QPair> #include <QPair>
#include <QStringList> #include <QStringList>
@@ -43,7 +43,7 @@ QString queryVersion(const Utils::FilePath &clangToolPath, QueryFailMode failMod
class ClangTidyInfo class ClangTidyInfo
{ {
public: public:
ClangTidyInfo(const QString &executablePath); ClangTidyInfo(const Utils::FilePath &executablePath);
QStringList defaultChecks; QStringList defaultChecks;
QStringList supportedChecks; QStringList supportedChecks;
}; };
@@ -60,7 +60,7 @@ using ClazyChecks = QVector<ClazyCheck>;
class ClazyStandaloneInfo class ClazyStandaloneInfo
{ {
public: public:
ClazyStandaloneInfo(const QString &executablePath); ClazyStandaloneInfo(const Utils::FilePath &executablePath);
QVersionNumber version; QVersionNumber version;
QStringList defaultChecks; QStringList defaultChecks;

View File

@@ -36,6 +36,8 @@
#include <QThread> #include <QThread>
using namespace Utils;
namespace ClangTools { namespace ClangTools {
namespace Internal { namespace Internal {
@@ -60,8 +62,8 @@ static CppTools::ClangDiagnosticConfigsWidget *createEditWidget(
const CppTools::ClangDiagnosticConfigs &configs, const Utils::Id &configToSelect) const CppTools::ClangDiagnosticConfigs &configs, const Utils::Id &configToSelect)
{ {
// Determine executable paths // Determine executable paths
QString clangTidyPath; FilePath clangTidyPath;
QString clazyStandalonePath; FilePath clazyStandalonePath;
if (auto settingsWidget = SettingsWidget::instance()) { if (auto settingsWidget = SettingsWidget::instance()) {
// Global settings case; executables might not yet applied to settings // Global settings case; executables might not yet applied to settings
clangTidyPath = settingsWidget->clangTidyPath(); clangTidyPath = settingsWidget->clangTidyPath();

View File

@@ -37,20 +37,22 @@
#include <utils/optional.h> #include <utils/optional.h>
using namespace Utils;
namespace ClangTools { namespace ClangTools {
namespace Internal { namespace Internal {
static SettingsWidget *m_instance = nullptr; static SettingsWidget *m_instance = nullptr;
static void setupPathChooser(Utils::PathChooser *const chooser, static void setupPathChooser(PathChooser *const chooser,
const QString &promptDiaglogTitle, const QString &promptDiaglogTitle,
const QString &placeHolderText, const QString &placeHolderText,
const QString &pathFromSettings, const FilePath &pathFromSettings,
const QString &historyCompleterId) const QString &historyCompleterId)
{ {
chooser->setPromptDialogTitle(promptDiaglogTitle); chooser->setPromptDialogTitle(promptDiaglogTitle);
chooser->setDefaultValue(placeHolderText); chooser->setDefaultValue(placeHolderText);
chooser->setPath(pathFromSettings); chooser->setFilePath(pathFromSettings);
chooser->setExpectedKind(Utils::PathChooser::ExistingCommand); chooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
chooser->setHistoryCompleter(historyCompleterId); chooser->setHistoryCompleter(historyCompleterId);
} }
@@ -71,8 +73,8 @@ SettingsWidget::SettingsWidget()
// Group box "Executables" // Group box "Executables"
// //
QString placeHolderText = shippedClangTidyExecutable(); QString placeHolderText = shippedClangTidyExecutable().toUserOutput();
QString path = m_settings->clangTidyExecutable(); FilePath path = m_settings->clangTidyExecutable();
if (path.isEmpty() && placeHolderText.isEmpty()) if (path.isEmpty() && placeHolderText.isEmpty())
path = Constants::CLANG_TIDY_EXECUTABLE_NAME; path = Constants::CLANG_TIDY_EXECUTABLE_NAME;
setupPathChooser(m_ui->clangTidyPathChooser, setupPathChooser(m_ui->clangTidyPathChooser,
@@ -81,7 +83,7 @@ SettingsWidget::SettingsWidget()
path, path,
"ClangTools.ClangTidyExecutable.History"); "ClangTools.ClangTidyExecutable.History");
placeHolderText = shippedClazyStandaloneExecutable(); placeHolderText = shippedClazyStandaloneExecutable().toUserOutput();
path = m_settings->clazyStandaloneExecutable(); path = m_settings->clazyStandaloneExecutable();
if (path.isEmpty() && placeHolderText.isEmpty()) if (path.isEmpty() && placeHolderText.isEmpty())
path = Constants::CLAZY_STANDALONE_EXECUTABLE_NAME; path = Constants::CLAZY_STANDALONE_EXECUTABLE_NAME;
@@ -101,8 +103,8 @@ SettingsWidget::SettingsWidget()
void SettingsWidget::apply() void SettingsWidget::apply()
{ {
// Executables // Executables
m_settings->setClangTidyExecutable(m_ui->clangTidyPathChooser->rawPath()); m_settings->setClangTidyExecutable(clangTidyPath());
m_settings->setClazyStandaloneExecutable(m_ui->clazyStandalonePathChooser->rawPath()); m_settings->setClazyStandaloneExecutable(clazyStandalonePath());
// Run options // Run options
m_settings->setRunSettings(m_ui->runSettingsWidget->toSettings()); m_settings->setRunSettings(m_ui->runSettingsWidget->toSettings());
@@ -120,14 +122,14 @@ SettingsWidget::~SettingsWidget()
m_instance = nullptr; m_instance = nullptr;
} }
QString SettingsWidget::clangTidyPath() const FilePath SettingsWidget::clangTidyPath() const
{ {
return m_ui->clangTidyPathChooser->rawPath(); return m_ui->clangTidyPathChooser->rawFilePath();
} }
QString SettingsWidget::clazyStandalonePath() const FilePath SettingsWidget::clazyStandalonePath() const
{ {
return m_ui->clazyStandalonePathChooser->rawPath(); return m_ui->clazyStandalonePathChooser->rawFilePath();
} }
// ClangToolsOptionsPage // ClangToolsOptionsPage

View File

@@ -31,6 +31,8 @@
#include <memory> #include <memory>
namespace Utils { class FilePath; }
namespace ClangTools { namespace ClangTools {
namespace Internal { namespace Internal {
@@ -46,8 +48,8 @@ public:
SettingsWidget(); SettingsWidget();
~SettingsWidget() override; ~SettingsWidget() override;
QString clangTidyPath() const; Utils::FilePath clangTidyPath() const;
QString clazyStandalonePath() const; Utils::FilePath clazyStandalonePath() const;
private: private:
void apply() final; void apply() final;

View File

@@ -522,31 +522,31 @@ static QString clangIncludePath(const QString &clangVersion)
/*! /*!
\internal \internal
*/ */
QString ICore::clangIncludeDirectory(const QString &clangVersion, FilePath ICore::clangIncludeDirectory(const QString &clangVersion,
const QString &clangFallbackIncludeDir) const FilePath &clangFallbackIncludeDir)
{ {
FilePath dir = libexecPath("clang" + clangIncludePath(clangVersion)); FilePath dir = libexecPath("clang" + clangIncludePath(clangVersion));
if (!dir.exists() || !dir.pathAppended("stdint.h").exists()) if (!dir.exists() || !dir.pathAppended("stdint.h").exists())
dir = FilePath::fromString(clangFallbackIncludeDir); dir = clangFallbackIncludeDir;
return dir.canonicalPath().toUserOutput(); return dir.canonicalPath();
} }
/*! /*!
\internal \internal
*/ */
static QString clangBinary(const QString &binaryBaseName, const QString &clangBinDirectory) static FilePath clangBinary(const QString &binaryBaseName, const FilePath &clangBinDirectory)
{ {
const QString hostExeSuffix(QTC_HOST_EXE_SUFFIX); FilePath executable =
FilePath executable = ICore::libexecPath("clang/bin") / binaryBaseName + hostExeSuffix; ICore::libexecPath("clang/bin").pathAppended(binaryBaseName).withExecutableSuffix();
if (!executable.exists()) if (!executable.exists())
executable = FilePath::fromString(clangBinDirectory) / binaryBaseName + hostExeSuffix; executable = clangBinDirectory.pathAppended(binaryBaseName).withExecutableSuffix();
return executable.canonicalPath().toUserOutput(); return executable.canonicalPath();
} }
/*! /*!
\internal \internal
*/ */
QString ICore::clangExecutable(const QString &clangBinDirectory) FilePath ICore::clangExecutable(const FilePath &clangBinDirectory)
{ {
return clangBinary("clang", clangBinDirectory); return clangBinary("clang", clangBinDirectory);
} }
@@ -554,7 +554,7 @@ QString ICore::clangExecutable(const QString &clangBinDirectory)
/*! /*!
\internal \internal
*/ */
QString ICore::clangdExecutable(const QString &clangBinDirectory) FilePath ICore::clangdExecutable(const FilePath &clangBinDirectory)
{ {
return clangBinary("clangd", clangBinDirectory); return clangBinary("clangd", clangBinDirectory);
} }
@@ -562,7 +562,7 @@ QString ICore::clangdExecutable(const QString &clangBinDirectory)
/*! /*!
\internal \internal
*/ */
QString ICore::clangTidyExecutable(const QString &clangBinDirectory) FilePath ICore::clangTidyExecutable(const FilePath &clangBinDirectory)
{ {
return clangBinary("clang-tidy", clangBinDirectory); return clangBinary("clang-tidy", clangBinDirectory);
} }
@@ -570,7 +570,7 @@ QString ICore::clangTidyExecutable(const QString &clangBinDirectory)
/*! /*!
\internal \internal
*/ */
QString ICore::clazyStandaloneExecutable(const QString &clangBinDirectory) FilePath ICore::clazyStandaloneExecutable(const FilePath &clangBinDirectory)
{ {
return clangBinary("clazy-standalone", clangBinDirectory); return clangBinary("clazy-standalone", clangBinDirectory);
} }

View File

@@ -164,12 +164,12 @@ public:
static void setupScreenShooter(const QString &name, QWidget *w, const QRect &rc = QRect()); static void setupScreenShooter(const QString &name, QWidget *w, const QRect &rc = QRect());
static QString pluginPath(); static QString pluginPath();
static QString userPluginPath(); static QString userPluginPath();
static QString clangExecutable(const QString &clangBinDirectory); static Utils::FilePath clangExecutable(const Utils::FilePath &clangBinDirectory);
static QString clangdExecutable(const QString &clangBinDirectory); static Utils::FilePath clangdExecutable(const Utils::FilePath &clangBinDirectory);
static QString clangTidyExecutable(const QString &clangBinDirectory); static Utils::FilePath clangTidyExecutable(const Utils::FilePath &clangBinDirectory);
static QString clazyStandaloneExecutable(const QString &clangBinDirectory); static Utils::FilePath clazyStandaloneExecutable(const Utils::FilePath &clangBinDirectory);
static QString clangIncludeDirectory(const QString &clangVersion, static Utils::FilePath clangIncludeDirectory(const QString &clangVersion,
const QString &clangFallbackIncludeDir); const Utils::FilePath &clangFallbackIncludeDir);
static QString buildCompatibilityString(); static QString buildCompatibilityString();
static QStatusBar *statusBar(); static QStatusBar *statusBar();

View File

@@ -45,6 +45,8 @@
#include <QRegularExpression> #include <QRegularExpression>
#include <QtGlobal> #include <QtGlobal>
using namespace Utils;
namespace CppTools { namespace CppTools {
static const char defineOption[] = "-D"; static const char defineOption[] = "-D";
@@ -104,7 +106,7 @@ CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
UseLanguageDefines useLanguageDefines, UseLanguageDefines useLanguageDefines,
UseBuildSystemWarnings useBuildSystemWarnings, UseBuildSystemWarnings useBuildSystemWarnings,
const QString &clangVersion, const QString &clangVersion,
const QString &clangIncludeDirectory) const FilePath &clangIncludeDirectory)
: m_projectPart(projectPart) : m_projectPart(projectPart)
, m_useSystemHeader(useSystemHeader) , m_useSystemHeader(useSystemHeader)
, m_useTweakedHeaderPaths(useTweakedHeaderPaths) , m_useTweakedHeaderPaths(useTweakedHeaderPaths)

View File

@@ -50,8 +50,8 @@ public:
UseTweakedHeaderPaths useTweakedHeaderPaths = UseTweakedHeaderPaths::No, UseTweakedHeaderPaths useTweakedHeaderPaths = UseTweakedHeaderPaths::No,
UseLanguageDefines useLanguageDefines = UseLanguageDefines::No, UseLanguageDefines useLanguageDefines = UseLanguageDefines::No,
UseBuildSystemWarnings useBuildSystemWarnings = UseBuildSystemWarnings::No, UseBuildSystemWarnings useBuildSystemWarnings = UseBuildSystemWarnings::No,
const QString &clangVersion = QString(), const QString &clangVersion = {},
const QString &clangIncludeDirectory = QString()); const Utils::FilePath &clangIncludeDirectory = {});
QStringList build(ProjectFile::Kind fileKind, UsePrecompiledHeaders usePrecompiledHeaders); QStringList build(ProjectFile::Kind fileKind, UsePrecompiledHeaders usePrecompiledHeaders);
QStringList options() const { return m_options; } QStringList options() const { return m_options; }
@@ -113,7 +113,7 @@ private:
const UseBuildSystemWarnings m_useBuildSystemWarnings; const UseBuildSystemWarnings m_useBuildSystemWarnings;
const QString m_clangVersion; const QString m_clangVersion;
const QString m_clangIncludeDirectory; const Utils::FilePath m_clangIncludeDirectory;
struct { struct {
QStringList flags; QStringList flags;

View File

@@ -36,11 +36,10 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
namespace CppTools { using namespace ProjectExplorer;
using namespace Utils;
using ProjectExplorer::HeaderPath; namespace CppTools {
using ProjectExplorer::HeaderPaths;
using ProjectExplorer::HeaderPathType;
void HeaderPathFilter::process() void HeaderPathFilter::process()
{ {
@@ -104,7 +103,7 @@ void HeaderPathFilter::filterHeaderPath(const ProjectExplorer::HeaderPath &heade
namespace { namespace {
QString clangIncludeDirectory(const QString &clangVersion, const QString &clangFallbackIncludeDir) FilePath clangIncludeDirectory(const QString &clangVersion, const FilePath &clangFallbackIncludeDir)
{ {
#ifndef UNIT_TESTS #ifndef UNIT_TESTS
return Core::ICore::clangIncludeDirectory(clangVersion, clangFallbackIncludeDir); return Core::ICore::clangIncludeDirectory(clangVersion, clangFallbackIncludeDir);
@@ -158,9 +157,9 @@ void HeaderPathFilter::tweakHeaderPaths()
auto split = resourceIterator(builtInHeaderPaths); auto split = resourceIterator(builtInHeaderPaths);
if (!clangVersion.isEmpty()) { if (!clangVersion.isEmpty()) {
const QString clangIncludePath const FilePath clangIncludePath
= clangIncludeDirectory(clangVersion, clangFallbackIncludeDirectory); = clangIncludeDirectory(clangVersion, clangFallbackIncludeDirectory);
builtInHeaderPaths.insert(split, HeaderPath{clangIncludePath, HeaderPathType::BuiltIn}); builtInHeaderPaths.insert(split, HeaderPath{clangIncludePath.toString(), HeaderPathType::BuiltIn});
} }
} }

View File

@@ -28,14 +28,17 @@
#include "compileroptionsbuilder.h" #include "compileroptionsbuilder.h"
#include "projectpart.h" #include "projectpart.h"
#include <utils/filepath.h>
namespace CppTools { namespace CppTools {
class CPPTOOLS_EXPORT HeaderPathFilter class CPPTOOLS_EXPORT HeaderPathFilter
{ {
public: public:
HeaderPathFilter(const ProjectPart &projectPart, HeaderPathFilter(const ProjectPart &projectPart,
UseTweakedHeaderPaths useTweakedHeaderPaths = UseTweakedHeaderPaths::Yes, UseTweakedHeaderPaths useTweakedHeaderPaths = UseTweakedHeaderPaths::Yes,
const QString &clangVersion = {}, const QString &clangVersion = {},
const QString &clangIncludeDirectory = {}, const Utils::FilePath &clangIncludeDirectory = {},
const QString &projectDirectory = {}, const QString &projectDirectory = {},
const QString &buildDirectory = {}) const QString &buildDirectory = {})
: projectPart{projectPart} : projectPart{projectPart}
@@ -67,7 +70,7 @@ public:
ProjectExplorer::HeaderPaths userHeaderPaths; ProjectExplorer::HeaderPaths userHeaderPaths;
const ProjectPart &projectPart; const ProjectPart &projectPart;
const QString clangVersion; const QString clangVersion;
const QString clangFallbackIncludeDirectory; const Utils::FilePath clangFallbackIncludeDirectory;
const QString projectDirectory; const QString projectDirectory;
const QString buildDirectory; const QString buildDirectory;
const UseTweakedHeaderPaths useTweakedHeaderPaths; const UseTweakedHeaderPaths useTweakedHeaderPaths;

View File

@@ -37,7 +37,7 @@
#include <cplusplus/Token.h> #include <cplusplus/Token.h>
#include <utils/cpplanguage_details.h> #include <utils/cpplanguage_details.h>
#include <utils/fileutils.h> #include <utils/filepath.h>
#include <utils/id.h> #include <utils/id.h>
#include <QString> #include <QString>

View File

@@ -1640,10 +1640,9 @@ QList<ToolChain *> ClangToolChainFactory::autoDetect(const QList<ToolChain *> &a
Constants::CLANG_TOOLCHAIN_TYPEID, alreadyKnown, device)); Constants::CLANG_TOOLCHAIN_TYPEID, alreadyKnown, device));
known.append(tcs); known.append(tcs);
const FilePath compilerPath = FilePath::fromString(Core::ICore::clangExecutable(CLANG_BINDIR)); const FilePath compilerPath = Core::ICore::clangExecutable(CLANG_BINDIR);
if (!compilerPath.isEmpty()) { if (!compilerPath.isEmpty()) {
const FilePath clang = compilerPath.parentDir().pathAppended( const FilePath clang = compilerPath.parentDir().pathAppended("clang").withExecutableSuffix();
HostOsInfo::withExecutableSuffix("clang"));
tcs.append(autoDetectToolchains(clang.toString(), DetectVariants::No, tcs.append(autoDetectToolchains(clang.toString(), DetectVariants::No,
Constants::C_LANGUAGE_ID, Constants::CLANG_TOOLCHAIN_TYPEID, Constants::C_LANGUAGE_ID, Constants::CLANG_TOOLCHAIN_TYPEID,
tcs, device)); tcs, device));

View File

@@ -1985,13 +1985,11 @@ QList<ToolChain *> ClangClToolChainFactory::autoDetect(const QList<ToolChain *>
QList<ToolChain *> results; QList<ToolChain *> results;
QList<ToolChain *> known = alreadyKnown; QList<ToolChain *> known = alreadyKnown;
QString qtCreatorsClang = Core::ICore::clangExecutable(CLANG_BINDIR); FilePath qtCreatorsClang = Core::ICore::clangExecutable(CLANG_BINDIR);
if (!qtCreatorsClang.isEmpty()) { if (!qtCreatorsClang.isEmpty()) {
qtCreatorsClang = Utils::FilePath::fromString(qtCreatorsClang) qtCreatorsClang = qtCreatorsClang.parentDir().pathAppended("clang-cl.exe");
.parentDir() results.append(detectClangClToolChainInPath(qtCreatorsClang.toString(),
.pathAppended("clang-cl.exe") alreadyKnown, "", true));
.toString();
results.append(detectClangClToolChainInPath(qtCreatorsClang, alreadyKnown, "", true));
known.append(results); known.append(results);
} }