[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-19 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin closed 
https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-17 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.


https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/81985

>From ddafb4672e1a481d4a9556ebe31ca9a07e1f3569 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 16 Feb 2024 03:51:07 -0800
Subject: [PATCH 1/3] [clang-tidy][readability-identifier-naming] Resolve
 symlinks for checking style for file

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools
---
 .../readability/IdentifierNamingCheck.cpp |  7 +--
 .../Inputs/identifier-naming/symlink/build/test.h |  1 +
 .../identifier-naming/symlink/include/.clang-tidy |  4 
 .../identifier-naming/symlink/include/test.h  |  1 +
 .../readability/identifier-naming-symlink.cpp | 15 +++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 12 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
new file mode 100644
index 00..72926bff908df8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
@@ -0,0 +1,15 @@
+// Specify `-std=c++20` to run test only once becuase test expects changes
+// in the header file so it fails if runs multiple times with different
+// `-std` flags as check_clang_tidy doesn by default.
+//
+// RUN: rm 

[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/81985

>From ddafb4672e1a481d4a9556ebe31ca9a07e1f3569 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 16 Feb 2024 03:51:07 -0800
Subject: [PATCH 1/3] [clang-tidy][readability-identifier-naming] Resolve
 symlinks for checking style for file

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools
---
 .../readability/IdentifierNamingCheck.cpp |  7 +--
 .../Inputs/identifier-naming/symlink/build/test.h |  1 +
 .../identifier-naming/symlink/include/.clang-tidy |  4 
 .../identifier-naming/symlink/include/test.h  |  1 +
 .../readability/identifier-naming-symlink.cpp | 15 +++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 12 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
new file mode 100644
index 00..72926bff908df8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
@@ -0,0 +1,15 @@
+// Specify `-std=c++20` to run test only once becuase test expects changes
+// in the header file so it fails if runs multiple times with different
+// `-std` flags as check_clang_tidy doesn by default.
+//
+// RUN: rm 

[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Piotr Zegar via cfe-commits


@@ -164,6 +164,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`readability-identifier-naming
+  ` check in 
``GetConfigPerFile: true``

PiotrZSL wrote:

use single \`, remove `: true`

https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.


https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

> This problem seems like it should be handled globally, not in a single 
> specific check. IIUC any check that reads options from the .clang-tidy file 
> is affected.

Yes, but the majority of checks ignores the problem but 
`readability-identifier-naming` handles styles per file so improving logic here 
makes sense to me. About general issue with checks being selected by main file 
there are several discussions as far as I know without clear direction that all 
agreed.

> What build system are you using, bazel? We use it and don't have any 
> problems. If your build system creates a sandbox, you need to make sure 
> clang-tidy is also executed from within that sandbox.

I'm talking about Buck in some configurations but I think Bazel also should be 
affected. Projects with more unified styles usually significantly less affected 
because .clang-tidy config in higher level can be found and used in some cases.

https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

This problem seems like it should be handled globally, not in a single specific 
check. IIUC any check that reads options from the .cñsng-tidy file is affected.

What build system are you using, bazel? We use it and don't have any problems. 
If your build system creates a sandbox, you need to make sure clang-tidy is 
also executed from within that sandbox.

https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/81985

>From ddafb4672e1a481d4a9556ebe31ca9a07e1f3569 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 16 Feb 2024 03:51:07 -0800
Subject: [PATCH 1/2] [clang-tidy][readability-identifier-naming] Resolve
 symlinks for checking style for file

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools
---
 .../readability/IdentifierNamingCheck.cpp |  7 +--
 .../Inputs/identifier-naming/symlink/build/test.h |  1 +
 .../identifier-naming/symlink/include/.clang-tidy |  4 
 .../identifier-naming/symlink/include/test.h  |  1 +
 .../readability/identifier-naming-symlink.cpp | 15 +++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 12 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
new file mode 100644
index 00..72926bff908df8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
@@ -0,0 +1,15 @@
+// Specify `-std=c++20` to run test only once becuase test expects changes
+// in the header file so it fails if runs multiple times with different
+// `-std` flags as check_clang_tidy doesn by default.
+//
+// RUN: rm 

[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL commented:

Overall looks fine, release notes should be updated for clang-tidy.

https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1 @@
+../include/test.h

PiotrZSL wrote:

this symlink should be created on fly, to avoid some random issues on checkout.

https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Dmitry Polukhin (dmpolukhin)


Changes

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools

---
Full diff: https://github.com/llvm/llvm-project/pull/81985.diff


5 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
(+5-2) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 (+1) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 (+4) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 (+1) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 (+15) 


``diff
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
new file mode 100644
index 00..72926bff908df8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
@@ -0,0 +1,15 @@
+// Specify `-std=c++20` to run test only once becuase test expects changes
+// in the header file so it fails if runs multiple times with different
+// `-std` flags as check_clang_tidy doesn by default.
+//
+// RUN: rm -rf %T/symlink
+// RUN: cp -r %S/Inputs/identifier-naming/symlink %T/symlink
+// RUN: %check_clang_tidy -std=c++20 %s readability-identifier-naming %t -- 
--header-filter="test.h" 
--config-file=%S/Inputs/identifier-naming/symlink/include/.clang-tidy -- -I 
%T/symlink/build
+
+#include "test.h"
+
+int foo() {
+return global_const;
+// CHECK-MESSAGES: warning: invalid case style for global constant 

[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin created 
https://github.com/llvm/llvm-project/pull/81985

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools

>From ddafb4672e1a481d4a9556ebe31ca9a07e1f3569 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 16 Feb 2024 03:51:07 -0800
Subject: [PATCH] [clang-tidy][readability-identifier-naming] Resolve symlinks
 for checking style for file

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools
---
 .../readability/IdentifierNamingCheck.cpp |  7 +--
 .../Inputs/identifier-naming/symlink/build/test.h |  1 +
 .../identifier-naming/symlink/include/.clang-tidy |  4 
 .../identifier-naming/symlink/include/test.h  |  1 +
 .../readability/identifier-naming-symlink.cpp | 15 +++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 12 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git