forked from qt-creator/qt-creator
ClangToolsUtils: Add isVFSOverlaySupported()
Remove ClangToolRunner::supportsVFSOverlay(). Move check for modified document and vfsOverlay into runner creator method, as it's called in the same cycle just before the runner is about to be started. Change-Id: I7a5df71bfa73c350862e4c7f9eae49773b6206b7 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -103,25 +103,12 @@ QStringList ClangToolRunner::mainToolArguments() const
|
||||
{
|
||||
QStringList result;
|
||||
result << "-export-fixes=" + m_outputFilePath;
|
||||
if (!m_input.overlayFilePath.isEmpty() && supportsVFSOverlay())
|
||||
if (!m_input.overlayFilePath.isEmpty() && isVFSOverlaySupported(m_executable))
|
||||
result << "--vfsoverlay=" + m_input.overlayFilePath;
|
||||
result << QDir::toNativeSeparators(m_input.unit.file);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ClangToolRunner::supportsVFSOverlay() const
|
||||
{
|
||||
static QMap<FilePath, bool> vfsCapabilities;
|
||||
auto it = vfsCapabilities.find(m_executable);
|
||||
if (it == vfsCapabilities.end()) {
|
||||
QtcProcess p;
|
||||
p.setCommand({m_executable, {"--help"}});
|
||||
p.runBlocking();
|
||||
it = vfsCapabilities.insert(m_executable, p.allOutput().contains("vfsoverlay"));
|
||||
}
|
||||
return it.value();
|
||||
}
|
||||
|
||||
static QString createOutputFilePath(const FilePath &dirPath, const QString &fileToAnalyze)
|
||||
{
|
||||
const QString fileName = QFileInfo(fileToAnalyze).fileName();
|
||||
|
@@ -54,7 +54,6 @@ public:
|
||||
|
||||
QString name() const { return m_name; }
|
||||
QString fileToAnalyze() const { return m_input.unit.file; }
|
||||
bool supportsVFSOverlay() const;
|
||||
|
||||
// compilerOptions is expected to contain everything except:
|
||||
// (1) file to analyze
|
||||
|
@@ -200,6 +200,19 @@ FilePath toolFallbackExecutable(ClangToolType tool)
|
||||
return findValidExecutable({toolShippedExecutable(tool), fallback});
|
||||
}
|
||||
|
||||
bool isVFSOverlaySupported(const FilePath &executable)
|
||||
{
|
||||
static QMap<FilePath, bool> vfsCapabilities;
|
||||
auto it = vfsCapabilities.find(executable);
|
||||
if (it == vfsCapabilities.end()) {
|
||||
QtcProcess p;
|
||||
p.setCommand({executable, {"--help"}});
|
||||
p.runBlocking();
|
||||
it = vfsCapabilities.insert(executable, p.allOutput().contains("vfsoverlay"));
|
||||
}
|
||||
return it.value();
|
||||
}
|
||||
|
||||
static void addBuiltinConfigs(ClangDiagnosticConfigsModel &model)
|
||||
{
|
||||
model.appendOrUpdate(builtinConfig());
|
||||
|
@@ -47,6 +47,8 @@ Utils::FilePath toolShippedExecutable(CppEditor::ClangToolType tool);
|
||||
Utils::FilePath toolExecutable(CppEditor::ClangToolType tool);
|
||||
Utils::FilePath toolFallbackExecutable(CppEditor::ClangToolType tool);
|
||||
|
||||
bool isVFSOverlaySupported(const Utils::FilePath &executable);
|
||||
|
||||
Utils::FilePath fullPath(const Utils::FilePath &executable);
|
||||
|
||||
QString documentationUrl(const QString &checkName);
|
||||
|
@@ -206,8 +206,14 @@ void DocumentClangToolRunner::run()
|
||||
if (!executable.isExecutableFile() || includeDir.isEmpty() || clangVersion.isEmpty())
|
||||
return;
|
||||
const AnalyzeUnit unit(m_fileInfo, includeDir, clangVersion);
|
||||
m_runnerCreators << [this, tool, unit, config, env] {
|
||||
return createRunner(tool, unit, config, env);
|
||||
m_runnerCreators << [=]() -> ClangToolRunner * {
|
||||
if (m_document->isModified() && !isVFSOverlaySupported(executable))
|
||||
return nullptr;
|
||||
auto runner = new ClangToolRunner({tool, config, m_temporaryDir.path(),
|
||||
env, unit, vfso().overlayFilePath().toString()}, this);
|
||||
connect(runner, &ClangToolRunner::done,
|
||||
this, &DocumentClangToolRunner::onDone);
|
||||
return runner;
|
||||
};
|
||||
};
|
||||
addClangTool(ClangToolType::Tidy);
|
||||
@@ -226,15 +232,14 @@ void DocumentClangToolRunner::runNext()
|
||||
{
|
||||
if (m_currentRunner)
|
||||
m_currentRunner.release()->deleteLater();
|
||||
m_currentRunner.reset(m_runnerCreators.isEmpty() ? nullptr : m_runnerCreators.takeFirst()());
|
||||
if (m_currentRunner) {
|
||||
if (m_document->isModified() && !m_currentRunner->supportsVFSOverlay())
|
||||
runNext();
|
||||
else if (!m_currentRunner->run())
|
||||
runNext();
|
||||
} else {
|
||||
|
||||
if (m_runnerCreators.isEmpty()) {
|
||||
finalize();
|
||||
return;
|
||||
}
|
||||
m_currentRunner.reset(m_runnerCreators.takeFirst()());
|
||||
if (!m_currentRunner || !m_currentRunner->run())
|
||||
runNext();
|
||||
}
|
||||
|
||||
static void updateLocation(Debugger::DiagnosticLocation &location)
|
||||
@@ -344,15 +349,5 @@ bool DocumentClangToolRunner::isSuppressed(const Diagnostic &diagnostic) const
|
||||
return Utils::anyOf(m_suppressed, equalsSuppressed);
|
||||
}
|
||||
|
||||
ClangToolRunner *DocumentClangToolRunner::createRunner(ClangToolType tool, const AnalyzeUnit &unit,
|
||||
const ClangDiagnosticConfig &config,
|
||||
const Environment &env)
|
||||
{
|
||||
auto runner = new ClangToolRunner({tool, config, m_temporaryDir.path(), env, unit,
|
||||
vfso().overlayFilePath().toString()}, this);
|
||||
connect(runner, &ClangToolRunner::done, this, &DocumentClangToolRunner::onDone);
|
||||
return runner;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangTools
|
||||
|
@@ -7,22 +7,19 @@
|
||||
#include "clangtoolsdiagnostic.h"
|
||||
#include "clangtoolsprojectsettings.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Core { class IDocument; }
|
||||
namespace CppEditor { class ClangDiagnosticConfig; }
|
||||
namespace TextEditor { class TextEditorWidget; }
|
||||
|
||||
namespace ClangTools {
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class AnalyzeOutputData;
|
||||
class AnalyzeUnit;
|
||||
class ClangToolRunner;
|
||||
class DiagnosticMark;
|
||||
|
||||
@@ -49,10 +46,6 @@ private:
|
||||
|
||||
bool isSuppressed(const Diagnostic &diagnostic) const;
|
||||
|
||||
ClangToolRunner *createRunner(CppEditor::ClangToolType tool, const AnalyzeUnit &unit,
|
||||
const CppEditor::ClangDiagnosticConfig &config,
|
||||
const Utils::Environment &env);
|
||||
|
||||
QTimer m_runTimer;
|
||||
Core::IDocument *m_document = nullptr;
|
||||
Utils::TemporaryDirectory m_temporaryDir;
|
||||
|
Reference in New Issue
Block a user