llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.12k stars 12.01k forks source link

clang-format breaks symlinks #46336

Open stephenhines opened 4 years ago

stephenhines commented 4 years ago
Bugzilla Link 46992
Resolution FIXED
Resolved on May 11, 2021 20:50
Version unspecified
OS Linux
CC @pirama-arumuga-nainar

Extended Description

This comes from an Android bug about running clang-format on a symlinked file (in this case, one named DisplayId.h that is pointing to a different DisplayId.h).

diff --git a/libs/ui/include_vndk/ui/DisplayId.h b/libs/ui/include_vndk/ui/DisplayId.h index 73c9fe8d689..ec31ce4a306 120000 --- a/libs/ui/include_vndk/ui/DisplayId.h +++ b/libs/ui/include_vndk/ui/DisplayId.h @@ -1 +1 @@ -../../include/ui/DisplayId.h \ No newline at end of file +../../ include / ui / DisplayId.h \ No newline at end of file

Ideally, clang-format would detect that it is running on a symlink and not adjust the file at all.

pirama-arumuga-nainar commented 3 years ago

Fixed by 0fd0a010a1ed2ce761d20bfc6378e5bbaa75c8de (https://reviews.llvm.org/D101878).

pirama-arumuga-nainar commented 3 years ago

To reproduce:

  1. create a symlink foo.h and commit it to a git project
  2. git-clang-format --diff --style file --extensions c,h,cc,cpp 85e55396aaa5ad5661232154f2ce778f4752b79f^ 85e55396aaa5ad5661232154f2ce778f4752b79f

This'd suggest a formatting change to the foo.h.

https://reviews.llvm.org/D101878 has a proposed fix.

stephenhines commented 4 years ago

assigned to @pirama-arumuga-nainar

NikolausDemmel commented 11 months ago

It seems this was fixed only for git-clang-format. If you run clang-format -i on a symlink, it still seems replace the symlink with a regular file. I would expect it to either replace the file the symlink points to, or to skip the symlink.

Can this issue be reopened?