xref: /aosp_15_r20/external/cronet/build/config/ios/compile_ib_files.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2016 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
6import argparse
7import logging
8import os
9import re
10import subprocess
11import sys
12
13
14def main():
15  parser = argparse.ArgumentParser(
16      description='A script to compile xib and storyboard.',
17      fromfile_prefix_chars='@')
18  parser.add_argument('-o', '--output', required=True,
19                      help='Path to output bundle.')
20  parser.add_argument('-i', '--input', required=True,
21                      help='Path to input xib or storyboard.')
22  args, unknown_args = parser.parse_known_args()
23
24  ibtool_args = [
25      'xcrun', 'ibtool',
26      '--errors', '--warnings', '--notices',
27      '--output-format', 'human-readable-text'
28  ]
29  ibtool_args += unknown_args
30  ibtool_args += [
31      '--compile',
32      os.path.abspath(args.output),
33      os.path.abspath(args.input)
34  ]
35
36  ibtool_section_re = re.compile(r'/\*.*\*/')
37  ibtool_re = re.compile(r'.*note:.*is clipping its content')
38  try:
39    stdout = subprocess.check_output(ibtool_args)
40  except subprocess.CalledProcessError as e:
41    print(e.output)
42    raise
43  current_section_header = None
44  for line in stdout.splitlines():
45    if ibtool_section_re.match(line):
46      current_section_header = line
47    elif not ibtool_re.match(line):
48      if current_section_header:
49        print(current_section_header)
50        current_section_header = None
51      print(line)
52  return 0
53
54
55if __name__ == '__main__':
56  sys.exit(main())
57