[clang] [clang-tools-extra] In compilation databases, add support for relative directories (PR #69856)

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 24 21:24:22 PDT 2026


MaskRay wrote:

```
The possible bases

┌─────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────┬───────────────────────┬──────────────────────┬─────────────────────────────────────────────────────────────────┐
│              Base for a relative directory              │              Symlink at repo root (your workflow)              │ File copied elsewhere │ Whole checkout moved │             Generator knows the base when writing?              │
├─────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────┼───────────────────────┼──────────────────────┼─────────────────────────────────────────────────────────────────┤
│ A. Path the file was opened through (this branch)       │ Resolves to repo root, which is wrong for a build-dir database │ Meaning changes       │ Works                │ No                                                              │
├─────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────┼───────────────────────┼──────────────────────┼─────────────────────────────────────────────────────────────────┤
│ B. Real location of the file (symlinks followed)        │ Resolves to build/, which is right                             │ Meaning changes       │ Works                │ Yes                                                             │
├─────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────┼───────────────────────┼──────────────────────┼─────────────────────────────────────────────────────────────────┤
│ C. Tool's current directory (what ClangTool does today) │ Depends on how the tool was launched                           │ Same                  │ Same                 │ No                                                              │
├─────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────┼───────────────────────┼──────────────────────┼─────────────────────────────────────────────────────────────────┤
│ D. Workspace/project root (what ccls does)              │ Repo root                                                      │ Works                 │ Works                │ Only if it assumes the root; libTooling has no notion of a root │
└─────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────┴───────────────────────┴──────────────────────┴─────────────────────────────────────────────────────────────────┘
```

This PR implements A, which I think is not ideal.

https://github.com/llvm/llvm-project/pull/69856


More information about the cfe-commits mailing list