[PATCH] D53481: [clangd] Support passing a relative path to -compile-commands-dir

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 23 04:56:52 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL345022: [clangd] Support passing a relative path to -compile-commands-dir (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D53481?vs=170384&id=170609#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53481

Files:
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -251,16 +251,24 @@
   // If --compile-commands-dir arg was invoked, check value and override default
   // path.
   Optional<Path> CompileCommandsDirPath;
-  if (CompileCommandsDir.empty()) {
-    CompileCommandsDirPath = None;
-  } else if (!sys::path::is_absolute(CompileCommandsDir) ||
-             !sys::fs::exists(CompileCommandsDir)) {
-    errs() << "Path specified by --compile-commands-dir either does not "
-              "exist or is not an absolute "
-              "path. The argument will be ignored.\n";
-    CompileCommandsDirPath = None;
-  } else {
-    CompileCommandsDirPath = CompileCommandsDir;
+  if (!CompileCommandsDir.empty()) {
+    if (sys::fs::exists(CompileCommandsDir)) {
+      // We support passing both relative and absolute paths to the
+      // --compile-commands-dir argument, but we assume the path is absolute in
+      // the rest of clangd so we make sure the path is absolute before
+      // continuing.
+      SmallString<128> Path(CompileCommandsDir);
+      if (std::error_code EC = sys::fs::make_absolute(Path)) {
+        errs() << "Error while converting the relative path specified by "
+                  "--compile-commands-dir to an absolute path: "
+               << EC.message() << ". The argument will be ignored.\n";
+      } else {
+        CompileCommandsDirPath = Path.str();
+      }
+    } else {
+      errs() << "Path specified by --compile-commands-dir does not exist. The "
+                "argument will be ignored.\n";
+    }
   }
 
   ClangdServer::Options Opts;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53481.170609.patch
Type: text/x-patch
Size: 1775 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181023/a5b1168b/attachment.bin>


More information about the cfe-commits mailing list