blob: ecdc4d73d813e1a35b627fd24007c71d196b31f6 [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
11import argparse
12import glob
13import os
14import plistlib
15import re
16import subprocess
17import sys
18import tarfile
19import tempfile
20
21
22TOOLCHAIN_URL = "gs://chrome-mac-sdk"
23
24# It's important to at least remove unused Platform folders to cut down on the
25# size of the toolchain folder. There are other various unused folders that
26# have been removed through trial and error. If future versions of Xcode become
27# problematic it's possible this list is incorrect, and can be reduced to just
28# the unused platforms. On the flip side, it's likely more directories can be
29# excluded.
justincohenaa615f072016-11-30 18:46:4130DEFAULT_EXCLUDE_FOLDERS = [
justincohen6a03a3d2016-03-26 21:44:3831'Contents/Applications',
32'Contents/Developer/Documentation',
justincohenaa615f072016-11-30 18:46:4133'Contents/Developer/Library/Xcode/Templates',
justincohen6a03a3d2016-03-26 21:44:3834'Contents/Developer/Platforms/AppleTVOS.platform',
35'Contents/Developer/Platforms/AppleTVSimulator.platform',
justincohenaa615f072016-11-30 18:46:4136'Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/'
37 'usr/share/man/',
justincohen6a03a3d2016-03-26 21:44:3838'Contents/Developer/Platforms/WatchOS.platform',
39'Contents/Developer/Platforms/WatchSimulator.platform',
justincohenaa615f072016-11-30 18:46:4140'Contents/Developer/Toolchains/Swift*',
justincohen6a03a3d2016-03-26 21:44:3841'Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift',
justincohenaa615f072016-11-30 18:46:4142'Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator',
43'Contents/Resources/Packages/MobileDevice.pkg',
44'Contents/SharedFrameworks/DNTDocumentationSupport.framework'
justincohen6a03a3d2016-03-26 21:44:3845]
46
justincohenaa615f072016-11-30 18:46:4147MAC_EXCLUDE_FOLDERS = [
justincohenccbbfa22017-02-13 20:51:4348# The only thing we need in iPhoneOS.platform on mac is:
49# \Developer\Library\Xcode\PrivatePlugins
50# \Info.Plist.
51# This is the cleanest way to get these.
52'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks',
53'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/GPUTools',
54'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/'
55 'GPUToolsPlatform',
56'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/'
57 'PrivateFrameworks',
58'Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr',
59'Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs',
60'Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport',
61'Contents/Developer/Platforms/iPhoneOS.platform/Library',
62'Contents/Developer/Platforms/iPhoneOS.platform/usr',
63
64# iPhoneSimulator has a similar requirement, but the bulk of the binary size is
65# in \Developer\SDKs, so only excluding that here.
justincohen62d09b762017-02-08 00:38:2066'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs',
justincohenaa615f072016-11-30 18:46:4167]
68
69IOS_EXCLUDE_FOLDERS = [
70'Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/'
71'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
72 'iPhoneSimulator.sdk/Applications/',
73'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
74 'iPhoneSimulator.sdk/System/Library/AccessibilityBundles/',
75'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
76 'iPhoneSimulator.sdk/System/Library/CoreServices/',
77'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
78 'iPhoneSimulator.sdk/System/Library/LinguisticData/',
79]
justincohen6a03a3d2016-03-26 21:44:3880
81def main():
82 """Compress |target_dir| and upload to |TOOLCHAIN_URL|"""
83 parser = argparse.ArgumentParser()
84 parser.add_argument('target_dir',
85 help="Xcode installation directory.")
justincohenaa615f072016-11-30 18:46:4186 parser.add_argument('platform', choices=['ios', 'mac'],
87 help="Target platform for bundle.")
88 parser_args = parser.parse_args()
justincohen6a03a3d2016-03-26 21:44:3889
90 # Verify this looks like an Xcode directory.
justincohenaa615f072016-11-30 18:46:4191 contents_dir = os.path.join(parser_args.target_dir, 'Contents')
justincohen6a03a3d2016-03-26 21:44:3892 plist_file = os.path.join(contents_dir, 'version.plist')
93 try:
94 info = plistlib.readPlist(plist_file)
95 except:
96 print "Invalid Xcode dir."
97 return 0
98 build_version = info['ProductBuildVersion']
99
100 # Look for previous toolchain tgz files with the same |build_version|.
justincohenaa615f072016-11-30 18:46:41101 fname = 'toolchain'
102 if parser_args.platform == 'ios':
103 fname = 'ios-' + fname
104 wildcard_filename = '%s/%s-%s-*.tgz' % (TOOLCHAIN_URL, fname, build_version)
justincohen6a03a3d2016-03-26 21:44:38105 p = subprocess.Popen(['gsutil.py', 'ls', wildcard_filename],
106 stdout=subprocess.PIPE,
107 stderr=subprocess.PIPE)
108 output = p.communicate()[0]
109 next_count = 1
110 if p.returncode == 0:
111 next_count = len(output.split('\n'))
112 sys.stdout.write("%s already exists (%s). "
113 "Do you want to create another? [y/n] "
114 % (build_version, next_count - 1))
115
116 if raw_input().lower() not in set(['yes','y', 'ye']):
117 print "Skipping duplicate upload."
118 return 0
119
justincohenaa615f072016-11-30 18:46:41120 os.chdir(parser_args.target_dir)
121 toolchain_file_name = "%s-%s-%s" % (fname, build_version, next_count)
justincohen6a03a3d2016-03-26 21:44:38122 toolchain_name = tempfile.mktemp(suffix='toolchain.tgz')
123
124 print "Creating %s (%s)." % (toolchain_file_name, toolchain_name)
125 os.environ["COPYFILE_DISABLE"] = "1"
justincohenaa615f072016-11-30 18:46:41126 os.environ["GZ_OPT"] = "-8"
justincohen6a03a3d2016-03-26 21:44:38127 args = ['tar', '-cvzf', toolchain_name]
justincohenaa615f072016-11-30 18:46:41128 exclude_folders = DEFAULT_EXCLUDE_FOLDERS
129 if parser_args.platform == 'mac':
130 exclude_folders += MAC_EXCLUDE_FOLDERS
131 else:
132 exclude_folders += IOS_EXCLUDE_FOLDERS
133 args.extend(map('--exclude={0}'.format, exclude_folders))
justincohen6a03a3d2016-03-26 21:44:38134 args.extend(['.'])
135 subprocess.check_call(args)
136
137 print "Uploading %s toolchain." % toolchain_file_name
138 destination_path = '%s/%s.tgz' % (TOOLCHAIN_URL, toolchain_file_name)
justincohena139a1562016-11-16 18:52:24139 subprocess.check_call(['gsutil.py', 'cp', '-n', toolchain_name,
140 destination_path])
justincohen6a03a3d2016-03-26 21:44:38141
142 print "Done with %s upload." % toolchain_file_name
143 return 0
144
145if __name__ == '__main__':
146 sys.exit(main())