summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/rename_check.py
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/rename_check.py')
-rwxr-xr-xclang-tools-extra/clang-tidy/rename_check.py48
1 files changed, 35 insertions, 13 deletions
diff --git a/clang-tools-extra/clang-tidy/rename_check.py b/clang-tools-extra/clang-tidy/rename_check.py
index 4eb3d740376..d5f24073496 100755
--- a/clang-tools-extra/clang-tidy/rename_check.py
+++ b/clang-tools-extra/clang-tidy/rename_check.py
@@ -14,6 +14,18 @@ import os
import re
+def replaceInFileRegex(fileName, sFrom, sTo):
+ if sFrom == sTo:
+ return
+ txt = None
+ with open(fileName, "r") as f:
+ txt = f.read()
+
+ txt = re.sub(sFrom, sTo, txt)
+ print("Replacing '%s' -> '%s' in '%s'..." % (sFrom, sTo, fileName))
+ with open(fileName, "w") as f:
+ f.write(txt)
+
def replaceInFile(fileName, sFrom, sTo):
if sFrom == sTo:
return
@@ -203,6 +215,8 @@ def main():
clang_tidy_path = os.path.dirname(__file__)
header_guard_variants = [
+ (args.old_check_name.replace('-', '_')).upper() + '_CHECK',
+ (old_module + '_' + check_name_camel).upper(),
(old_module + '_' + new_check_name_camel).upper(),
args.old_check_name.replace('-', '_').upper()]
header_guard_new = (new_module + '_' + new_check_name_camel).upper()
@@ -210,18 +224,19 @@ def main():
old_module_path = os.path.join(clang_tidy_path, old_module)
new_module_path = os.path.join(clang_tidy_path, new_module)
- # Remove the check from the old module.
- cmake_lists = os.path.join(old_module_path, 'CMakeLists.txt')
- check_found = deleteMatchingLines(cmake_lists, '\\b' + check_name_camel)
- if not check_found:
- print("Check name '%s' not found in %s. Exiting." %
+ if (args.old_check_name != args.new_check_name):
+ # Remove the check from the old module.
+ cmake_lists = os.path.join(old_module_path, 'CMakeLists.txt')
+ check_found = deleteMatchingLines(cmake_lists, '\\b' + check_name_camel)
+ if not check_found:
+ print("Check name '%s' not found in %s. Exiting." %
(check_name_camel, cmake_lists))
- return 1
+ return 1
- modulecpp = filter(
- lambda p: p.lower() == old_module.lower() + 'tidymodule.cpp',
- os.listdir(old_module_path))[0]
- deleteMatchingLines(os.path.join(old_module_path, modulecpp),
+ modulecpp = filter(
+ lambda p: p.lower() == old_module.lower() + 'tidymodule.cpp',
+ os.listdir(old_module_path))[0]
+ deleteMatchingLines(os.path.join(old_module_path, modulecpp),
'\\b' + check_name_camel + '|\\b' + args.old_check_name)
for filename in getListOfFiles(clang_tidy_path):
@@ -249,14 +264,21 @@ def main():
new_module + '/' + new_check_name_camel)
replaceInFile(filename, check_name_camel, new_check_name_camel)
- if old_module != new_module:
+ if old_module != new_module or new_module == 'llvm':
+ if new_module == 'llvm':
+ new_namespace = new_module + '_check'
+ else:
+ new_namespace = new_module
check_implementation_files = glob.glob(
os.path.join(old_module_path, new_check_name_camel + '*'))
for filename in check_implementation_files:
# Move check implementation to the directory of the new module.
filename = fileRename(filename, old_module_path, new_module_path)
- replaceInFile(filename, 'namespace ' + old_module,
- 'namespace ' + new_module)
+ replaceInFileRegex(filename, 'namespace ' + old_module + '[^ \n]*',
+ 'namespace ' + new_namespace)
+
+ if (args.old_check_name == args.new_check_name):
+ return
# Add check to the new module.
adapt_cmake(new_module_path, new_check_name_camel)
OpenPOWER on IntegriCloud