Commit a7c053a3 authored by René J.V. Bertin's avatar René J.V. Bertin

kdev-clazy: use canonical paths

Ensure that clazy can always access files list in compile_commands.json
regardless of the presence of symlinks in theirs paths and/or in the
current process working directory.

Differential Revision: https://phabricator.kde.org/D15797
parent f7571e8b
Pipeline #662 canceled with stage
in 35 seconds
......@@ -147,6 +147,7 @@ JobParameters::JobParameters(KDevelop::IProject* project, const QString& checkPa
Q_ASSERT(project);
auto projectRootPath = project->path().toLocalFile();
auto projectCanonicalRootPath = QFileInfo(projectRootPath).canonicalFilePath();
auto buildPath = project->buildSystemManager()->buildDirectory(project->projectItem());
m_projectBuildPath = buildPath.toLocalFile();
......@@ -158,6 +159,10 @@ JobParameters::JobParameters(KDevelop::IProject* project, const QString& checkPa
m_error = i18n("Compile commands file '%1' does not exist.", commandsFilePath);
return;
}
const auto pathInfo = QFileInfo(m_checkPath);
const bool checkPathIsFile = pathInfo.isFile();
const auto canonicalPathToCheck = checkPathIsFile ? pathInfo.canonicalFilePath() : QStringLiteral("");
if (!m_checkPath.isEmpty()) {
const auto allFiles = compileCommandsFiles(commandsFilePath, m_error);
......@@ -165,18 +170,17 @@ JobParameters::JobParameters(KDevelop::IProject* project, const QString& checkPa
return;
}
if (m_checkPath == projectRootPath) {
if (canonicalPathToCheck == projectCanonicalRootPath) {
m_sources = allFiles;
} else {
const bool checkPathIsFile = QFileInfo(m_checkPath).isFile();
for (auto& file : allFiles) {
if (checkPathIsFile) {
if (file == m_checkPath) {
if (file == canonicalPathToCheck) {
m_sources.clear();
m_sources += m_checkPath;
m_sources += canonicalPathToCheck;
break;
}
} else if (file.startsWith(m_checkPath)) {
} else if (file.startsWith(m_checkPath) || file.startsWith(canonicalPathToCheck)) {
m_sources += file;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment