Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | #===- run-clang-tidy.py - Parallel clang-tidy runner ---------*- python -*--===# |
| 4 | # |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 5 | # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 6 | # See https://llvm.org/LICENSE.txt for license information. |
| 7 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 8 | # |
| 9 | #===------------------------------------------------------------------------===# |
| 10 | # FIXME: Integrate with clang-tidy-diff.py |
| 11 | |
| 12 | """ |
| 13 | Parallel clang-tidy runner |
| 14 | ========================== |
| 15 | |
| 16 | Runs clang-tidy over all files in a compilation database. Requires clang-tidy |
| 17 | and clang-apply-replacements in $PATH. |
| 18 | |
| 19 | Example invocations. |
| 20 | - Run clang-tidy on all files in the current working directory with a default |
| 21 | set of checks and show warnings in the cpp files and all project headers. |
| 22 | run-clang-tidy.py $PWD |
| 23 | |
| 24 | - Fix all header guards. |
| 25 | run-clang-tidy.py -fix -checks=-*,llvm-header-guard |
| 26 | |
| 27 | - Fix all header guards included from clang-tidy and header guards |
| 28 | for clang-tidy headers. |
| 29 | run-clang-tidy.py -fix -checks=-*,llvm-header-guard extra/clang-tidy \ |
| 30 | -header-filter=extra/clang-tidy |
| 31 | |
| 32 | Compilation database setup: |
| 33 | http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html |
| 34 | """ |
| 35 | |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 36 | from __future__ import print_function |
Kevin Funk | d331cb6 | 2017-09-05 12:36:33 +0000 | [diff] [blame] | 37 | |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 38 | import argparse |
Alexander Kornienko | 16300e1 | 2017-07-21 10:31:26 +0000 | [diff] [blame] | 39 | import glob |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 40 | import json |
| 41 | import multiprocessing |
| 42 | import os |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 43 | import re |
| 44 | import shutil |
| 45 | import subprocess |
| 46 | import sys |
| 47 | import tempfile |
| 48 | import threading |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 49 | import traceback |
Zinovy Nis | f8b7269f | 2019-03-27 19:21:32 +0000 | [diff] [blame] | 50 | |
| 51 | try: |
| 52 | import yaml |
| 53 | except ImportError: |
| 54 | yaml = None |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 55 | |
Kevin Funk | d331cb6 | 2017-09-05 12:36:33 +0000 | [diff] [blame] | 56 | is_py2 = sys.version[0] == '2' |
| 57 | |
| 58 | if is_py2: |
| 59 | import Queue as queue |
| 60 | else: |
| 61 | import queue as queue |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 62 | |
| 63 | def find_compilation_database(path): |
| 64 | """Adjusts the directory until a compilation database is found.""" |
| 65 | result = './' |
| 66 | while not os.path.isfile(os.path.join(result, path)): |
| 67 | if os.path.realpath(result) == '/': |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 68 | print('Error: could not find compilation database.') |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 69 | sys.exit(1) |
| 70 | result += '../' |
| 71 | return os.path.realpath(result) |
| 72 | |
| 73 | |
Gabor Horvath | 8de900a | 2017-11-06 10:36:02 +0000 | [diff] [blame] | 74 | def make_absolute(f, directory): |
| 75 | if os.path.isabs(f): |
| 76 | return f |
| 77 | return os.path.normpath(os.path.join(directory, f)) |
| 78 | |
| 79 | |
Benjamin Kramer | 815dbad | 2014-09-08 14:56:40 +0000 | [diff] [blame] | 80 | def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path, |
Julie Hockett | c3716ca | 2018-03-09 23:26:56 +0000 | [diff] [blame] | 81 | header_filter, extra_arg, extra_arg_before, quiet, |
| 82 | config): |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 83 | """Gets a command line for clang-tidy.""" |
Benjamin Kramer | 815dbad | 2014-09-08 14:56:40 +0000 | [diff] [blame] | 84 | start = [clang_tidy_binary] |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 85 | if header_filter is not None: |
| 86 | start.append('-header-filter=' + header_filter) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 87 | if checks: |
Alexander Kornienko | 3f11538 | 2015-09-08 10:31:36 +0000 | [diff] [blame] | 88 | start.append('-checks=' + checks) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 89 | if tmpdir is not None: |
| 90 | start.append('-export-fixes') |
| 91 | # Get a temporary file. We immediately close the handle so clang-tidy can |
| 92 | # overwrite it. |
| 93 | (handle, name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir) |
Benjamin Kramer | 815dbad | 2014-09-08 14:56:40 +0000 | [diff] [blame] | 94 | os.close(handle) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 95 | start.append(name) |
Ehsan Akhgari | 221ab77 | 2017-01-18 17:49:35 +0000 | [diff] [blame] | 96 | for arg in extra_arg: |
| 97 | start.append('-extra-arg=%s' % arg) |
| 98 | for arg in extra_arg_before: |
| 99 | start.append('-extra-arg-before=%s' % arg) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 100 | start.append('-p=' + build_path) |
Ehsan Akhgari | b7418d3 | 2017-02-09 18:32:02 +0000 | [diff] [blame] | 101 | if quiet: |
| 102 | start.append('-quiet') |
Julie Hockett | c3716ca | 2018-03-09 23:26:56 +0000 | [diff] [blame] | 103 | if config: |
| 104 | start.append('-config=' + config) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 105 | start.append(f) |
| 106 | return start |
| 107 | |
| 108 | |
Alexander Kornienko | 16300e1 | 2017-07-21 10:31:26 +0000 | [diff] [blame] | 109 | def merge_replacement_files(tmpdir, mergefile): |
| 110 | """Merge all replacement files in a directory into a single file""" |
| 111 | # The fixes suggested by clang-tidy >= 4.0.0 are given under |
| 112 | # the top level key 'Diagnostics' in the output yaml files |
| 113 | mergekey="Diagnostics" |
| 114 | merged=[] |
| 115 | for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')): |
| 116 | content = yaml.safe_load(open(replacefile, 'r')) |
| 117 | if not content: |
| 118 | continue # Skip empty files. |
| 119 | merged.extend(content.get(mergekey, [])) |
| 120 | |
| 121 | if merged: |
| 122 | # MainSourceFile: The key is required by the definition inside |
| 123 | # include/clang/Tooling/ReplacementsYaml.h, but the value |
| 124 | # is actually never used inside clang-apply-replacements, |
| 125 | # so we set it to '' here. |
| 126 | output = { 'MainSourceFile': '', mergekey: merged } |
| 127 | with open(mergefile, 'w') as out: |
| 128 | yaml.safe_dump(output, out) |
| 129 | else: |
| 130 | # Empty the file: |
| 131 | open(mergefile, 'w').close() |
| 132 | |
| 133 | |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 134 | def check_clang_apply_replacements_binary(args): |
| 135 | """Checks if invoking supplied clang-apply-replacements binary works.""" |
| 136 | try: |
| 137 | subprocess.check_call([args.clang_apply_replacements_binary, '--version']) |
| 138 | except: |
| 139 | print('Unable to run clang-apply-replacements. Is clang-apply-replacements ' |
| 140 | 'binary correctly specified?', file=sys.stderr) |
| 141 | traceback.print_exc() |
| 142 | sys.exit(1) |
| 143 | |
| 144 | |
Benjamin Kramer | 815dbad | 2014-09-08 14:56:40 +0000 | [diff] [blame] | 145 | def apply_fixes(args, tmpdir): |
Alexander Kornienko | 16300e1 | 2017-07-21 10:31:26 +0000 | [diff] [blame] | 146 | """Calls clang-apply-fixes on a given directory.""" |
Benjamin Kramer | 815dbad | 2014-09-08 14:56:40 +0000 | [diff] [blame] | 147 | invocation = [args.clang_apply_replacements_binary] |
| 148 | if args.format: |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 149 | invocation.append('-format') |
Vassil Vassilev | c4c33ce | 2017-06-09 22:23:03 +0000 | [diff] [blame] | 150 | if args.style: |
| 151 | invocation.append('-style=' + args.style) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 152 | invocation.append(tmpdir) |
| 153 | subprocess.call(invocation) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 154 | |
| 155 | |
Andi-Bogdan Postelnicu | bebcd6f | 2018-08-10 11:50:47 +0000 | [diff] [blame] | 156 | def run_tidy(args, tmpdir, build_path, queue, lock, failed_files): |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 157 | """Takes filenames out of queue and runs clang-tidy on them.""" |
| 158 | while True: |
| 159 | name = queue.get() |
Benjamin Kramer | 815dbad | 2014-09-08 14:56:40 +0000 | [diff] [blame] | 160 | invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks, |
Ehsan Akhgari | 221ab77 | 2017-01-18 17:49:35 +0000 | [diff] [blame] | 161 | tmpdir, build_path, args.header_filter, |
Ehsan Akhgari | b7418d3 | 2017-02-09 18:32:02 +0000 | [diff] [blame] | 162 | args.extra_arg, args.extra_arg_before, |
Julie Hockett | c3716ca | 2018-03-09 23:26:56 +0000 | [diff] [blame] | 163 | args.quiet, args.config) |
Andi-Bogdan Postelnicu | bebcd6f | 2018-08-10 11:50:47 +0000 | [diff] [blame] | 164 | |
| 165 | proc = subprocess.Popen(invocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 166 | output, err = proc.communicate() |
| 167 | if proc.returncode != 0: |
Miklos Vajna | 10fe9bc | 2018-03-19 14:43:59 +0000 | [diff] [blame] | 168 | failed_files.append(name) |
Andi-Bogdan Postelnicu | bebcd6f | 2018-08-10 11:50:47 +0000 | [diff] [blame] | 169 | with lock: |
Jonas Toth | f12c973 | 2019-05-16 12:39:22 +0000 | [diff] [blame] | 170 | sys.stdout.write(' '.join(invocation) + '\n' + output.decode('utf-8')) |
Andi-Bogdan Postelnicu | 1a05697 | 2018-09-19 11:52:20 +0000 | [diff] [blame] | 171 | if len(err) > 0: |
Andi-Bogdan Postelnicu | 965c581 | 2019-04-09 11:17:02 +0000 | [diff] [blame] | 172 | sys.stdout.flush() |
Jonas Toth | f12c973 | 2019-05-16 12:39:22 +0000 | [diff] [blame] | 173 | sys.stderr.write(err.decode('utf-8')) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 174 | queue.task_done() |
| 175 | |
| 176 | |
| 177 | def main(): |
| 178 | parser = argparse.ArgumentParser(description='Runs clang-tidy over all files ' |
| 179 | 'in a compilation database. Requires ' |
| 180 | 'clang-tidy and clang-apply-replacements in ' |
| 181 | '$PATH.') |
Benjamin Kramer | 815dbad | 2014-09-08 14:56:40 +0000 | [diff] [blame] | 182 | parser.add_argument('-clang-tidy-binary', metavar='PATH', |
| 183 | default='clang-tidy', |
| 184 | help='path to clang-tidy binary') |
| 185 | parser.add_argument('-clang-apply-replacements-binary', metavar='PATH', |
| 186 | default='clang-apply-replacements', |
| 187 | help='path to clang-apply-replacements binary') |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 188 | parser.add_argument('-checks', default=None, |
| 189 | help='checks filter, when not specified, use clang-tidy ' |
| 190 | 'default') |
Julie Hockett | c3716ca | 2018-03-09 23:26:56 +0000 | [diff] [blame] | 191 | parser.add_argument('-config', default=None, |
| 192 | help='Specifies a configuration in YAML/JSON format: ' |
| 193 | ' -config="{Checks: \'*\', ' |
| 194 | ' CheckOptions: [{key: x, ' |
| 195 | ' value: y}]}" ' |
| 196 | 'When the value is empty, clang-tidy will ' |
| 197 | 'attempt to find a file named .clang-tidy for ' |
| 198 | 'each source file in its parent directories.') |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 199 | parser.add_argument('-header-filter', default=None, |
| 200 | help='regular expression matching the names of the ' |
| 201 | 'headers to output diagnostics from. Diagnostics from ' |
| 202 | 'the main file of each translation unit are always ' |
| 203 | 'displayed.') |
Zinovy Nis | f8b7269f | 2019-03-27 19:21:32 +0000 | [diff] [blame] | 204 | if yaml: |
| 205 | parser.add_argument('-export-fixes', metavar='filename', dest='export_fixes', |
| 206 | help='Create a yaml file to store suggested fixes in, ' |
| 207 | 'which can be applied with clang-apply-replacements.') |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 208 | parser.add_argument('-j', type=int, default=0, |
| 209 | help='number of tidy instances to be run in parallel.') |
| 210 | parser.add_argument('files', nargs='*', default=['.*'], |
| 211 | help='files to be processed (regex on path)') |
| 212 | parser.add_argument('-fix', action='store_true', help='apply fix-its') |
| 213 | parser.add_argument('-format', action='store_true', help='Reformat code ' |
| 214 | 'after applying fixes') |
Vassil Vassilev | c4c33ce | 2017-06-09 22:23:03 +0000 | [diff] [blame] | 215 | parser.add_argument('-style', default='file', help='The style of reformat ' |
| 216 | 'code after applying fixes') |
Guillaume Papin | 68b5910 | 2015-09-28 17:53:04 +0000 | [diff] [blame] | 217 | parser.add_argument('-p', dest='build_path', |
| 218 | help='Path used to read a compile command database.') |
Ehsan Akhgari | 221ab77 | 2017-01-18 17:49:35 +0000 | [diff] [blame] | 219 | parser.add_argument('-extra-arg', dest='extra_arg', |
| 220 | action='append', default=[], |
| 221 | help='Additional argument to append to the compiler ' |
| 222 | 'command line.') |
| 223 | parser.add_argument('-extra-arg-before', dest='extra_arg_before', |
| 224 | action='append', default=[], |
| 225 | help='Additional argument to prepend to the compiler ' |
| 226 | 'command line.') |
Ehsan Akhgari | b7418d3 | 2017-02-09 18:32:02 +0000 | [diff] [blame] | 227 | parser.add_argument('-quiet', action='store_true', |
| 228 | help='Run clang-tidy in quiet mode') |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 229 | args = parser.parse_args() |
| 230 | |
Guillaume Papin | 68b5910 | 2015-09-28 17:53:04 +0000 | [diff] [blame] | 231 | db_path = 'compile_commands.json' |
| 232 | |
| 233 | if args.build_path is not None: |
| 234 | build_path = args.build_path |
| 235 | else: |
| 236 | # Find our database |
| 237 | build_path = find_compilation_database(db_path) |
| 238 | |
Benjamin Kramer | 815dbad | 2014-09-08 14:56:40 +0000 | [diff] [blame] | 239 | try: |
Alexander Kornienko | f73fe3a | 2014-09-22 00:07:07 +0000 | [diff] [blame] | 240 | invocation = [args.clang_tidy_binary, '-list-checks'] |
Guillaume Papin | 68b5910 | 2015-09-28 17:53:04 +0000 | [diff] [blame] | 241 | invocation.append('-p=' + build_path) |
Alexander Kornienko | f73fe3a | 2014-09-22 00:07:07 +0000 | [diff] [blame] | 242 | if args.checks: |
Alexander Kornienko | 3f11538 | 2015-09-08 10:31:36 +0000 | [diff] [blame] | 243 | invocation.append('-checks=' + args.checks) |
Alexander Kornienko | f73fe3a | 2014-09-22 00:07:07 +0000 | [diff] [blame] | 244 | invocation.append('-') |
Jonas Toth | 3cbf3c8 | 2019-05-16 09:22:39 +0000 | [diff] [blame] | 245 | if args.quiet: |
| 246 | # Even with -quiet we still want to check if we can call clang-tidy. |
| 247 | with open(os.devnull, 'w') as dev_null: |
| 248 | subprocess.check_call(invocation, stdout=dev_null) |
| 249 | else: |
| 250 | subprocess.check_call(invocation) |
Benjamin Kramer | 815dbad | 2014-09-08 14:56:40 +0000 | [diff] [blame] | 251 | except: |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 252 | print("Unable to run clang-tidy.", file=sys.stderr) |
Benjamin Kramer | 815dbad | 2014-09-08 14:56:40 +0000 | [diff] [blame] | 253 | sys.exit(1) |
| 254 | |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 255 | # Load the database and extract all files. |
| 256 | database = json.load(open(os.path.join(build_path, db_path))) |
Gabor Horvath | 8de900a | 2017-11-06 10:36:02 +0000 | [diff] [blame] | 257 | files = [make_absolute(entry['file'], entry['directory']) |
| 258 | for entry in database] |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 259 | |
| 260 | max_task = args.j |
| 261 | if max_task == 0: |
| 262 | max_task = multiprocessing.cpu_count() |
| 263 | |
| 264 | tmpdir = None |
Zinovy Nis | f8b7269f | 2019-03-27 19:21:32 +0000 | [diff] [blame] | 265 | if args.fix or (yaml and args.export_fixes): |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 266 | check_clang_apply_replacements_binary(args) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 267 | tmpdir = tempfile.mkdtemp() |
| 268 | |
| 269 | # Build up a big regexy filter from all command line arguments. |
Alexander Kornienko | eaada5c | 2017-03-23 16:29:39 +0000 | [diff] [blame] | 270 | file_name_re = re.compile('|'.join(args.files)) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 271 | |
Miklos Vajna | 10fe9bc | 2018-03-19 14:43:59 +0000 | [diff] [blame] | 272 | return_code = 0 |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 273 | try: |
| 274 | # Spin up a bunch of tidy-launching threads. |
Kevin Funk | d331cb6 | 2017-09-05 12:36:33 +0000 | [diff] [blame] | 275 | task_queue = queue.Queue(max_task) |
Miklos Vajna | 10fe9bc | 2018-03-19 14:43:59 +0000 | [diff] [blame] | 276 | # List of files with a non-zero return code. |
| 277 | failed_files = [] |
Andi-Bogdan Postelnicu | bebcd6f | 2018-08-10 11:50:47 +0000 | [diff] [blame] | 278 | lock = threading.Lock() |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 279 | for _ in range(max_task): |
| 280 | t = threading.Thread(target=run_tidy, |
Andi-Bogdan Postelnicu | bebcd6f | 2018-08-10 11:50:47 +0000 | [diff] [blame] | 281 | args=(args, tmpdir, build_path, task_queue, lock, failed_files)) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 282 | t.daemon = True |
| 283 | t.start() |
| 284 | |
| 285 | # Fill the queue with files. |
| 286 | for name in files: |
| 287 | if file_name_re.search(name): |
Kevin Funk | d331cb6 | 2017-09-05 12:36:33 +0000 | [diff] [blame] | 288 | task_queue.put(name) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 289 | |
| 290 | # Wait for all threads to be done. |
Kevin Funk | d331cb6 | 2017-09-05 12:36:33 +0000 | [diff] [blame] | 291 | task_queue.join() |
Miklos Vajna | 10fe9bc | 2018-03-19 14:43:59 +0000 | [diff] [blame] | 292 | if len(failed_files): |
| 293 | return_code = 1 |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 294 | |
| 295 | except KeyboardInterrupt: |
| 296 | # This is a sad hack. Unfortunately subprocess goes |
| 297 | # bonkers with ctrl-c and we start forking merrily. |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 298 | print('\nCtrl-C detected, goodbye.') |
Alexander Kornienko | 16300e1 | 2017-07-21 10:31:26 +0000 | [diff] [blame] | 299 | if tmpdir: |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 300 | shutil.rmtree(tmpdir) |
| 301 | os.kill(0, 9) |
| 302 | |
Zinovy Nis | f8b7269f | 2019-03-27 19:21:32 +0000 | [diff] [blame] | 303 | if yaml and args.export_fixes: |
Alexander Kornienko | 16300e1 | 2017-07-21 10:31:26 +0000 | [diff] [blame] | 304 | print('Writing fixes to ' + args.export_fixes + ' ...') |
| 305 | try: |
| 306 | merge_replacement_files(tmpdir, args.export_fixes) |
| 307 | except: |
| 308 | print('Error exporting fixes.\n', file=sys.stderr) |
| 309 | traceback.print_exc() |
| 310 | return_code=1 |
| 311 | |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 312 | if args.fix: |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 313 | print('Applying fixes ...') |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 314 | try: |
| 315 | apply_fixes(args, tmpdir) |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 316 | except: |
| 317 | print('Error applying fixes.\n', file=sys.stderr) |
| 318 | traceback.print_exc() |
Alexander Kornienko | 16300e1 | 2017-07-21 10:31:26 +0000 | [diff] [blame] | 319 | return_code=1 |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 320 | |
Alexander Kornienko | 16300e1 | 2017-07-21 10:31:26 +0000 | [diff] [blame] | 321 | if tmpdir: |
Jakub Kuderski | a7410fd | 2017-04-25 22:38:39 +0000 | [diff] [blame] | 322 | shutil.rmtree(tmpdir) |
Alexander Kornienko | 16300e1 | 2017-07-21 10:31:26 +0000 | [diff] [blame] | 323 | sys.exit(return_code) |
Benjamin Kramer | a9d9a4d | 2014-09-08 14:01:31 +0000 | [diff] [blame] | 324 | |
| 325 | if __name__ == '__main__': |
| 326 | main() |