[PATCH] D68026: [clang-tidy] Make llvm-header-guard work on llvm git monorepo
Haojian Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 02:54:49 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372953: [clang-tidy] Make llvm-header-guard work on llvm git monorepo (authored by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D68026?vs=221765&id=221905#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68026/new/
https://reviews.llvm.org/D68026
Files:
clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp
clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp
Index: clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp
@@ -211,6 +211,15 @@
"#endif /* LLVM_ADT_FOO_H\\ \n"
" FOO */",
"include/llvm/ADT/foo.h", None));
+
+ EXPECT_EQ("#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FOO_H\n"
+ "#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FOO_H\n"
+ "\n"
+ "\n"
+ "#endif\n",
+ runHeaderGuardCheck(
+ "", "/llvm-project/clang-tools-extra/clangd/foo.h",
+ StringRef("header is missing header guard")));
}
#endif
Index: clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp
@@ -33,6 +33,13 @@
if (PosToolsClang != StringRef::npos)
Guard = Guard.substr(PosToolsClang + std::strlen("tools/"));
+ // Unlike LLVM svn, LLVM git monorepo is named llvm-project, so we replace
+ // "/llvm-project/" with the cannonical "/llvm/".
+ const static StringRef LLVMProject = "/llvm-project/";
+ size_t PosLLVMProject = Guard.rfind(LLVMProject);
+ if (PosLLVMProject != StringRef::npos)
+ Guard = Guard.replace(PosLLVMProject, LLVMProject.size(), "/llvm/");
+
// The remainder is LLVM_FULL_PATH_TO_HEADER_H
size_t PosLLVM = Guard.rfind("llvm/");
if (PosLLVM != StringRef::npos)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68026.221905.patch
Type: text/x-patch
Size: 1746 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190926/dfad2137/attachment.bin>
More information about the llvm-commits
mailing list