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

Daan De Meyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 22 03:55:26 PDT 2018


DaanDeMeyer updated this revision to Diff 170384.
DaanDeMeyer added a comment.

Updated diff according to comments.


https://reviews.llvm.org/D53481

Files:
  clangd/tool/ClangdMain.cpp


Index: clangd/tool/ClangdMain.cpp
===================================================================
--- clangd/tool/ClangdMain.cpp
+++ 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.170384.patch
Type: text/x-patch
Size: 1703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181022/48f50860/attachment.bin>


More information about the cfe-commits mailing list