blob: 48672bb49a209aea8720a8f77c7b817a45fc82ba [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',
justincohen6a03a3d2016-03-26 21:44:3844]
45
justincohenaa615f072016-11-30 18:46:4146MAC_EXCLUDE_FOLDERS = [
justincohenccbbfa22017-02-13 20:51:4347# The only thing we need in iPhoneOS.platform on mac is:
48# \Developer\Library\Xcode\PrivatePlugins
49# \Info.Plist.
50# This is the cleanest way to get these.
51'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks',
52'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/GPUTools',
53'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/'
54 'GPUToolsPlatform',
55'Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/'
56 'PrivateFrameworks',
57'Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr',
58'Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs',
59'Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport',
60'Contents/Developer/Platforms/iPhoneOS.platform/Library',
61'Contents/Developer/Platforms/iPhoneOS.platform/usr',
62
63# iPhoneSimulator has a similar requirement, but the bulk of the binary size is
64# in \Developer\SDKs, so only excluding that here.
justincohen62d09b762017-02-08 00:38:2065'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs',
justincohenaa615f072016-11-30 18:46:4166]
67
68IOS_EXCLUDE_FOLDERS = [
69'Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/'
70'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
71 'iPhoneSimulator.sdk/Applications/',
72'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
73 'iPhoneSimulator.sdk/System/Library/AccessibilityBundles/',
74'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
75 'iPhoneSimulator.sdk/System/Library/CoreServices/',
76'Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'
77 'iPhoneSimulator.sdk/System/Library/LinguisticData/',
78]
justincohen6a03a3d2016-03-26 21:44:3879
80def main():
81 """Compress |target_dir| and upload to |TOOLCHAIN_URL|"""
82 parser = argparse.ArgumentParser()
83 parser.add_argument('target_dir',
84 help="Xcode installation directory.")
justincohenaa615f072016-11-30 18:46:4185 parser.add_argument('platform', choices=['ios', 'mac'],
86 help="Target platform for bundle.")
87 parser_args = parser.parse_args()
justincohen6a03a3d2016-03-26 21:44:3888
89 # Verify this looks like an Xcode directory.
justincohenaa615f072016-11-30 18:46:4190 contents_dir = os.path.join(parser_args.target_dir, 'Contents')
justincohen6a03a3d2016-03-26 21:44:3891 plist_file = os.path.join(contents_dir, 'version.plist')
92 try:
93 info = plistlib.readPlist(plist_file)
94 except:
95 print "Invalid Xcode dir."
96 return 0
97 build_version = info['ProductBuildVersion']
98
99 # Look for previous toolchain tgz files with the same |build_version|.
justincohenaa615f072016-11-30 18:46:41100 fname = 'toolchain'
101 if parser_args.platform == 'ios':
102 fname = 'ios-' + fname
103 wildcard_filename = '%s/%s-%s-*.tgz' % (TOOLCHAIN_URL, fname, build_version)
justincohen6a03a3d2016-03-26 21:44:38104 p = subprocess.Popen(['gsutil.py', 'ls', wildcard_filename],
105 stdout=subprocess.PIPE,
106 stderr=subprocess.PIPE)
107 output = p.communicate()[0]
108 next_count = 1
109 if p.returncode == 0:
110 next_count = len(output.split('\n'))
111 sys.stdout.write("%s already exists (%s). "
112 "Do you want to create another? [y/n] "
113 % (build_version, next_count - 1))
114
115 if raw_input().lower() not in set(['yes','y', 'ye']):
116 print "Skipping duplicate upload."
117 return 0
118
justincohenaa615f072016-11-30 18:46:41119 os.chdir(parser_args.target_dir)
120 toolchain_file_name = "%s-%s-%s" % (fname, build_version, next_count)
justincohen6a03a3d2016-03-26 21:44:38121 toolchain_name = tempfile.mktemp(suffix='toolchain.tgz')
122
123 print "Creating %s (%s)." % (toolchain_file_name, toolchain_name)
124 os.environ["COPYFILE_DISABLE"] = "1"
justincohenaa615f072016-11-30 18:46:41125 os.environ["GZ_OPT"] = "-8"
justincohen6a03a3d2016-03-26 21:44:38126 args = ['tar', '-cvzf', toolchain_name]
justincohenaa615f072016-11-30 18:46:41127 exclude_folders = DEFAULT_EXCLUDE_FOLDERS
128 if parser_args.platform == 'mac':
129 exclude_folders += MAC_EXCLUDE_FOLDERS
130 else:
131 exclude_folders += IOS_EXCLUDE_FOLDERS
132 args.extend(map('--exclude={0}'.format, exclude_folders))
justincohen6a03a3d2016-03-26 21:44:38133 args.extend(['.'])
134 subprocess.check_call(args)
135
136 print "Uploading %s toolchain." % toolchain_file_name
137 destination_path = '%s/%s.tgz' % (TOOLCHAIN_URL, toolchain_file_name)
justincohena139a1562016-11-16 18:52:24138 subprocess.check_call(['gsutil.py', 'cp', '-n', toolchain_name,
139 destination_path])
justincohen6a03a3d2016-03-26 21:44:38140
141 print "Done with %s upload." % toolchain_file_name
142 return 0
143
144if __name__ == '__main__':
145 sys.exit(main())