diff options
author | Jarek Kobus <[email protected]> | 2023-01-11 15:32:46 +0100 |
---|---|---|
committer | Jarek Kobus <[email protected]> | 2023-01-12 09:24:43 +0000 |
commit | 5dec97ea4121a8253f6d89d99e5165eb333e50a0 (patch) | |
tree | f52eaab824513ce15f88ac9cc94b480c84d3fe95 /src/plugins/clangtools/clangtoolrunner.cpp | |
parent | c181631de9b06654148c915479592cf2522f4a10 (diff) |
ClangToolRunner: Add done(const AnalyzeOutputData &) signal
Introduce AnalyzerOutputData structure that is passed inside
new done() signal. This signal replaces the finishedWithSuccess()
and finishedWithFailure() signals. The output structure contains
all the data required in clients' handlers.
Move AnalyzeUnit into clangtoolrunner.h in order to avoid
circular dependencies.
Get rid of outputFilePath(), as it's passed inside AnalyzeOutputData
now.
Inline ClangToolRunWorker::unitsToAnalyze() as it's used only once.
Change-Id: Icf9a52853c68e83f6ddfc4858dbcb830b96e1844
Reviewed-by: <[email protected]>
Reviewed-by: David Schulz <[email protected]>
Diffstat (limited to 'src/plugins/clangtools/clangtoolrunner.cpp')
-rw-r--r-- | src/plugins/clangtools/clangtoolrunner.cpp | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/src/plugins/clangtools/clangtoolrunner.cpp b/src/plugins/clangtools/clangtoolrunner.cpp index dd0cfd41897..59f8d4c322b 100644 --- a/src/plugins/clangtools/clangtoolrunner.cpp +++ b/src/plugins/clangtools/clangtoolrunner.cpp @@ -5,8 +5,11 @@ #include "clangtoolsutils.h" +#include <coreplugin/icore.h> + #include <cppeditor/clangdiagnosticconfigsmodel.h> #include <cppeditor/compileroptionsbuilder.h> +#include <cppeditor/cpptoolsreuse.h> #include <utils/environment.h> #include <utils/qtcassert.h> @@ -26,6 +29,24 @@ using namespace Utils; namespace ClangTools { namespace Internal { +AnalyzeUnit::AnalyzeUnit(const FileInfo &fileInfo, + const FilePath &clangIncludeDir, + const QString &clangVersion) +{ + const FilePath actualClangIncludeDir = Core::ICore::clangIncludeDirectory( + clangVersion, clangIncludeDir); + CompilerOptionsBuilder optionsBuilder(*fileInfo.projectPart, + UseSystemHeader::No, + UseTweakedHeaderPaths::Tools, + UseLanguageDefines::No, + UseBuildSystemWarnings::No, + actualClangIncludeDir); + file = fileInfo.file.toString(); + arguments = extraClangToolsPrependOptions(); + arguments.append(optionsBuilder.build(fileInfo.kind, CppEditor::getPchUsage())); + arguments.append(extraClangToolsAppendOptions()); +} + static bool isClMode(const QStringList &options) { return options.contains("--driver-mode=cl"); @@ -64,21 +85,6 @@ static QStringList clangArguments(const ClangDiagnosticConfig &diagnosticConfig, return arguments; } -static QString generalProcessError(const QString &name) -{ - return ClangToolRunner::tr("An error occurred with the %1 process.").arg(name); -} - -static QString finishedDueToCrash(const QString &name) -{ - return ClangToolRunner::tr("%1 crashed.").arg(name); -} - -static QString finishedWithBadExitCode(const QString &name, int exitCode) -{ - return ClangToolRunner::tr("%1 finished with exit code: %2.").arg(name).arg(exitCode); -} - ClangToolRunner::ClangToolRunner(const AnalyzeInputData &input, QObject *parent) : QObject(parent) , m_input(input) @@ -156,27 +162,27 @@ bool ClangToolRunner::run() void ClangToolRunner::onProcessDone() { - if (m_process.result() == ProcessResult::StartFailed) { - emit finishedWithFailure(generalProcessError(m_name), commandlineAndOutput()); - } else if (m_process.result() == ProcessResult::FinishedWithSuccess) { + if (m_process.result() == ProcessResult::FinishedWithSuccess) { qCDebug(LOG).noquote() << "Output:\n" << m_process.cleanedStdOut(); - emit finishedWithSuccess(m_input.unit.file); - } else if (m_process.result() == ProcessResult::FinishedWithError) { - emit finishedWithFailure(finishedWithBadExitCode(m_name, m_process.exitCode()), - commandlineAndOutput()); - } else { // == QProcess::CrashExit - emit finishedWithFailure(finishedDueToCrash(m_name), commandlineAndOutput()); + emit done({true, m_input.unit.file, m_outputFilePath, m_name}); + return; } -} -QString ClangToolRunner::commandlineAndOutput() const -{ - return tr("Command line: %1\n" - "Process Error: %2\n" - "Output:\n%3") - .arg(m_process.commandLine().toUserOutput()) - .arg(m_process.error()) - .arg(m_process.cleanedStdOut()); + const QString details = tr("Command line: %1\n" + "Process Error: %2\n" + "Output:\n%3") + .arg(m_process.commandLine().toUserOutput()) + .arg(m_process.error()) + .arg(m_process.cleanedStdOut()); + QString message; + if (m_process.result() == ProcessResult::StartFailed) + message = tr("An error occurred with the %1 process.").arg(m_name); + else if (m_process.result() == ProcessResult::FinishedWithError) + message = tr("%1 finished with exit code: %2.").arg(m_name).arg(m_process.exitCode()); + else + message = tr("%1 crashed.").arg(m_name); + + emit done({false, m_input.unit.file, m_outputFilePath, m_name, message, details}); } } // namespace Internal |