[PATCH] D141463: [clang-tidy] Improve rename_check.py

Chris Cotter via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 10 23:49:44 PST 2023


ccotter created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
ccotter requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

rename_check.py now find and renames the test file. rename_check.py
also will now use 'git mv', so the developer no longer has to manually
add the file after running the script.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141463

Files:
  clang-tools-extra/clang-tidy/rename_check.py


Index: clang-tools-extra/clang-tidy/rename_check.py
===================================================================
--- clang-tools-extra/clang-tidy/rename_check.py
+++ clang-tools-extra/clang-tidy/rename_check.py
@@ -15,6 +15,7 @@
 import io
 import os
 import re
+import subprocess
 
 def replaceInFileRegex(fileName, sFrom, sTo):
   if sFrom == sTo:
@@ -71,7 +72,7 @@
     return fileName
   newFileName = fileName.replace(sFrom, sTo)
   print("Renaming '%s' -> '%s'..." % (fileName, newFileName))
-  os.rename(fileName, newFileName)
+  subprocess.check_call(["git", "mv", fileName, newFileName])
   return newFileName
 
 
@@ -93,12 +94,9 @@
 
 
 def getListOfFiles(clang_tidy_path):
-  files = glob.glob(os.path.join(clang_tidy_path, '*'))
-  for dirname in files:
-    if os.path.isdir(dirname):
-      files += glob.glob(os.path.join(dirname, '*'))
+  files = glob.glob(os.path.join(clang_tidy_path, '**'), recursive=True)
   files += glob.glob(os.path.join(clang_tidy_path, '..', 'test',
-                                  'clang-tidy', '*'))
+                                  'clang-tidy', 'checkers', '**'), recursive=True)
   files += glob.glob(os.path.join(clang_tidy_path, '..', 'docs',
                                   'clang-tidy', 'checks', '*'))
   return [filename for filename in files if os.path.isfile(filename)]
@@ -273,10 +271,12 @@
     deleteMatchingLines(os.path.join(old_module_path, modulecpp),
                       '\\b' + check_name_camel + '|\\b' + args.old_check_name)
 
+  old_check_filename = '-'.join(args.old_check_name.split('-')[1:])
+  new_check_filename = '-'.join(args.new_check_name.split('-')[1:])
+
   for filename in getListOfFiles(clang_tidy_path):
     originalName = filename
-    filename = fileRename(filename, args.old_check_name,
-                          args.new_check_name)
+    filename = fileRename(filename, old_check_filename, new_check_filename)
     filename = fileRename(filename, check_name_camel, new_check_name_camel)
     replaceInFile(filename, generateCommentLineHeader(originalName),
                   generateCommentLineHeader(filename))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141463.488090.patch
Type: text/x-patch
Size: 2118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230111/f8dde0bc/attachment.bin>


More information about the cfe-commits mailing list