blob: 2c03ef37e3cbd75dc08b5dd7a725698b818d1e6c [file] [log] [blame]
justincohen6a03a3d2016-03-26 21:44:381#!/usr/bin/env python
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
4# found in the LICENSE file.
5
justincohenaa615f072016-11-30 18:46:416"""Compress and upload Mac toolchain files.
7
8Stored in in https://pantheon.corp.google.com/storage/browser/chrome-mac-sdk/.
9"""
justincohen6a03a3d2016-03-26 21:44:3810
Raul Tambre9e24293b2019-05-12 06:11:0711from __future__ import print_function
12
justincohen6a03a3d2016-03-26 21:44:3813import argparse
14import glob
15import os
16import plistlib
17import re
18import subprocess
19import sys
20import tarfile
21import tempfile
22
23
24TOOLCHAIN_URL = "gs://chrome-mac-sdk"
25
26# It's important to at least remove unused Platform folders to cut down on the
27# size of the toolchain folder. There are other various unused folders that
28# have been removed through trial and error. If future versions of Xcode become
29# problematic it's possible this list is incorrect, and can be reduced to just
30# the unused platforms. On the flip side, it's likely more directories can be
31# excluded.
justincohenaa615f072016-11-30 18:46:4132DEFAULT_EXCLUDE_FOLDERS = [
justincohen6a03a3d2016-03-26 21:44:3833'Contents/Applications',
34'Contents/Developer/Documentation',
justincohenaa615f072016-11-30 18:46:4135'Contents/Developer/Library/Xcode/Templates',
justincohen6a03a3d2016-03-26 21:44:3836'Contents/Developer/Platforms/AppleTVOS.platform',
37'Contents/Developer/Platforms/AppleTVSimulator.platform',
justincohenaa615f072016-11-30 18:46:4138'Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/'
39 'usr/share/man/',
justincohen6a03a3d2016-03-26 21:44:3840'Contents/Developer/Platforms/WatchOS.platform',
41'Contents/Developer/Platforms/WatchSimulator.platform',
justincohenaa615f072016-11-30 18:46:4142'Contents/Developer/Toolchains/Swift*',
justincohen6a03a3d2016-03-26 21:44:3843'Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift',
justincohenaa615f072016-11-30 18:46:4144'Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator',
45'Contents/Resources/Packages/MobileDevice.pkg',
justincohen6a03a3d2016-03-26 21:44:3846]
47
justincohenaa615f072016-11-30 18:46:4148MAC_EXCLUDE_FOLDERS = [
justincohenccbbfa22017-02-13 20:51:4349# The only thing we need in iPhoneOS.platform on mac is:
50# \Developer\Library\Xcode\PrivatePlugins
51# \Info.Plist.
52# This is the cleanest way to get these.
53'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks',
54'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/GPUTools',
55'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/'
56 'GPUToolsPlatform',
57'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/'
58 'PrivateFrameworks',
59'Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr',
60'Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs',
61'Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport',
62'Contents/Developer/Platforms/iPhoneOS.platform/Library',
63'Contents/Developer/Platforms/iPhoneOS.platform/usr',
64
65# iPhoneSimulator has a similar requirement, but the bulk of the binary size is
66# in \Developer\SDKs, so only excluding that here.
justincohen62d09b762017-02-08 00:38:2067'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs',
justincohenaa615f072016-11-30 18:46:4168]
69
70IOS_EXCLUDE_FOLDERS = [
71'Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/'
72'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
73 'iPhoneSimulator.sdk/Applications/',
74'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
75 'iPhoneSimulator.sdk/System/Library/AccessibilityBundles/',
76'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
77 'iPhoneSimulator.sdk/System/Library/CoreServices/',
78'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
79 'iPhoneSimulator.sdk/System/Library/LinguisticData/',
80]
justincohen6a03a3d2016-03-26 21:44:3881
82def main():
83 """Compress |target_dir| and upload to |TOOLCHAIN_URL|"""
84 parser = argparse.ArgumentParser()
85 parser.add_argument('target_dir',
86 help="Xcode installation directory.")
justincohenaa615f072016-11-30 18:46:4187 parser.add_argument('platform', choices=['ios', 'mac'],
88 help="Target platform for bundle.")
89 parser_args = parser.parse_args()
justincohen6a03a3d2016-03-26 21:44:3890
91 # Verify this looks like an Xcode directory.
justincohenaa615f072016-11-30 18:46:4192 contents_dir = os.path.join(parser_args.target_dir, 'Contents')
justincohen6a03a3d2016-03-26 21:44:3893 plist_file = os.path.join(contents_dir, 'version.plist')
94 try:
95 info = plistlib.readPlist(plist_file)
96 except:
Raul Tambre9e24293b2019-05-12 06:11:0797 print("Invalid Xcode dir.")
justincohen6a03a3d2016-03-26 21:44:3898 return 0
99 build_version = info['ProductBuildVersion']
100
101 # Look for previous toolchain tgz files with the same |build_version|.
justincohenaa615f072016-11-30 18:46:41102 fname = 'toolchain'
103 if parser_args.platform == 'ios':
104 fname = 'ios-' + fname
105 wildcard_filename = '%s/%s-%s-*.tgz' % (TOOLCHAIN_URL, fname, build_version)
justincohen6a03a3d2016-03-26 21:44:38106 p = subprocess.Popen(['gsutil.py', 'ls', wildcard_filename],
107 stdout=subprocess.PIPE,
108 stderr=subprocess.PIPE)
109 output = p.communicate()[0]
110 next_count = 1
111 if p.returncode == 0:
112 next_count = len(output.split('\n'))
113 sys.stdout.write("%s already exists (%s). "
114 "Do you want to create another? [y/n] "
115 % (build_version, next_count - 1))
116
117 if raw_input().lower() not in set(['yes','y', 'ye']):
Raul Tambre9e24293b2019-05-12 06:11:07118 print("Skipping duplicate upload.")
justincohen6a03a3d2016-03-26 21:44:38119 return 0
120
justincohenaa615f072016-11-30 18:46:41121 os.chdir(parser_args.target_dir)
122 toolchain_file_name = "%s-%s-%s" % (fname, build_version, next_count)
justincohen6a03a3d2016-03-26 21:44:38123 toolchain_name = tempfile.mktemp(suffix='toolchain.tgz')
124
Raul Tambre9e24293b2019-05-12 06:11:07125 print("Creating %s (%s)." % (toolchain_file_name, toolchain_name))
justincohen6a03a3d2016-03-26 21:44:38126 os.environ["COPYFILE_DISABLE"] = "1"
justincohenaa615f072016-11-30 18:46:41127 os.environ["GZ_OPT"] = "-8"
justincohen6a03a3d2016-03-26 21:44:38128 args = ['tar', '-cvzf', toolchain_name]
justincohenaa615f072016-11-30 18:46:41129 exclude_folders = DEFAULT_EXCLUDE_FOLDERS
130 if parser_args.platform == 'mac':
131 exclude_folders += MAC_EXCLUDE_FOLDERS
132 else:
133 exclude_folders += IOS_EXCLUDE_FOLDERS
134 args.extend(map('--exclude={0}'.format, exclude_folders))
justincohen6a03a3d2016-03-26 21:44:38135 args.extend(['.'])
136 subprocess.check_call(args)
137
Raul Tambre9e24293b2019-05-12 06:11:07138 print("Uploading %s toolchain." % toolchain_file_name)
justincohen6a03a3d2016-03-26 21:44:38139 destination_path = '%s/%s.tgz' % (TOOLCHAIN_URL, toolchain_file_name)
justincohena139a1562016-11-16 18:52:24140 subprocess.check_call(['gsutil.py', 'cp', '-n', toolchain_name,
141 destination_path])
justincohen6a03a3d2016-03-26 21:44:38142
Raul Tambre9e24293b2019-05-12 06:11:07143 print("Done with %s upload." % toolchain_file_name)
justincohen6a03a3d2016-03-26 21:44:38144 return 0
145
146if __name__ == '__main__':
147 sys.exit(main())