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 Builds and packages 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 """Returns a default output directory name string. | |
17 | |
18 Args: | |
19 build_config: A string describing the build configuration. Ex: 'Debug' | |
20 target_device: A string describing the target device. Ex: 'simulator' | |
21 """ | |
22 return '%s-iphone%s' % (build_config, target_device) | |
23 | |
24 def build(build_config, target_device, extra_gn_options): | |
25 """Generates and builds CronetChromeWebView.framework. | |
26 | |
27 Args: | |
28 build_config: A string describing the build configuration. Ex: 'Debug' | |
29 target_device: A string describing the target device. Ex: 'simulator' | |
30 extra_gn_options: A string of gn args (space separated key=value items) to | |
31 be appended to the gn gen command. | |
32 | |
33 Returns: | |
34 The return code of generating ninja if it is non-zero, else the return code | |
35 of the ninja build command. | |
36 """ | |
37 if target_device == 'os': | |
38 target_cpu = 'arm' | |
39 additional_cpu = 'arm64' | |
40 else: | |
41 target_cpu = 'x86' | |
42 additional_cpu = 'x64' | |
43 | |
44 if build_config == 'Debug': | |
45 build_config_gn_args = 'is_debug=true' | |
46 else: | |
47 build_config_gn_args = 'is_debug=false enable_stripping=true' | |
48 | |
49 build_dir = os.path.join("out", target_dir_name(build_config, target_device)) | |
50 gn_args = ('target_os="ios" enable_websockets=false ' | |
51 'is_component_build=false use_xcode_clang=false ' | |
mef
2017/06/16 19:29:00
Is use_xcode_clang=false intentional?
We've switc
michaeldo
2017/06/16 20:12:29
In the default ios gn args setup, "use_xcode_clang
| |
52 'disable_file_support=true disable_ftp_support=true ' | |
53 'disable_brotli_filter=true ' | |
54 'target_cpu="%s" additional_target_cpus = ["%s"] %s %s' % | |
55 (target_cpu, additional_cpu, build_config_gn_args, | |
56 extra_gn_options)) | |
57 | |
58 gn_command = 'gn gen %s --args=\'%s\'' % (build_dir, gn_args) | |
59 print gn_command | |
60 gn_result = os.system(gn_command) | |
61 if gn_result != 0: | |
62 return gn_result | |
63 | |
64 ninja_command = ('ninja -C %s ios/web_view:cronet_ios_web_view_package' % | |
65 build_dir) | |
66 print ninja_command | |
67 return os.system(ninja_command) | |
68 | |
69 def copy_build_products(build_config, target_device, out_dir): | |
70 """Copies the resulting framework and symbols to out_dir. | |
71 | |
72 Args: | |
73 build_config: A string describing the build configuration. Ex: 'Debug' | |
74 target_device: A string describing the target device. Ex: 'simulator' | |
75 out_dir: A string to the path which all build products will be copied. | |
76 """ | |
77 target_dir = target_dir_name(build_config, target_device) | |
78 build_dir = os.path.join("out", target_dir) | |
79 | |
80 # Copy framework. | |
81 framework_source = os.path.join(build_dir, 'CronetChromeWebView.framework') | |
82 framework_dest = os.path.join(out_dir, target_dir, | |
83 'CronetChromeWebView.framework') | |
84 print 'Copying %s to %s' % (framework_source, framework_dest) | |
85 shutil.copytree(framework_source, framework_dest) | |
86 | |
87 # Copy symbols. | |
88 symbols_source = os.path.join(build_dir, 'CronetChromeWebView.dSYM') | |
89 symbols_dest = os.path.join(out_dir, target_dir, 'CronetChromeWebView.dSYM') | |
90 print 'Copying %s to %s' % (symbols_source, symbols_dest) | |
91 shutil.copytree(symbols_source, symbols_dest) | |
92 | |
93 def package_framework(build_config, target_device, out_dir, extra_gn_options): | |
94 """Builds CronetChromeWebView.framework and copies the result to out_dir. | |
95 | |
96 Args: | |
97 build_config: A string describing the build configuration. Ex: 'Debug' | |
98 target_device: A string describing the target device. Ex: 'simulator' | |
99 out_dir: A string to the path which all build products will be copied. | |
100 extra_gn_options: A string of gn args (space separated key=value items) to | |
101 be appended to the gn gen command. | |
102 | |
103 Returns: | |
104 The return code of the build if it fails or 0 if the build was successful. | |
105 """ | |
106 print '\nBuilding for %s (%s)' % (target_device, build_config) | |
107 | |
108 build_result = build(build_config, target_device, extra_gn_options) | |
109 if build_result != 0: | |
110 error = 'Building %s/%s failed with code: ' % (build_config, target_device) | |
111 print >>sys.stderr, error, build_result | |
112 return build_result | |
113 copy_build_products(build_config, target_device, out_dir) | |
114 return 0 | |
115 | |
116 def package_all_frameworks(out_dir, extra_gn_options): | |
117 """Builds CronetChromeWebView.framework. | |
118 | |
119 Builds Release and Debug versions of CronetChromeWebView.framework for both | |
120 iOS devices and simulator and copies the resulting frameworks into out_dir. | |
121 | |
122 Args: | |
123 out_dir: A string to the path which all build products will be copied. | |
124 extra_gn_options: A string of gn args (space separated key=value items) to | |
125 be appended to the gn gen command. | |
126 | |
127 Returns: | |
128 0 if all builds are successful or 1 if any build fails. | |
129 """ | |
130 print 'Building CronetChromeWebView.framework...' | |
131 | |
132 # Package all builds in the output directory | |
133 os.makedirs(out_dir) | |
134 | |
135 if package_framework('Debug', 'simulator', out_dir, extra_gn_options) != 0: | |
136 return 1 | |
137 if package_framework('Debug', 'os', out_dir, extra_gn_options) != 0: | |
138 return 1 | |
139 if package_framework('Release', 'simulator', out_dir, extra_gn_options) != 0: | |
140 return 1 | |
141 if package_framework('Release', 'os', out_dir, extra_gn_options) != 0: | |
142 return 1 | |
143 | |
144 # Copy common files from last built package to out_dir. | |
145 build_dir = os.path.join("out", target_dir_name('Release', 'os')) | |
146 package_dir = os.path.join(build_dir, 'cronet_ios_web_view') | |
147 shutil.copy2(os.path.join(package_dir, 'AUTHORS'), out_dir) | |
148 shutil.copy2(os.path.join(package_dir, 'LICENSE'), out_dir) | |
149 shutil.copy2(os.path.join(package_dir, 'VERSION'), out_dir) | |
150 | |
151 print '\nSuccess! CronetChromeWebView.framework is packaged into %s' % out_dir | |
152 | |
153 return 0 | |
154 | |
155 def main(): | |
156 description = "Build and package CronetChromeWebView.framework" | |
157 parser = argparse.ArgumentParser(description=description) | |
158 | |
159 parser.add_argument('out_dir', nargs='?', default='out/CronetChromeWebView', | |
160 help='path to output directory') | |
161 parser.add_argument('--no_goma', action='store_true', | |
162 help='Prevents adding use_goma=true to the gn args.') | |
163 | |
164 options, extra_options = parser.parse_known_args() | |
165 print 'Options:', options | |
166 | |
167 if len(extra_options): | |
168 print >>sys.stderr, 'Unknown options: ', extra_options | |
169 return 1 | |
170 | |
171 out_dir = options.out_dir | |
172 # Make sure that the output directory does not exist | |
173 if os.path.exists(out_dir): | |
174 print >>sys.stderr, 'The output directory already exists: ' + out_dir | |
175 return 1 | |
176 | |
177 gn_options = '' if options.no_goma else 'use_goma=true' | |
178 | |
179 return package_all_frameworks(out_dir, gn_options) | |
180 | |
181 | |
182 if __name__ == '__main__': | |
183 sys.exit(main()) | |
OLD | NEW |