-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file #81985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file #81985
Conversation
…king 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
@llvm/pr-subscribers-clang-tidy @llvm/pr-subscribers-clang-tools-extra Author: Dmitry Polukhin (dmpolukhin) ChangesSummary: 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:
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 120000
index 00000000000000..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 00000000000000..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 00000000000000..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 00000000000000..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 'global_const' [readability-identifier-naming]
+ // CHECK-FIXES: return kGlobalConst;
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks fine, release notes should be updated for clang-tidy.
...ols-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
Outdated
Show resolved
Hide resolved
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. 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. |
Yes, but the majority of checks ignores the problem but
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. |
@@ -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 | |||
<clang-tidy/checks/readability/identifier-naming>` check in ``GetConfigPerFile: true`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use single `, remove : true
- Reduce disk IO usage by adding cache to an realpath introduced by llvm#81985 - Refactor HungarianNotation::getDeclTypeName to remove some string copies and use more safe string API.
- Reduce disk IO usage by adding cache to an realpath introduced by llvm#81985
- Reduce disk IO usage by adding cache to an realpath introduced by #81985
…#92659) - Reduce disk IO usage by adding cache to an realpath introduced by llvm#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