diff options
| author | Stefan Boberg <[email protected]> | 2022-02-02 11:06:37 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2022-02-02 11:06:37 +0100 |
| commit | 1abd19da4f0c3c938411bb005a09874800e9bd43 (patch) | |
| tree | 8d7046921aea5aaeecc88680e35668f7c9e63d40 /scripts/formatcode.py | |
| parent | clang-format (diff) | |
| download | zen-1abd19da4f0c3c938411bb005a09874800e9bd43.tar.xz zen-1abd19da4f0c3c938411bb005a09874800e9bd43.zip | |
Added --no-batch option to formatcode script
Intended as a workaround for cases when clang-format crashes, which often is "fixed" by only formatting a specific file
Diffstat (limited to 'scripts/formatcode.py')
| -rw-r--r-- | scripts/formatcode.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/scripts/formatcode.py b/scripts/formatcode.py index 423d2b4e7..dc13ae117 100644 --- a/scripts/formatcode.py +++ b/scripts/formatcode.py @@ -7,6 +7,7 @@ import re match_expressions = [] valid_extensions = [] root_dir = '' +use_batching = True def is_header_missing(f): with open(f) as reader: @@ -37,7 +38,11 @@ def scan_tree(root): header_files.append(full_path) args = "" if files: - os.system("clang-format -i " + " ".join(files)) + if use_batching: + os.system("clang-format -i " + " ".join(files)) + else: + for file in files: + os.system("clang-format -i " + file) if header_files: add_headers(header_files, "// Copyright Epic Games, Inc. All Rights Reserved.\n\n") @@ -75,26 +80,31 @@ def parse_match_expressions(wildcards, matches): try: match_expressions.append(re.compile(regex, re.IGNORECASE)) except Exception as ex: - print('Could not parse input filename expression \'{}\': {}'.format(wildcard, str(ex))) + print(f'Could not parse input filename expression \'{wildcard}\': {str(ex)}') quit() for regex in matches: try: match_expressions.append(re.compile(regex, re.IGNORECASE)) except Exception as ex: - print('Could not parse input --match expression \'{}\': {}'.format(regex, str(ex))) + print(f'Could not parse input --match expression \'{regex}\': {str(ex)}') quit() def _main(): - global root_dir + global root_dir, use_batching parser = argparse.ArgumentParser() parser.add_argument('filenames', nargs='*', help="Match text for filenames. If fullpath contains text it is a match, " +\ "* is a wildcard. Directory separators are matched by either / or \\. Case insensitive.") parser.add_argument('--match', action='append', default=[], help="Match regular expression for filenames. " +\ "Relative path from the root zen directory must be a complete match. Directory separators are matched only by /. Case insensitive.") + parser.add_argument('--batch', dest='use_batching', action='store_true', help="Enable batching calls to clang-format.") + parser.add_argument('--no-batch', dest='use_batching', action='store_false', help="Disable batching calls to clang-format.") + parser.set_defaults(use_batching=True) options = parser.parse_args() + parse_match_expressions(options.filenames, options.match) root_dir = pathlib.Path(__file__).parent.parent.resolve() + use_batching = options.use_batching while True: if (os.path.isfile(".clang-format")): |