diff options
| author | Eike Ziller <eike.ziller@qt.io> | 2022-07-04 08:29:53 +0200 |
|---|---|---|
| committer | Eike Ziller <eike.ziller@qt.io> | 2022-07-04 08:53:22 +0200 |
| commit | 91fb0cf1232850f8cb41840d28689bf6bcfd633c (patch) | |
| tree | 337a883dda347f3f0890989c0adefd062a43e851 /src/plugins/cppeditor/cppcodemodelsettings.cpp | |
| parent | 1ce044ef7a0c69fbd7841dccd6f4bb7802d1dae4 (diff) | |
| parent | 4180e1b84f43cc39119e003457f76be518588107 (diff) | |
| download | qt-creator-91fb0cf1232850f8cb41840d28689bf6bcfd633c.tar.gz | |
Merge remote-tracking branch 'origin/8.0'
Conflicts:
src/plugins/qmldesigner/qmldesignerprojectmanager.cpp
Change-Id: I5106bb632c2a3a144287097137be45b0894b9ee4
Diffstat (limited to 'src/plugins/cppeditor/cppcodemodelsettings.cpp')
| -rw-r--r-- | src/plugins/cppeditor/cppcodemodelsettings.cpp | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/src/plugins/cppeditor/cppcodemodelsettings.cpp b/src/plugins/cppeditor/cppcodemodelsettings.cpp index 3038bf98f9..e25e2d0284 100644 --- a/src/plugins/cppeditor/cppcodemodelsettings.cpp +++ b/src/plugins/cppeditor/cppcodemodelsettings.cpp @@ -314,16 +314,38 @@ QVersionNumber ClangdSettings::clangdVersion(const FilePath &clangdFilePath) return it->second; } -FilePath ClangdSettings::clangdIncludePath() const +static FilePath getClangHeadersPathFromClang(const FilePath &clangdFilePath) { - QTC_ASSERT(useClangd(), return {}); - FilePath clangdPath = clangdFilePath(); - QTC_ASSERT(!clangdPath.isEmpty() && clangdPath.exists(), return {}); - const QVersionNumber version = clangdVersion(); + const FilePath clangFilePath = clangdFilePath.absolutePath().pathAppended("clang") + .withExecutableSuffix(); + if (!clangFilePath.exists()) + return {}; + QtcProcess clang; + clang.setCommand({clangFilePath, {"-print-resource-dir"}}); + clang.start(); + if (!clang.waitForFinished()) + return {}; + const FilePath resourceDir = FilePath::fromUserInput(QString::fromLocal8Bit( + clang.readAllStandardOutput().trimmed())); + if (resourceDir.isEmpty() || !resourceDir.exists()) + return {}; + const FilePath includeDir = resourceDir.pathAppended("include"); + if (!includeDir.exists()) + return {}; + return includeDir; +} + +static FilePath getClangHeadersPath(const FilePath &clangdFilePath) +{ + const FilePath headersPath = getClangHeadersPathFromClang(clangdFilePath); + if (!headersPath.isEmpty()) + return headersPath; + + const QVersionNumber version = ClangdSettings::clangdVersion(clangdFilePath); QTC_ASSERT(!version.isNull(), return {}); static const QStringList libDirs{"lib", "lib64"}; for (const QString &libDir : libDirs) { - const FilePath includePath = clangdPath.absolutePath().parentDir().pathAppended(libDir) + const FilePath includePath = clangdFilePath.absolutePath().parentDir().pathAppended(libDir) .pathAppended("clang").pathAppended(version.toString()).pathAppended("include"); if (includePath.exists()) return includePath; @@ -332,6 +354,21 @@ FilePath ClangdSettings::clangdIncludePath() const return {}; } +FilePath ClangdSettings::clangdIncludePath() const +{ + QTC_ASSERT(useClangd(), return {}); + FilePath clangdPath = clangdFilePath(); + QTC_ASSERT(!clangdPath.isEmpty() && clangdPath.exists(), return {}); + static QHash<FilePath, FilePath> headersPathCache; + const auto it = headersPathCache.constFind(clangdPath); + if (it != headersPathCache.constEnd()) + return *it; + const FilePath headersPath = getClangHeadersPath(clangdPath); + if (!headersPath.isEmpty()) + headersPathCache.insert(clangdPath, headersPath); + return headersPath; +} + FilePath ClangdSettings::clangdUserConfigFilePath() { return FilePath::fromString( |
