| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 package_ios.py - Build and Package Release and Rebug fat libraries for iOS. | 7 package_ios.py - Build and Package Release and Rebug fat libraries for iOS. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import argparse | 10 import argparse |
| 11 import os | 11 import os |
| 12 import shutil | 12 import shutil |
| 13 import sys | 13 import sys |
| 14 | 14 |
| 15 def run(command, extra_options=''): | 15 def run(command, extra_options=''): |
| 16 command = command + ' ' + extra_options | 16 command = command + ' ' + ' '.join(extra_options) |
| 17 print command | 17 print command |
| 18 return os.system(command) | 18 return os.system(command) |
| 19 | 19 |
| 20 | 20 |
| 21 def build(out_dir, test_target, extra_options=''): | 21 def build(out_dir, test_target, extra_options=''): |
| 22 return run('ninja -C ' + out_dir + ' ' + test_target, | 22 return run('ninja -C ' + out_dir + ' ' + test_target, |
| 23 extra_options) | 23 extra_options) |
| 24 | 24 |
| 25 | 25 |
| 26 def lipo_libraries(out_dir, input_dirs, out_lib, input_lib): | 26 def lipo_libraries(out_dir, input_dirs, out_lib, input_lib): |
| 27 lipo = "lipo -create " | 27 lipo = "lipo -create " |
| 28 for input_dir in input_dirs: | 28 for input_dir in input_dirs: |
| 29 lipo += input_dir + "/" + input_lib + " " | 29 lipo += input_dir + "/" + input_lib + " " |
| 30 lipo += '-output ' + out_dir + "/" + out_lib | 30 lipo += '-output ' + out_dir + "/" + out_lib |
| 31 return run(lipo) | 31 return run(lipo) |
| 32 | 32 |
| 33 | 33 |
| 34 def copy_build_dir(target_dir, build_dir): | 34 def copy_build_dir(target_dir, build_dir): |
| 35 try: | 35 try: |
| 36 shutil.copytree(build_dir, target_dir, ignore=shutil.ignore_patterns('*.a')) | 36 shutil.copytree(build_dir, target_dir, ignore=shutil.ignore_patterns('*.a')) |
| 37 except OSError as e: | 37 except OSError as e: |
| 38 print('Directory not copied. Error: %s' % e) | 38 print('Directory not copied. Error: %s' % e) |
| 39 return 0 | 39 return 0 |
| 40 | 40 |
| 41 |
| 41 def package_ios(out_dir, build_dir, build_config): | 42 def package_ios(out_dir, build_dir, build_config): |
| 42 build_dir_sim = build_dir | 43 build_dir_sim = build_dir |
| 43 build_dir_dev = build_dir +'-iphoneos' | 44 build_dir_dev = build_dir +'-iphoneos' |
| 44 build_target = 'cronet_package' | 45 build_target = 'cronet_package' |
| 45 target_dir = out_dir + "/Cronet" | 46 target_dir = out_dir + "/Cronet" |
| 46 return build(build_dir_sim, build_target) or \ | 47 return build(build_dir_sim, build_target) or \ |
| 47 build(build_dir_dev, build_target) or \ | 48 build(build_dir_dev, build_target) or \ |
| 48 copy_build_dir(target_dir, build_dir_dev + "/cronet") or \ | 49 copy_build_dir(target_dir, build_dir_dev + "/cronet") or \ |
| 49 lipo_libraries(target_dir, [build_dir_sim, build_dir_dev], \ | 50 lipo_libraries(target_dir, [build_dir_sim, build_dir_dev], \ |
| 50 "libcronet_" + build_config + ".a", \ | 51 "libcronet_" + build_config + ".a", \ |
| 51 "cronet/libcronet_standalone.a") | 52 "cronet/libcronet_standalone.a") |
| 52 | 53 |
| 53 | 54 |
| 55 def package_ios_framework(out_dir='out/Framework', extra_options=''): |
| 56 print 'Building Cronet Dynamic Framework...' |
| 57 |
| 58 # Use Ninja to build all possible combinations. |
| 59 build_dirs = ['Debug-iphonesimulator', |
| 60 'Debug-iphoneos', |
| 61 'Release-iphonesimulator', |
| 62 'Release-iphoneos'] |
| 63 for build_dir in build_dirs: |
| 64 print 'Building ' + build_dir |
| 65 build_result = run('ninja -C out/' + build_dir + ' cronet_framework', |
| 66 extra_options) |
| 67 if build_result != 0: |
| 68 return build_result |
| 69 |
| 70 # Package all builds in the output directory |
| 71 os.makedirs(out_dir) |
| 72 for build_dir in build_dirs: |
| 73 shutil.copytree(os.path.join('out', build_dir, 'Cronet.framework'), |
| 74 os.path.join(out_dir, build_dir, 'Cronet.framework')) |
| 75 if 'Release' in build_dir: |
| 76 shutil.copytree(os.path.join('out', build_dir, 'Cronet.framework.dSYM'), |
| 77 os.path.join(out_dir, build_dir, 'Cronet.framework.dSYM')) |
| 78 |
| 79 |
| 54 def main(): | 80 def main(): |
| 55 parser = argparse.ArgumentParser() | 81 parser = argparse.ArgumentParser() |
| 56 parser.add_argument('out_dir', nargs=1, help='path to output directory') | 82 parser.add_argument('out_dir', nargs=1, help='path to output directory') |
| 57 parser.add_argument('-g', '--skip_gyp', action='store_true', | 83 parser.add_argument('-g', '--skip_gyp', action='store_true', |
| 58 help='skip gyp') | 84 help='skip gyp') |
| 59 parser.add_argument('-d', '--debug', action='store_true', | 85 parser.add_argument('-d', '--debug', action='store_true', |
| 60 help='use release configuration') | 86 help='use release configuration') |
| 61 parser.add_argument('-r', '--release', action='store_true', | 87 parser.add_argument('-r', '--release', action='store_true', |
| 62 help='use release configuration') | 88 help='use release configuration') |
| 89 parser.add_argument('--framework', action='store_true', |
| 90 help='build Cronet dynamic framework') |
| 63 | 91 |
| 64 options, extra_options_list = parser.parse_known_args() | 92 options, extra_options_list = parser.parse_known_args() |
| 65 print options | 93 print options |
| 66 print extra_options_list | 94 print extra_options_list |
| 67 | 95 |
| 96 out_dir = options.out_dir[0] |
| 97 |
| 98 # Make sure that the output directory does not exist |
| 99 if os.path.exists(out_dir): |
| 100 print >>sys.stderr, 'The output directory already exists: ' + out_dir |
| 101 return 1 |
| 102 |
| 68 gyp_defines = 'GYP_DEFINES="OS=ios enable_websockets=0 '+ \ | 103 gyp_defines = 'GYP_DEFINES="OS=ios enable_websockets=0 '+ \ |
| 69 'disable_file_support=1 disable_ftp_support=1 '+ \ | 104 'disable_file_support=1 disable_ftp_support=1 '+ \ |
| 70 'enable_errorprone=1 use_platform_icu_alternatives=1 ' + \ | 105 'enable_errorprone=1 use_platform_icu_alternatives=1 ' + \ |
| 71 'disable_brotli_filter=1 target_subarch=both"' | 106 'disable_brotli_filter=1 chromium_ios_signing=0 ' + \ |
| 107 'target_subarch=both"' |
| 72 if not options.skip_gyp: | 108 if not options.skip_gyp: |
| 73 run (gyp_defines + ' gclient runhooks') | 109 run (gyp_defines + ' gclient runhooks') |
| 74 | 110 |
| 75 return package_ios(options.out_dir[0], "out/Release", "opt") or \ | 111 if options.framework: |
| 76 package_ios(options.out_dir[0], "out/Debug", "dbg") | 112 return package_ios_framework(out_dir, extra_options_list) |
| 113 |
| 114 return package_ios(out_dir, "out/Release", "opt") or \ |
| 115 package_ios(out_dir, "out/Debug", "dbg") |
| 77 | 116 |
| 78 | 117 |
| 79 if __name__ == '__main__': | 118 if __name__ == '__main__': |
| 80 sys.exit(main()) | 119 sys.exit(main()) |
| OLD | NEW |