Chromium Code Reviews| Index: ios/web_view/tools/build.py |
| diff --git a/ios/web_view/tools/build.py b/ios/web_view/tools/build.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..e438618ec694c0442efa67ff999b1c44112670d8 |
| --- /dev/null |
| +++ b/ios/web_view/tools/build.py |
| @@ -0,0 +1,144 @@ |
| +#!/usr/bin/python |
| +# Copyright 2017 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +""" |
| +Build and package CronetChromeWebView.framework |
| +""" |
| + |
| +import argparse |
| +import os |
| +import shutil |
| +import sys |
| + |
| +def target_dir_name(build_config, target_device): |
| + """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
|
| + target_device""" |
| + return '%s-iphone%s' % (build_config, target_device) |
| + |
| +def build(build_config, target_device, extra_gn_options): |
| + """Generates and builds CronetChromeWebView.framework for the given |
| + build_config and target_device""" |
| + if target_device == 'os': |
| + target_cpu = 'arm' |
| + additional_cpu = 'arm64' |
| + else: |
| + target_cpu = 'x86' |
| + additional_cpu = 'x64' |
| + |
| + if build_config == 'Debug': |
| + 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
|
| + else: |
| + gn_extra_args = 'is_debug=false enable_stripping=true' |
| + |
| + build_dir = os.path.join("out", target_dir_name(build_config, target_device)) |
| + 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.
|
| + 'is_component_build=false use_xcode_clang=false ' \ |
| + 'disable_file_support=true disable_ftp_support=true ' \ |
| + 'disable_brotli_filter=true ' \ |
| + 'target_cpu="%s" additional_target_cpus = ["%s"] %s %s' % \ |
| + (target_cpu, additional_cpu, gn_extra_args, extra_gn_options) |
| + |
| + gn_command = 'gn gen %s --args=\'%s\'' % (build_dir, gn_args) |
| + print gn_command |
| + gn_result = os.system(gn_command) |
| + if gn_result != 0: |
| + return gn_result |
| + |
| + 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.
|
| + build_dir |
| + print ninja_command |
| + return os.system(ninja_command) |
| + |
| +def copy_build_products(build_config, target_device, out_dir): |
| + """Copies the resulting framework and symbols to out_dir""" |
| + target_dir = target_dir_name(build_config, target_device) |
| + build_dir = os.path.join("out", target_dir) |
| + |
| + # Copy framework. |
| + framework_source = os.path.join(build_dir, 'CronetChromeWebView.framework') |
| + framework_dest = os.path.join(out_dir, target_dir, |
| + 'CronetChromeWebView.framework') |
| + print 'Copying %s to %s' % (framework_source, framework_dest) |
| + shutil.copytree(framework_source, framework_dest) |
| + |
| + # Copy symbols. |
| + symbols_source = os.path.join(build_dir, 'CronetChromeWebView.dSYM') |
| + symbols_dest = os.path.join(out_dir, target_dir, 'CronetChromeWebView.dSYM') |
| + print 'Copying %s to %s' % (symbols_source, symbols_dest) |
| + shutil.copytree(symbols_source, symbols_dest) |
| + |
| +def package_framework(build_config, target_device, out_dir, extra_gn_options): |
| + """Builds CronetChromeWebView.framework for the given build_config and |
| + target_device and copies the result into out_dir""" |
| + print '\nBuilding for %s (%s)' % (target_device, build_config) |
| + |
| + build_result = build(build_config, target_device, extra_gn_options) |
| + if build_result != 0: |
| + error = 'Building %s/%s failed with code: ' % (build_config, target_device) |
| + print >>sys.stderr, error, build_result |
| + return build_result |
| + copy_build_products(build_config, target_device, out_dir) |
| + return 0 |
| + |
| +def package_all_frameworks(out_dir, extra_gn_options): |
| + """Builds Release and Debug versions of CronetChromeWebView.framework for both |
| + iOS devices and simulator and copies the resulting frameworks into out_dir. |
| + """ |
| + print 'Building CronetChromeWebView.framework...' |
| + |
| + # Package all builds in the output directory |
| + os.makedirs(out_dir) |
| + |
| + if package_framework('Debug', 'simulator', out_dir, extra_gn_options) != 0: |
| + return 1 |
| + if package_framework('Debug', 'os', out_dir, extra_gn_options) != 0: |
| + return 1 |
| + if package_framework('Release', 'simulator', out_dir, extra_gn_options) != 0: |
| + return 1 |
| + if package_framework('Release', 'os', out_dir, extra_gn_options) != 0: |
| + return 1 |
| + |
| + # Copy common files from last built package to out_dir. |
| + build_dir = os.path.join("out", target_dir_name('Release', 'os')) |
| + package_dir = os.path.join(build_dir, 'cronet_ios_web_view') |
| + shutil.copy2(os.path.join(package_dir, 'AUTHORS'), out_dir) |
| + shutil.copy2(os.path.join(package_dir, 'LICENSE'), out_dir) |
| + shutil.copy2(os.path.join(package_dir, 'VERSION'), out_dir) |
| + |
| + print '\nSuccess! CronetChromeWebView.framework is packaged into %s' % out_dir |
| + |
| + return 0 |
| + |
| +def main(): |
| + description = "Build and package CronetChromeWebView.framework" |
| + parser = argparse.ArgumentParser(description=description) |
| + |
| + parser.add_argument('out_dir', nargs='?', default='out/CronetChromeWebView', |
| + help='path to output directory') |
| + parser.add_argument('--no_goma', action='store_true', |
| + help='Prevents adding use_goma=true to the gn args.') |
| + |
| + options, extra_options = parser.parse_known_args() |
| + 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.
|
| + |
| + if len(extra_options): |
| + print >>sys.stderr, 'Unknown options: ', extra_options |
| + return 1 |
| + |
| + out_dir = options.out_dir |
| + # Make sure that the output directory does not exist |
| + if os.path.exists(out_dir): |
| + print >>sys.stderr, 'The output directory already exists: ' + out_dir |
| + return 1 |
| + |
| + 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.
|
| + if options.no_goma: |
| + gn_options = '' |
| + |
| + return package_all_frameworks(out_dir, gn_options) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |