OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright 2017 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """ | |
7 Build and package CronetChromeWebView.framework | |
8 """ | |
9 | |
10 import argparse | |
11 import os | |
12 import shutil | |
13 import sys | |
14 | |
15 def target_dir_name(build_config, target_device): | |
16 """Creates a defult output directory name for the given build_config and | |
Eugene But (OOO till 7-30)
2017/06/16 03:37:18
This link has an example of comments than conform
michaeldo
2017/06/16 18:16:50
Thank you for the reference, updated function comm
| |
17 target_device""" | |
18 return '%s-iphone%s' % (build_config, target_device) | |
19 | |
20 def build(build_config, target_device, extra_gn_options): | |
21 """Generates and builds CronetChromeWebView.framework for the given | |
22 build_config and target_device""" | |
23 if target_device == 'os': | |
24 target_cpu = 'arm' | |
25 additional_cpu = 'arm64' | |
26 else: | |
27 target_cpu = 'x86' | |
28 additional_cpu = 'x64' | |
29 | |
30 if build_config == 'Debug': | |
31 gn_extra_args = 'is_debug=true' | |
Hiroshi Ichikawa
2017/06/16 07:41:59
Optional: This may be too confusing with extra_gn_
michaeldo
2017/06/16 18:16:50
I agree, I updated it to build_config_gn_args to b
| |
32 else: | |
33 gn_extra_args = 'is_debug=false enable_stripping=true' | |
34 | |
35 build_dir = os.path.join("out", target_dir_name(build_config, target_device)) | |
36 gn_args = 'target_os="ios" enable_websockets=false ' \ | |
Hiroshi Ichikawa
2017/06/16 07:41:59
It seems preferred to use parentheses than backsla
michaeldo
2017/06/16 18:16:50
Done.
| |
37 'is_component_build=false use_xcode_clang=false ' \ | |
38 'disable_file_support=true disable_ftp_support=true ' \ | |
39 'disable_brotli_filter=true ' \ | |
40 'target_cpu="%s" additional_target_cpus = ["%s"] %s %s' % \ | |
41 (target_cpu, additional_cpu, gn_extra_args, extra_gn_options) | |
42 | |
43 gn_command = 'gn gen %s --args=\'%s\'' % (build_dir, gn_args) | |
44 print gn_command | |
45 gn_result = os.system(gn_command) | |
46 if gn_result != 0: | |
47 return gn_result | |
48 | |
49 ninja_command = 'ninja -C %s ios/web_view:cronet_ios_web_view_package' % \ | |
Hiroshi Ichikawa
2017/06/16 07:41:59
Ditto.
michaeldo
2017/06/16 18:16:50
Done.
| |
50 build_dir | |
51 print ninja_command | |
52 return os.system(ninja_command) | |
53 | |
54 def copy_build_products(build_config, target_device, out_dir): | |
55 """Copies the resulting framework and symbols to out_dir""" | |
56 target_dir = target_dir_name(build_config, target_device) | |
57 build_dir = os.path.join("out", target_dir) | |
58 | |
59 # Copy framework. | |
60 framework_source = os.path.join(build_dir, 'CronetChromeWebView.framework') | |
61 framework_dest = os.path.join(out_dir, target_dir, | |
62 'CronetChromeWebView.framework') | |
63 print 'Copying %s to %s' % (framework_source, framework_dest) | |
64 shutil.copytree(framework_source, framework_dest) | |
65 | |
66 # Copy symbols. | |
67 symbols_source = os.path.join(build_dir, 'CronetChromeWebView.dSYM') | |
68 symbols_dest = os.path.join(out_dir, target_dir, 'CronetChromeWebView.dSYM') | |
69 print 'Copying %s to %s' % (symbols_source, symbols_dest) | |
70 shutil.copytree(symbols_source, symbols_dest) | |
71 | |
72 def package_framework(build_config, target_device, out_dir, extra_gn_options): | |
73 """Builds CronetChromeWebView.framework for the given build_config and | |
74 target_device and copies the result into out_dir""" | |
75 print '\nBuilding for %s (%s)' % (target_device, build_config) | |
76 | |
77 build_result = build(build_config, target_device, extra_gn_options) | |
78 if build_result != 0: | |
79 error = 'Building %s/%s failed with code: ' % (build_config, target_device) | |
80 print >>sys.stderr, error, build_result | |
81 return build_result | |
82 copy_build_products(build_config, target_device, out_dir) | |
83 return 0 | |
84 | |
85 def package_all_frameworks(out_dir, extra_gn_options): | |
86 """Builds Release and Debug versions of CronetChromeWebView.framework for both | |
87 iOS devices and simulator and copies the resulting frameworks into out_dir. | |
88 """ | |
89 print 'Building CronetChromeWebView.framework...' | |
90 | |
91 # Package all builds in the output directory | |
92 os.makedirs(out_dir) | |
93 | |
94 if package_framework('Debug', 'simulator', out_dir, extra_gn_options) != 0: | |
95 return 1 | |
96 if package_framework('Debug', 'os', out_dir, extra_gn_options) != 0: | |
97 return 1 | |
98 if package_framework('Release', 'simulator', out_dir, extra_gn_options) != 0: | |
99 return 1 | |
100 if package_framework('Release', 'os', out_dir, extra_gn_options) != 0: | |
101 return 1 | |
102 | |
103 # Copy common files from last built package to out_dir. | |
104 build_dir = os.path.join("out", target_dir_name('Release', 'os')) | |
105 package_dir = os.path.join(build_dir, 'cronet_ios_web_view') | |
106 shutil.copy2(os.path.join(package_dir, 'AUTHORS'), out_dir) | |
107 shutil.copy2(os.path.join(package_dir, 'LICENSE'), out_dir) | |
108 shutil.copy2(os.path.join(package_dir, 'VERSION'), out_dir) | |
109 | |
110 print '\nSuccess! CronetChromeWebView.framework is packaged into %s' % out_dir | |
111 | |
112 return 0 | |
113 | |
114 def main(): | |
115 description = "Build and package CronetChromeWebView.framework" | |
116 parser = argparse.ArgumentParser(description=description) | |
117 | |
118 parser.add_argument('out_dir', nargs='?', default='out/CronetChromeWebView', | |
119 help='path to output directory') | |
120 parser.add_argument('--no_goma', action='store_true', | |
121 help='Prevents adding use_goma=true to the gn args.') | |
122 | |
123 options, extra_options = parser.parse_known_args() | |
124 print options | |
Hiroshi Ichikawa
2017/06/16 07:41:59
Maybe prefix this output with "options: " or somet
michaeldo
2017/06/16 18:16:50
I added a comment before the options are printed.
| |
125 | |
126 if len(extra_options): | |
127 print >>sys.stderr, 'Unknown options: ', extra_options | |
128 return 1 | |
129 | |
130 out_dir = options.out_dir | |
131 # Make sure that the output directory does not exist | |
132 if os.path.exists(out_dir): | |
133 print >>sys.stderr, 'The output directory already exists: ' + out_dir | |
134 return 1 | |
135 | |
136 gn_options = 'use_goma=true' | |
Hiroshi Ichikawa
2017/06/16 07:41:59
Maybe cleaner to be one line?:
gn_options = '' i
michaeldo
2017/06/16 18:16:50
Done.
| |
137 if options.no_goma: | |
138 gn_options = '' | |
139 | |
140 return package_all_frameworks(out_dir, gn_options) | |
141 | |
142 | |
143 if __name__ == '__main__': | |
144 sys.exit(main()) | |
OLD | NEW |