OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 # Wrapper around class-dump to allow gn build to run the tool (as action |
| 6 # target can only run python scripts). Also filters the output to remove |
| 7 # all cxx_destruct lines that are not understood from class-dump output. |
| 8 |
| 9 import argparse |
| 10 import errno |
| 11 import os |
| 12 import subprocess |
| 13 import sys |
| 14 |
| 15 |
| 16 def Main(args): |
| 17 parser = argparse.ArgumentParser('wrapper around class-dump') |
| 18 parser.add_argument( |
| 19 '-o', '--output', required=True, |
| 20 help='name of the output file') |
| 21 parser.add_argument( |
| 22 '-t', '--class-dump-path', required=True, |
| 23 help='path to class-dump executable') |
| 24 parser.add_argument( |
| 25 'args', nargs='*', |
| 26 help='arguments to pass to class-dump') |
| 27 args = parser.parse_args(args) |
| 28 |
| 29 try: |
| 30 os.makedirs(os.path.dirname(args.output)) |
| 31 except OSError, e: |
| 32 if e.errno != errno.EEXIST: |
| 33 raise |
| 34 |
| 35 process = subprocess.Popen( |
| 36 [args.class_dump_path] + args.args, |
| 37 stdout=subprocess.PIPE, |
| 38 stderr=subprocess.PIPE) |
| 39 stdout, stderr = process.communicate() |
| 40 if process.returncode != 0: |
| 41 sys.stderr.write(stderr) |
| 42 sys.exit(process.returncode) |
| 43 |
| 44 with open(args.output, 'wb') as output: |
| 45 output.write("// Treat class-dump output as a system header.\n") |
| 46 output.write("#pragma clang system_header\n") |
| 47 for line in stdout.splitlines(): |
| 48 if 'cxx_destruct' in line: |
| 49 continue |
| 50 output.write(line) |
| 51 output.write('\n') |
| 52 |
| 53 |
| 54 if __name__ == '__main__': |
| 55 Main(sys.argv[1:]) |
OLD | NEW |