Changeset View
Changeset View
Standalone View
Standalone View
plugins/clazy/jobparameters.cpp
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | |||||
136 | { | 136 | { | ||
137 | } | 137 | } | ||
138 | 138 | | |||
139 | JobParameters::JobParameters(KDevelop::IProject* project, const QString& checkPath) | 139 | JobParameters::JobParameters(KDevelop::IProject* project, const QString& checkPath) | ||
140 | : m_checkPath(checkPath) | 140 | : m_checkPath(checkPath) | ||
141 | { | 141 | { | ||
142 | Q_ASSERT(project); | 142 | Q_ASSERT(project); | ||
143 | 143 | | |||
144 | auto projectRootPath = project->path().toLocalFile(); | 144 | auto projectRootPath = QFileInfo(project->path().toLocalFile()).canonicalFilePath(); | ||
145 | 145 | | |||
146 | auto buildPath = project->buildSystemManager()->buildDirectory(project->projectItem()); | 146 | auto buildPath = project->buildSystemManager()->buildDirectory(project->projectItem()); | ||
147 | m_projectBuildPath = buildPath.toLocalFile(); | 147 | m_projectBuildPath = buildPath.toLocalFile(); | ||
148 | 148 | | |||
149 | buildPath.addPath(QStringLiteral("compile_commands.json")); | 149 | buildPath.addPath(QStringLiteral("compile_commands.json")); | ||
150 | 150 | | |||
151 | auto commandsFilePath = buildPath.toLocalFile(); | 151 | auto commandsFilePath = buildPath.toLocalFile(); | ||
152 | if (!QFile::exists(commandsFilePath)) { | 152 | if (!QFile::exists(commandsFilePath)) { | ||
153 | m_error = i18n("Compile commands file '%1' does not exist.", commandsFilePath); | 153 | m_error = i18n("Compile commands file '%1' does not exist.", commandsFilePath); | ||
154 | return; | 154 | return; | ||
155 | } | 155 | } | ||
156 | 156 | | |||
157 | const auto pathInfo = QFileInfo(m_checkPath); | ||||
158 | const bool checkPathIsFile = pathInfo.isFile(); | ||||
159 | const auto pathToCheck = checkPathIsFile && pathInfo.exists() ? pathInfo.canonicalFilePath() : m_checkPath; | ||||
kossebau: Why the `QStringLiteral("")` and not just a plain `QString()`? | |||||
160 | | ||||
157 | if (!m_checkPath.isEmpty()) { | 161 | if (!m_checkPath.isEmpty()) { | ||
158 | const auto allFiles = compileCommandsFiles(commandsFilePath, m_error); | 162 | const auto allFiles = compileCommandsFiles(commandsFilePath, m_error); | ||
159 | if (!m_error.isEmpty()) { | 163 | if (!m_error.isEmpty()) { | ||
160 | return; | 164 | return; | ||
161 | } | 165 | } | ||
162 | 166 | | |||
163 | if (m_checkPath == projectRootPath) { | 167 | if (pathToCheck == projectRootPath) { | ||
you can remove the previous check, since the second necessarily has to include it mwolff: you can remove the previous check, since the second necessarily has to include it | |||||
rjvbb: I assume you meant the first component of the `||` expression? | |||||
164 | m_sources = allFiles; | 168 | m_sources = allFiles; | ||
165 | } else { | 169 | } else { | ||
166 | const bool checkPathIsFile = QFileInfo(m_checkPath).isFile(); | | |||
167 | for (auto& file : allFiles) { | 170 | for (auto& file : allFiles) { | ||
168 | if (checkPathIsFile) { | 171 | if (checkPathIsFile) { | ||
169 | if (file == m_checkPath) { | 172 | if (file == pathToCheck) { | ||
170 | m_sources.clear(); | 173 | m_sources.clear(); | ||
171 | m_sources += m_checkPath; | 174 | m_sources += pathToCheck; | ||
we don't do this anywhere else - I'd suggest you always operate on canonical paths note that you may want to pretty print paths before showing them to the user anyways. there's a function somewhere (Project?) that takes a path and turns it into a relative-to-project-root string ready for consumption by the user mwolff: we don't do this anywhere else - I'd suggest you always operate on canonical paths
note that… | |||||
Yes, that would be something like Core::self()->projectController()->prettyFileName(urlDoc->url(), KDevelop::IProjectController::FormatPlain); (took me way longer than reasonable to remember where I might find it being used ...) It seems though that this is already being done (ProblemModel::reset()), did I miss a place where that is not yet so? rjvbb: Yes, that would be something like
```
Core::self()->projectController()->prettyFileName(urlDoc… | |||||
172 | break; | 175 | break; | ||
173 | } | 176 | } | ||
174 | } else if (file.startsWith(m_checkPath)) { | 177 | } else if (file.startsWith(pathToCheck)) { | ||
175 | m_sources += file; | 178 | m_sources += file; | ||
176 | } | 179 | } | ||
177 | } | 180 | } | ||
178 | } | 181 | } | ||
179 | } | 182 | } | ||
180 | 183 | | |||
181 | ProjectSettings projectSettings; | 184 | ProjectSettings projectSettings; | ||
182 | projectSettings.setSharedConfig(project->projectConfiguration()); | 185 | projectSettings.setSharedConfig(project->projectConfiguration()); | ||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |
Why the QStringLiteral("") and not just a plain QString()?