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