Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / build / config / mac / mac_app.py
blob70c313a65e68cdead795dee9d62cdaa91db28864
1 # Copyright (c) 2015 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.
5 import argparse
6 import errno
7 import os
8 import subprocess
9 import sys
11 def MakeDirectories(path):
12 try:
13 os.makedirs(path)
14 except OSError as exc:
15 if exc.errno == errno.EEXIST and os.path.isdir(path):
16 return 0
17 else:
18 return -1
20 return 0
23 def ProcessInfoPlist(args):
24 output_plist_file = os.path.abspath(os.path.join(args.output, 'Info.plist'))
25 return subprocess.check_call([
26 '/usr/bin/env',
27 'xcrun',
28 'plutil'
29 '-convert',
30 'binary1',
31 '-o',
32 output_plist_file,
33 '--',
34 args.input,
38 def ProcessNIB(args):
39 output_nib_file = os.path.join(os.path.abspath(args.output),
40 "%s.nib" % os.path.splitext(os.path.basename(args.input))[0])
42 return subprocess.check_call([
43 '/usr/bin/env',
44 'xcrun',
45 'ibtool',
46 '--module',
47 args.module,
48 '--auto-activate-custom-fonts',
49 '--target-device',
50 'mac',
51 '--compile',
52 output_nib_file,
53 os.path.abspath(args.input),
57 def GenerateProjectStructure(args):
58 application_path = os.path.join( args.dir, args.name + ".app", "Contents" )
59 return MakeDirectories( application_path )
62 def main():
63 parser = argparse.ArgumentParser(description='A script that aids in '
64 'the creation of an Mac application')
66 subparsers = parser.add_subparsers()
68 # Plist Parser
69 plist_parser = subparsers.add_parser('plist',
70 help='Process the Info.plist')
71 plist_parser.set_defaults(func=ProcessInfoPlist)
73 plist_parser.add_argument('-i', dest='input', help='The input plist path')
74 plist_parser.add_argument('-o', dest='output', help='The output plist dir')
76 # NIB Parser
77 plist_parser = subparsers.add_parser('nib',
78 help='Process a NIB file')
79 plist_parser.set_defaults(func=ProcessNIB)
81 plist_parser.add_argument('-i', dest='input', help='The input nib path')
82 plist_parser.add_argument('-o', dest='output', help='The output nib dir')
83 plist_parser.add_argument('-m', dest='module', help='The module name')
85 # Directory Structure Parser
86 dir_struct_parser = subparsers.add_parser('structure',
87 help='Creates the directory of an Mac application')
89 dir_struct_parser.set_defaults(func=GenerateProjectStructure)
91 dir_struct_parser.add_argument('-d', dest='dir', help='Out directory')
92 dir_struct_parser.add_argument('-n', dest='name', help='App name')
94 args = parser.parse_args()
95 return args.func(args)
98 if __name__ == '__main__':
99 sys.exit(main())