diff --git a/clang-tools-extra/clang-tidy/add_new_check.py b/clang-tools-extra/clang-tidy/add_new_check.py --- a/clang-tools-extra/clang-tidy/add_new_check.py +++ b/clang-tools-extra/clang-tidy/add_new_check.py @@ -1,12 +1,12 @@ #!/usr/bin/env python # -#===- add_new_check.py - clang-tidy check generator ----------*- python -*--===# +#===- add_new_check.py - clang-tidy check generator ---------*- python -*--===# # # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # -#===------------------------------------------------------------------------===# +#===-----------------------------------------------------------------------===# from __future__ import print_function @@ -15,8 +15,9 @@ import re import sys -# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry -# and 'False' if the entry already existed. + +# Adapts the module's CMakelist file. Returns 'True' if it could add a new +# entry and 'False' if the entry already existed. def adapt_cmake(module_path, check_name_camel): filename = os.path.join(module_path, 'CMakeLists.txt') with open(filename, 'r') as f: @@ -227,7 +228,6 @@ with open(filename, 'w') as f: note_added = False header_found = False - next_header_found = False add_note_here = False for line in lines: @@ -241,7 +241,6 @@ add_note_here = True if match_next: - next_header_found = True add_note_here = True if match: diff --git a/clang-tools-extra/clang-tidy/rename_check.py b/clang-tools-extra/clang-tidy/rename_check.py --- a/clang-tools-extra/clang-tidy/rename_check.py +++ b/clang-tools-extra/clang-tidy/rename_check.py @@ -1,12 +1,12 @@ #!/usr/bin/env python # -#===- rename_check.py - clang-tidy check renamer -------------*- python -*--===# +#===- rename_check.py - clang-tidy check renamer ------------*- python -*--===# # # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # -#===------------------------------------------------------------------------===# +#===-----------------------------------------------------------------------===# import argparse import glob @@ -26,6 +26,7 @@ with open(fileName, "w") as f: f.write(txt) + def replaceInFile(fileName, sFrom, sTo): if sFrom == sTo: return @@ -66,6 +67,7 @@ os.rename(fileName, newFileName) return newFileName + def deleteMatchingLines(fileName, pattern): lines = None with open(fileName, "r") as f: @@ -82,6 +84,7 @@ return True + def getListOfFiles(clang_tidy_path): files = glob.glob(os.path.join(clang_tidy_path, '*')) for dirname in files: @@ -93,8 +96,9 @@ 'clang-tidy', 'checks', '*')) return [filename for filename in files if os.path.isfile(filename)] -# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry -# and 'False' if the entry already existed. + +# Adapts the module's CMakelist file. Returns 'True' if it could add a new +# entry and 'False' if the entry already existed. def adapt_cmake(module_path, check_name_camel): filename = os.path.join(module_path, 'CMakeLists.txt') with open(filename, 'r') as f: @@ -177,7 +181,6 @@ with open(filename, 'wb') as f: note_added = False header_found = False - next_header_found = False add_note_here = False for line in lines: @@ -191,7 +194,6 @@ add_note_here = True if match_next: - next_header_found = True add_note_here = True if match: @@ -313,5 +315,6 @@ + ' --update-docs') add_release_notes(clang_tidy_path, args.old_check_name, args.new_check_name) + if __name__ == '__main__': main() diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py --- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py +++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py @@ -1,12 +1,12 @@ #!/usr/bin/env python # -#===- clang-tidy-diff.py - ClangTidy Diff Checker ------------*- python -*--===# +#===- clang-tidy-diff.py - ClangTidy Diff Checker -----------*- python -*--===# # # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # -#===------------------------------------------------------------------------===# +#===-----------------------------------------------------------------------===# r""" ClangTidy Diff Checker @@ -75,7 +75,7 @@ sys.stderr.write('Failed: ' + str(e) + ': '.join(command) + '\n') finally: with lock: - if (not timeout is None) and (not watchdog is None): + if not (timeout is None or watchdog is None): if not watchdog.is_alive(): sys.stderr.write('Terminated by timeout: ' + ' '.join(command) + '\n') @@ -89,6 +89,7 @@ t.daemon = True t.start() + def merge_replacement_files(tmpdir, mergefile): """Merge all replacement files in a directory into a single file""" # The fixes suggested by clang-tidy >= 4.0.0 are given under @@ -106,7 +107,7 @@ # include/clang/Tooling/ReplacementsYaml.h, but the value # is actually never used inside clang-apply-replacements, # so we set it to '' here. - output = { 'MainSourceFile': '', mergekey: merged } + output = {'MainSourceFile': '', mergekey: merged} with open(mergefile, 'w') as out: yaml.safe_dump(output, out) else: diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py --- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py +++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py @@ -1,14 +1,15 @@ #!/usr/bin/env python # -#===- run-clang-tidy.py - Parallel clang-tidy runner ---------*- python -*--===# +#===- run-clang-tidy.py - Parallel clang-tidy runner --------*- python -*--===# # # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # -#===------------------------------------------------------------------------===# +#===-----------------------------------------------------------------------===# # FIXME: Integrate with clang-tidy-diff.py + """ Parallel clang-tidy runner ========================== @@ -60,6 +61,7 @@ else: import queue as queue + def find_compilation_database(path): """Adjusts the directory until a compilation database is found.""" result = './' @@ -112,7 +114,7 @@ """Merge all replacement files in a directory into a single file""" # The fixes suggested by clang-tidy >= 4.0.0 are given under # the top level key 'Diagnostics' in the output yaml files - mergekey="Diagnostics" + mergekey = "Diagnostics" merged=[] for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')): content = yaml.safe_load(open(replacefile, 'r')) @@ -125,7 +127,7 @@ # include/clang/Tooling/ReplacementsYaml.h, but the value # is actually never used inside clang-apply-replacements, # so we set it to '' here. - output = { 'MainSourceFile': '', mergekey: merged } + output = {'MainSourceFile': '', mergekey: merged} with open(mergefile, 'w') as out: yaml.safe_dump(output, out) else: @@ -324,11 +326,12 @@ except: print('Error applying fixes.\n', file=sys.stderr) traceback.print_exc() - return_code=1 + return_code = 1 if tmpdir: shutil.rmtree(tmpdir) sys.exit(return_code) + if __name__ == '__main__': main()