[PATCH] D154903: clangd: Provide the resource dir via environment variable
Paul Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 10 15:43:04 PDT 2023
madscientist created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
madscientist published this revision for review.
madscientist added a comment.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
Ready for review please see https://github.com/clangd/clangd/issues/1695
Set an environment variable CLANGD_RESOURCE_DIR to the path of the Clang
resource directory, so that the compiler driver can (a) know it's being
invoked from clangd and (b) massage its system include paths to use the
Clang resources if it wishes to.
This addresses clangd/clangd#1695
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D154903
Files:
clang-tools-extra/clangd/tool/ClangdMain.cpp
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -982,6 +982,22 @@
Opts.Encoding = ForceOffsetEncoding;
setIncludeCleanerAnalyzesStdlib(IncludeCleanerStdlib);
+ constexpr const char *ResourceEnvVar = "CLANGD_RESOURCE_DIR";
+ std::string Resources;
+ if (!::getenv(ResourceEnvVar)) {
+ if (Opts.ResourceDir)
+ Resources = *Opts.ResourceDir;
+ if (Resources.empty()) {
+ static int StaticForMainAddr;
+ Resources = CompilerInvocation::GetResourcesPath(
+ "clangd", (void *)&StaticForMainAddr);
+ }
+ if (!Resources.empty()) {
+ ::setenv(ResourceEnvVar, Resources.c_str(), 1);
+ log("Setting {0} to \"{1}\"", ResourceEnvVar, Resources);
+ }
+ }
+
if (CheckFile.getNumOccurrences()) {
llvm::SmallString<256> Path;
if (auto Error =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154903.538856.patch
Type: text/x-patch
Size: 975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230710/93d52c2e/attachment.bin>
More information about the cfe-commits
mailing list