[clang-tools-extra] [clang-include-cleaner] Fix incorrect directory issue for writing files (PR #111375)
Byoungchan Lee via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 8 18:41:24 PDT 2024
bc-lee wrote:
Could you provide a minimal reproducer for this case if possible? Ideally, it should not depend on Google's internal Bazel setup or tools. From what I understand, Bazel itself doesn’t generate compilation databases, and third-party tools adjust the paths of raw compiler invocations to the correct ones. I tested two methods for generating compilation databases for Bazel projects in my demo repository (https://github.com/bc-lee/test-compilation-database), and both methods correctly generated the compilation databases, with no issues traversing over the Bazel build directory.
For instance, when I ran [kiron1/bazel-compile-commands](https://github.com/kiron1/bazel-compile-commands) in my demo repository, it generated the following `compile_commands.json`:
<details>
<summary>Click to toggle</summary>
```json
[
{
"directory": "/home/leebc/.cache/bazel/_bazel_leebc/5ea2deb937e75f0bf29ba4c49931e67d/execroot/_main",
"command": "/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -std=c++14 -MD -MF bazel-out/k8-fastbuild/bin/api/_objs/main/main.pic.d -frandom-seed=bazel-out/k8-fastbuild/bin/api/_objs/main/main.pic.o -fPIC -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -std=c++17 -fno-canonical-system-headers -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -c api/main.cc -o bazel-out/k8-fastbuild/bin/api/_objs/main/main.pic.o",
"file": "api/main.cc",
"output": "bazel-out/k8-fastbuild/bin/api/_objs/main/main.pic.o"
}
]
```
</details>
And `clang-include-cleaner` ran correctly. The file path was `api/main.cc`, and the compiler invocation’s working directory was `/home/leebc/.cache/bazel/_bazel_leebc/5ea2deb937e75f0bf29ba4c49931e67d/execroot/_main`, so `clang-include-cleaner` correctly adjusted the path to `/home/leebc/.cache/bazel/_bazel_leebc/5ea2deb937e75f0bf29ba4c49931e67d/execroot/_main/api/main.cc`, which was correctly symlinked.
If there are any other cases that I missed, please let me know. I’ll try to reproduce the issue and fix it.
https://github.com/llvm/llvm-project/pull/111375
More information about the cfe-commits
mailing list