Jim Van Verth | e784f75 | 2019-09-05 09:37:31 -0400 | [diff] [blame] | 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 | |
| 6 | import argparse |
| 7 | import os |
| 8 | import re |
| 9 | import subprocess |
| 10 | import sys |
| 11 | |
| 12 | |
| 13 | def main(): |
| 14 | parser = argparse.ArgumentParser( |
| 15 | description='A script to compile xib and storyboard.', |
| 16 | fromfile_prefix_chars='@') |
| 17 | parser.add_argument('-o', '--output', required=True, |
| 18 | help='Path to output bundle.') |
| 19 | parser.add_argument('-i', '--input', required=True, |
| 20 | help='Path to input xib or storyboard.') |
| 21 | parser.add_argument('--developer_dir', required=False, |
| 22 | help='Path to Xcode.') |
| 23 | args, unknown_args = parser.parse_known_args() |
| 24 | |
| 25 | if args.developer_dir: |
| 26 | os.environ['DEVELOPER_DIR'] = args.developer_dir |
| 27 | |
| 28 | ibtool_args = [ |
| 29 | 'xcrun', 'ibtool', |
| 30 | '--errors', '--warnings', '--notices', |
| 31 | '--output-format', 'human-readable-text' |
| 32 | ] |
| 33 | ibtool_args += unknown_args |
| 34 | ibtool_args += [ |
| 35 | '--compile', |
| 36 | os.path.abspath(args.output), |
| 37 | os.path.abspath(args.input) |
| 38 | ] |
| 39 | |
| 40 | ibtool_section_re = re.compile(r'/\*.*\*/') |
| 41 | ibtool_re = re.compile(r'.*note:.*is clipping its content') |
| 42 | try: |
| 43 | stdout = subprocess.check_output(ibtool_args) |
| 44 | except subprocess.CalledProcessError as e: |
| 45 | print(e.output) |
| 46 | raise |
| 47 | current_section_header = None |
| 48 | for line in stdout.splitlines(): |
| 49 | if ibtool_section_re.match(line): |
| 50 | current_section_header = line |
| 51 | elif not ibtool_re.match(line): |
| 52 | if current_section_header: |
| 53 | print(current_section_header) |
| 54 | current_section_header = None |
| 55 | print(line) |
| 56 | return 0 |
| 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |
| 60 | sys.exit(main()) |