ClangTools: Use FilePath in AnalyzeUnit

Change-Id: Ic8e19053a60e7c4d801f32f9048b7c48d00b2a3d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2023-02-07 18:22:32 +01:00
parent 15841807d5
commit 9ad60cd891
4 changed files with 16 additions and 14 deletions

View File

@@ -189,7 +189,7 @@ void ClangToolRunWorker::start()
const AnalyzeInputData input{tool, m_diagnosticConfig, m_temporaryDir.path(), const AnalyzeInputData input{tool, m_diagnosticConfig, m_temporaryDir.path(),
m_environment, unit}; m_environment, unit};
const auto setupHandler = [this, unit, tool] { const auto setupHandler = [this, unit, tool] {
const QString filePath = FilePath::fromString(unit.file).toUserOutput(); const QString filePath = unit.file.toUserOutput();
appendMessage(Tr::tr("Analyzing \"%1\" [%2].").arg(filePath, clangToolName(tool)), appendMessage(Tr::tr("Analyzing \"%1\" [%2].").arg(filePath, clangToolName(tool)),
Utils::StdOutFormat); Utils::StdOutFormat);
return true; return true;
@@ -231,7 +231,7 @@ void ClangToolRunWorker::onDone(const AnalyzeOutputData &output)
m_filesNotAnalyzed.insert(output.fileToAnalyze); m_filesNotAnalyzed.insert(output.fileToAnalyze);
const QString message = Tr::tr("Failed to analyze \"%1\": %2") const QString message = Tr::tr("Failed to analyze \"%1\": %2")
.arg(output.fileToAnalyze, output.errorMessage); .arg(output.fileToAnalyze.toUserOutput(), output.errorMessage);
appendMessage(message, Utils::StdErrFormat); appendMessage(message, Utils::StdErrFormat);
appendMessage(output.errorDetails, Utils::StdErrFormat); appendMessage(output.errorDetails, Utils::StdErrFormat);
return; return;
@@ -247,7 +247,8 @@ void ClangToolRunWorker::onDone(const AnalyzeOutputData &output)
m_filesAnalyzed.remove(output.fileToAnalyze); m_filesAnalyzed.remove(output.fileToAnalyze);
m_filesNotAnalyzed.insert(output.fileToAnalyze); m_filesNotAnalyzed.insert(output.fileToAnalyze);
qCDebug(LOG) << "onRunnerFinishedWithSuccess: Error reading log file:" << errorMessage; qCDebug(LOG) << "onRunnerFinishedWithSuccess: Error reading log file:" << errorMessage;
appendMessage(Tr::tr("Failed to analyze \"%1\": %2").arg(output.fileToAnalyze, errorMessage), appendMessage(Tr::tr("Failed to analyze \"%1\": %2")
.arg(output.fileToAnalyze.toUserOutput(), errorMessage),
Utils::StdErrFormat); Utils::StdErrFormat);
} else { } else {
if (!m_filesNotAnalyzed.contains(output.fileToAnalyze)) if (!m_filesNotAnalyzed.contains(output.fileToAnalyze))

View File

@@ -69,8 +69,8 @@ private:
std::unique_ptr<Utils::TaskTree> m_taskTree; std::unique_ptr<Utils::TaskTree> m_taskTree;
QSet<Utils::FilePath> m_projectFiles; QSet<Utils::FilePath> m_projectFiles;
QSet<QString> m_filesAnalyzed; QSet<Utils::FilePath> m_filesAnalyzed;
QSet<QString> m_filesNotAnalyzed; QSet<Utils::FilePath> m_filesNotAnalyzed;
QElapsedTimer m_elapsed; QElapsedTimer m_elapsed;
}; };

View File

@@ -41,7 +41,7 @@ AnalyzeUnit::AnalyzeUnit(const FileInfo &fileInfo,
UseLanguageDefines::No, UseLanguageDefines::No,
UseBuildSystemWarnings::No, UseBuildSystemWarnings::No,
actualClangIncludeDir); actualClangIncludeDir);
file = fileInfo.file.toString(); file = fileInfo.file;
arguments = extraClangToolsPrependOptions(); arguments = extraClangToolsPrependOptions();
arguments.append(optionsBuilder.build(fileInfo.kind, CppEditor::getPchUsage())); arguments.append(optionsBuilder.build(fileInfo.kind, CppEditor::getPchUsage()));
arguments.append(extraClangToolsAppendOptions()); arguments.append(extraClangToolsAppendOptions());
@@ -85,9 +85,9 @@ static QStringList clangArguments(const ClangDiagnosticConfig &diagnosticConfig,
return arguments; return arguments;
} }
static QString createOutputFilePath(const FilePath &dirPath, const QString &fileToAnalyze) static QString createOutputFilePath(const FilePath &dirPath, const FilePath &fileToAnalyze)
{ {
const QString fileName = QFileInfo(fileToAnalyze).fileName(); const QString fileName = fileToAnalyze.fileName();
const FilePath fileTemplate = dirPath.pathAppended("report-" + fileName + "-XXXXXX"); const FilePath fileTemplate = dirPath.pathAppended("report-" + fileName + "-XXXXXX");
TemporaryFile temporaryFile("clangtools"); TemporaryFile temporaryFile("clangtools");
@@ -117,7 +117,7 @@ TaskItem clangToolTask(const AnalyzeInputData &input,
result << "-export-fixes=" + data->outputFilePath; result << "-export-fixes=" + data->outputFilePath;
if (!input.overlayFilePath.isEmpty() && isVFSOverlaySupported(data->executable)) if (!input.overlayFilePath.isEmpty() && isVFSOverlaySupported(data->executable))
result << "--vfsoverlay=" + input.overlayFilePath; result << "--vfsoverlay=" + input.overlayFilePath;
result << QDir::toNativeSeparators(input.unit.file); result << input.unit.file.nativePath();
return result; return result;
}; };
@@ -134,8 +134,8 @@ TaskItem clangToolTask(const AnalyzeInputData &input,
} }
QTC_CHECK(!input.unit.arguments.contains(QLatin1String("-o"))); QTC_CHECK(!input.unit.arguments.contains(QLatin1String("-o")));
QTC_CHECK(!input.unit.arguments.contains(input.unit.file)); QTC_CHECK(!input.unit.arguments.contains(input.unit.file.nativePath()));
QTC_ASSERT(FilePath::fromString(input.unit.file).exists(), return TaskAction::StopWithError); QTC_ASSERT(input.unit.file.exists(), return TaskAction::StopWithError);
data->outputFilePath = createOutputFilePath(input.outputDirPath, input.unit.file); data->outputFilePath = createOutputFilePath(input.outputDirPath, input.unit.file);
QTC_ASSERT(!data->outputFilePath.isEmpty(), return TaskAction::StopWithError); QTC_ASSERT(!data->outputFilePath.isEmpty(), return TaskAction::StopWithError);

View File

@@ -14,12 +14,13 @@ namespace Utils::Tasking { class TaskItem; }
namespace ClangTools { namespace ClangTools {
namespace Internal { namespace Internal {
struct AnalyzeUnit { struct AnalyzeUnit
{
AnalyzeUnit(const FileInfo &fileInfo, AnalyzeUnit(const FileInfo &fileInfo,
const Utils::FilePath &clangResourceDir, const Utils::FilePath &clangResourceDir,
const QString &clangVersion); const QString &clangVersion);
QString file; Utils::FilePath file;
QStringList arguments; // without file itself and "-o somePath" QStringList arguments; // without file itself and "-o somePath"
}; };
using AnalyzeUnits = QList<AnalyzeUnit>; using AnalyzeUnits = QList<AnalyzeUnit>;
@@ -37,7 +38,7 @@ struct AnalyzeInputData
struct AnalyzeOutputData struct AnalyzeOutputData
{ {
bool success = true; bool success = true;
QString fileToAnalyze; Utils::FilePath fileToAnalyze;
QString outputFilePath; QString outputFilePath;
CppEditor::ClangToolType toolType; CppEditor::ClangToolType toolType;
QString errorMessage = {}; QString errorMessage = {};