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 =


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 =
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to