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