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 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 shutil.copytree(os.path.join('out', build_dir, 'Cronet.framework.dSYM'), | 76 shutil.copytree(os.path.join('out', build_dir, 'Cronet.framework.dSYM'), |
77 os.path.join(out_dir, build_dir, 'Cronet.framework.dSYM')) | 77 os.path.join(out_dir, build_dir, 'Cronet.framework.dSYM')) |
78 # Copy the version file | 78 # Copy the version file |
79 shutil.copy2('chrome/VERSION', out_dir) | 79 shutil.copy2('chrome/VERSION', out_dir) |
80 # Copy the headers | 80 # Copy the headers |
81 shutil.copytree(os.path.join(out_dir, build_dirs[0], | 81 shutil.copytree(os.path.join(out_dir, build_dirs[0], |
82 'Cronet.framework', 'Headers'), | 82 'Cronet.framework', 'Headers'), |
83 os.path.join(out_dir, 'Headers')) | 83 os.path.join(out_dir, 'Headers')) |
84 | 84 |
85 | 85 |
| 86 def package_ios_framework_using_gn(out_dir='out/Framework', extra_options=''): |
| 87 print 'Building Cronet Dynamic Framework using gn...' |
| 88 |
| 89 # Package all builds in the output directory |
| 90 os.makedirs(out_dir) |
| 91 build_dir = '' |
| 92 for (build_config, is_debug) in [('Debug', 'true'), |
| 93 ('Release', 'false')]: |
| 94 for (target_device, target_cpus) in [('simulator', ['x86', 'x64']), |
| 95 ('os', ['arm', 'arm64'])]: |
| 96 build_dirs = [] |
| 97 # Build every architecture separately until gn supports fat builds. |
| 98 for target_cpu in target_cpus: |
| 99 build_dir = 'out/cronet_%s_%s' % (build_config, target_cpu) |
| 100 build_dirs.append(build_dir) |
| 101 gn_args = 'target_os="ios" enable_websockets=false ' \ |
| 102 'disable_file_support=true disable_ftp_support=true ' \ |
| 103 'use_platform_icu_alternatives=true ' \ |
| 104 'disable_brotli_filter=true ' \ |
| 105 'target_cpu="%s" is_debug=%s' % (target_cpu, is_debug) |
| 106 |
| 107 print 'Generating Ninja ' + gn_args |
| 108 gn_result = run('gn gen %s --args=\'%s\'' % (build_dir, gn_args)) |
| 109 if gn_result != 0: |
| 110 return gn_result |
| 111 |
| 112 print 'Building ' + build_dir |
| 113 build_result = run('ninja -C %s cronet_package' % build_dir, |
| 114 extra_options) |
| 115 if build_result != 0: |
| 116 return build_result |
| 117 |
| 118 # Copy first framework. |
| 119 target_dir = '%s-iphone%s' % (build_config, target_device) |
| 120 shutil.copytree(os.path.join(build_dirs[0], 'Cronet.framework'), |
| 121 os.path.join(out_dir, target_dir, 'Cronet.framework')) |
| 122 # Lipo first and second cpu. |
| 123 lipo_result = run('lipo -create %s %s -output %s' % |
| 124 (os.path.join(build_dirs[0], 'Cronet.framework/Cronet'), |
| 125 os.path.join(build_dirs[1], 'Cronet.framework/Cronet'), |
| 126 os.path.join(out_dir, target_dir, 'Cronet.framework/Cronet'))) |
| 127 if lipo_result != 0: |
| 128 return lipo_result |
| 129 # Extract and strip symbols from release binaries. |
| 130 if 'Release' in build_config: |
| 131 run('dsymutil -o=%s -minimize %s' % |
| 132 (os.path.join(out_dir, target_dir, 'Cronet.framework.dSYM'), |
| 133 os.path.join(out_dir, target_dir, 'Cronet.framework/Cronet'))) |
| 134 run('strip -x %s' % |
| 135 os.path.join(out_dir, target_dir, 'Cronet.framework/Cronet')) |
| 136 |
| 137 # Copy common files from last built package. |
| 138 package_dir = os.path.join(build_dir, 'cronet') |
| 139 shutil.copy2(os.path.join(package_dir, 'AUTHORS'), out_dir) |
| 140 shutil.copy2(os.path.join(package_dir, 'LICENSE'), out_dir) |
| 141 shutil.copy2(os.path.join(package_dir, 'VERSION'), out_dir) |
| 142 # Copy the headers |
| 143 shutil.copytree(os.path.join(build_dir, |
| 144 'Cronet.framework', 'Headers'), |
| 145 os.path.join(out_dir, 'Headers')) |
| 146 print 'Cronet dynamic framework is packaged into %s' % out_dir |
| 147 |
| 148 |
86 def main(): | 149 def main(): |
87 parser = argparse.ArgumentParser() | 150 parser = argparse.ArgumentParser() |
88 parser.add_argument('out_dir', nargs=1, help='path to output directory') | 151 parser.add_argument('out_dir', nargs=1, help='path to output directory') |
89 parser.add_argument('-g', '--skip_gyp', action='store_true', | 152 parser.add_argument('-g', '--gn', action='store_true', |
90 help='skip gyp') | 153 help='build using gn') |
91 parser.add_argument('-d', '--debug', action='store_true', | 154 parser.add_argument('-d', '--debug', action='store_true', |
92 help='use release configuration') | 155 help='use release configuration') |
93 parser.add_argument('-r', '--release', action='store_true', | 156 parser.add_argument('-r', '--release', action='store_true', |
94 help='use release configuration') | 157 help='use release configuration') |
95 parser.add_argument('--framework', action='store_true', | 158 parser.add_argument('--framework', action='store_true', |
96 help='build Cronet dynamic framework') | 159 help='build Cronet dynamic framework') |
97 | 160 |
98 options, extra_options_list = parser.parse_known_args() | 161 options, extra_options_list = parser.parse_known_args() |
99 print options | 162 print options |
100 print extra_options_list | 163 print extra_options_list |
101 | 164 |
102 out_dir = options.out_dir[0] | 165 out_dir = options.out_dir[0] |
103 | 166 |
104 # Make sure that the output directory does not exist | 167 # Make sure that the output directory does not exist |
105 if os.path.exists(out_dir): | 168 if os.path.exists(out_dir): |
106 print >>sys.stderr, 'The output directory already exists: ' + out_dir | 169 print >>sys.stderr, 'The output directory already exists: ' + out_dir |
107 return 1 | 170 return 1 |
108 | 171 |
109 gyp_defines = 'GYP_DEFINES="OS=ios enable_websockets=0 '+ \ | 172 gyp_defines = 'GYP_DEFINES="OS=ios enable_websockets=0 '+ \ |
110 'disable_file_support=1 disable_ftp_support=1 '+ \ | 173 'disable_file_support=1 disable_ftp_support=1 '+ \ |
111 'enable_errorprone=1 use_platform_icu_alternatives=1 ' + \ | 174 'enable_errorprone=1 use_platform_icu_alternatives=1 ' + \ |
112 'disable_brotli_filter=1 chromium_ios_signing=0 ' + \ | 175 'disable_brotli_filter=1 chromium_ios_signing=0 ' + \ |
113 'target_subarch=both"' | 176 'target_subarch=both"' |
114 if not options.skip_gyp: | 177 if not options.gn: |
115 run (gyp_defines + ' gclient runhooks') | 178 run (gyp_defines + ' gclient runhooks') |
116 | 179 |
117 if options.framework: | 180 if options.framework: |
118 return package_ios_framework(out_dir, extra_options_list) | 181 return package_ios_framework(out_dir, extra_options_list) |
119 | 182 |
| 183 if options.gn: |
| 184 return package_ios_framework_using_gn(out_dir, extra_options_list) |
| 185 |
120 return package_ios(out_dir, "out/Release", "opt") or \ | 186 return package_ios(out_dir, "out/Release", "opt") or \ |
121 package_ios(out_dir, "out/Debug", "dbg") | 187 package_ios(out_dir, "out/Debug", "dbg") |
122 | 188 |
123 | 189 |
124 if __name__ == '__main__': | 190 if __name__ == '__main__': |
125 sys.exit(main()) | 191 sys.exit(main()) |
OLD | NEW |