forked from qt-creator/qt-creator
ClangTools: use VFSoverlay if the clang tool supports it
check the help output of a clang tool whether virtual file system overlay is supported. Prepares for the vfso support of clazy-standalone. Change-Id: I157c94de1dda41c83945c9bc8a4c2e132b2e6551 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -72,21 +72,6 @@ static QStringList clazyChecksArguments(const ClangDiagnosticConfig diagnosticCo
|
||||
return {};
|
||||
}
|
||||
|
||||
static QStringList mainToolArguments(const QString &mainFilePath, const QString &outputFilePath)
|
||||
{
|
||||
return {
|
||||
"-export-fixes=" + outputFilePath,
|
||||
QDir::toNativeSeparators(mainFilePath),
|
||||
};
|
||||
}
|
||||
|
||||
static QString virtualFileSystemOverlay(const QString &overlayFilePath)
|
||||
{
|
||||
if (overlayFilePath.isEmpty())
|
||||
return {};
|
||||
return "--vfsoverlay=" + overlayFilePath;
|
||||
}
|
||||
|
||||
static QStringList clangArguments(const ClangDiagnosticConfig &diagnosticConfig,
|
||||
const QStringList &baseOptions)
|
||||
{
|
||||
@@ -110,8 +95,7 @@ ClangTidyRunner::ClangTidyRunner(const ClangDiagnosticConfig &config, QObject *p
|
||||
setExecutable(clangTidyExecutable());
|
||||
setArgsCreator([this, config](const QStringList &baseOptions) {
|
||||
return QStringList() << tidyChecksArguments(config)
|
||||
<< mainToolArguments(fileToAnalyze(), outputFilePath())
|
||||
<< virtualFileSystemOverlay(m_overlayFilePath)
|
||||
<< mainToolArguments()
|
||||
<< "--"
|
||||
<< clangArguments(config, baseOptions);
|
||||
});
|
||||
@@ -124,11 +108,10 @@ ClazyStandaloneRunner::ClazyStandaloneRunner(const ClangDiagnosticConfig &config
|
||||
setOutputFileFormat(OutputFileFormat::Yaml);
|
||||
setExecutable(clazyStandaloneExecutable());
|
||||
setArgsCreator([this, config](const QStringList &baseOptions) {
|
||||
return QStringList()
|
||||
<< clazyChecksArguments(config)
|
||||
<< mainToolArguments(fileToAnalyze(), outputFilePath())
|
||||
<< "--"
|
||||
<< clangArguments(config, baseOptions);
|
||||
return QStringList() << clazyChecksArguments(config)
|
||||
<< mainToolArguments()
|
||||
<< "--"
|
||||
<< clangArguments(config, baseOptions);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -73,6 +73,29 @@ void ClangToolRunner::init(const QString &outputDirPath,
|
||||
connect(&m_process, &QProcess::readyRead, this, &ClangToolRunner::onProcessOutput);
|
||||
}
|
||||
|
||||
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);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ClangToolRunner::supportsVFSOverlay() const
|
||||
{
|
||||
static QMap<QString, bool> vfsCapabilities;
|
||||
auto it = vfsCapabilities.find(m_executable);
|
||||
if (it == vfsCapabilities.end()) {
|
||||
Utils::SynchronousProcess p;
|
||||
Utils::SynchronousProcessResponse response = p.runBlocking(
|
||||
Utils::CommandLine(m_executable, {"--help"}));
|
||||
it = vfsCapabilities.insert(m_executable, response.allOutput().contains("vfsoverlay"));
|
||||
}
|
||||
return it.value();
|
||||
}
|
||||
|
||||
ClangToolRunner::~ClangToolRunner()
|
||||
{
|
||||
if (m_process.state() != QProcess::NotRunning) {
|
||||
|
@@ -59,6 +59,8 @@ public:
|
||||
OutputFileFormat outputFileFormat() const { return m_outputFileFormat; }
|
||||
QString fileToAnalyze() const { return m_fileToAnalyze; }
|
||||
QString outputFilePath() const { return m_outputFilePath; }
|
||||
QStringList mainToolArguments() const;
|
||||
bool supportsVFSOverlay() const;
|
||||
|
||||
// compilerOptions is expected to contain everything except:
|
||||
// (1) file to analyze
|
||||
|
@@ -186,7 +186,7 @@ void DocumentClangToolRunner::run()
|
||||
return createRunner<ClangTidyRunner>(config, env);
|
||||
};
|
||||
}
|
||||
if (config.isClazyEnabled() && !m_document->isModified()) {
|
||||
if (config.isClazyEnabled()) {
|
||||
m_runnerCreators << [this, env, config]() {
|
||||
return createRunner<ClazyStandaloneRunner>(config, env);
|
||||
};
|
||||
@@ -218,7 +218,8 @@ void DocumentClangToolRunner::runNext()
|
||||
auto [clangIncludeDir, clangVersion] = getClangIncludeDirAndVersion(m_currentRunner.get());
|
||||
qCDebug(LOG) << Q_FUNC_INFO << m_currentRunner->executable() << clangIncludeDir
|
||||
<< clangVersion << m_fileInfo.file;
|
||||
if (clangIncludeDir.isEmpty() || clangVersion.isEmpty()) {
|
||||
if (clangIncludeDir.isEmpty() || clangVersion.isEmpty()
|
||||
|| (m_document->isModified() && !m_currentRunner->supportsVFSOverlay())) {
|
||||
runNext();
|
||||
} else {
|
||||
AnalyzeUnit unit(m_fileInfo, clangIncludeDir, clangVersion);
|
||||
|
Reference in New Issue
Block a user