MaskRay wrote:
> From clangd standpoint I support resolving relative paths (as described in
> the PR title), but I have concerns about resolving symlinks. TLDR; Holding
> real paths in the compilation database doesn't mean that via LSP we will
> receive real paths. I mean that we still can receive symlinked paths via LSP
> and there can be problems with compile command lookup. Also, I remember there
> were problems with background indexing start in case of symlinked root
> directory (but opening project via real path), here we can face this problem
> from another standpoint (we are using symlikned paths everywhere and
> background indexing won't start because somewhere we resolve symlinks). I
> didn't check that this patch really introduced problems which I mentioned
> above (can do this if really needed, but this can take some time), but I
> expect these problems and maybe some other because symlinks-related problems
> reports happen from time to time in clangd, and it seems to address all
> symlinks-related problems in clangd we need to resolve all paths (including
> paths inside compile command, like `-I<path-is-here>`). So, I think for now
> the better approach is to keep symlinks unresolved everywhere (or resolve
> everywhere, but this maybe won't be easy to implement keeping in mind that
> this will lead to performance degradation, especially on slow filesystems
> like NFS)
Updated to not resolve symlinks: a relative "directory" is relative to the
directory the database was loaded from. This should also suit Buck2, whose
"directory": "." means the project root when its buck-out/ database is
symlinked there.
For ccls I'll use such a patch:
```patch
diff --git a/src/project.cc b/src/project.cc
index e00fb0b9..d21611dc 100644
--- a/src/project.cc
+++ b/src/project.cc
@@ -17,4 +17,5 @@
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Tooling/CompilationDatabase.h>
+#include <clang/Tooling/JSONCompilationDatabase.h>
#include <llvm/ADT/STLExtras.h>
#include <llvm/ADT/StringSet.h>
@@ -312,5 +313,20 @@ void Project::loadDirectory(const std::string &root,
Project::Folder &folder) {
}
- std::unique_ptr<tooling::CompilationDatabase> cdb =
tooling::CompilationDatabase::loadFromDirectory(cdbDir, err_msg);
+ std::unique_ptr<tooling::CompilationDatabase> cdb;
+ if (g_config->compilationDatabaseCommand.empty()) {
+ cdb = tooling::CompilationDatabase::loadFromDirectory(cdbDir, err_msg);
+ } else if (auto buf = MemoryBuffer::getFile(path)) {
+ // The database is in a temporary directory. Resolve a relative
"directory" against the project root.
+#if LLVM_VERSION_MAJOR >= 24
+ cdb = tooling::JSONCompilationDatabase::loadFromBuffer(root,
(*buf)->getBuffer(), err_msg,
+
tooling::JSONCommandLineSyntax::AutoDetect);
+#else
+ cdb =
tooling::JSONCompilationDatabase::loadFromBuffer((*buf)->getBuffer(), err_msg,
+
tooling::JSONCommandLineSyntax::AutoDetect);
+#endif
+ if (cdb)
+ cdb = tooling::inferTargetAndDriverMode(
+ tooling::expandResponseFiles(std::move(cdb),
llvm::vfs::getRealFileSystem()));
+ }
if (!g_config->compilationDatabaseCommand.empty()) {
#ifdef _WIN32
```
https://github.com/llvm/llvm-project/pull/235400
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits