OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 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 |
| 6 """Compress and upload Mac toolchain files.""" |
| 7 |
| 8 import argparse |
| 9 import glob |
| 10 import os |
| 11 import plistlib |
| 12 import re |
| 13 import subprocess |
| 14 import sys |
| 15 import tarfile |
| 16 import tempfile |
| 17 |
| 18 |
| 19 TOOLCHAIN_URL = "gs://chrome-mac-sdk" |
| 20 # Remove too much and ibtool and other Xcode tools stop working. Removing |
| 21 # unused /Platforms save the most amount of space. |
| 22 EXCLUDE_FOLDERS = [ |
| 23 'Contents/Applications', |
| 24 'Contents/Developer/Documentation', |
| 25 'Contents/Developer/Platforms/AppleTVOS.platform', |
| 26 'Contents/Developer/Platforms/AppleTVSimulator.platform', |
| 27 'Contents/Developer/Platforms/WatchOS.platform', |
| 28 'Contents/Developer/Platforms/WatchSimulator.platform', |
| 29 'Contents/Developer/Platforms/iPhoneOS.platform', |
| 30 'Contents/Developer/Platforms/iPhoneSimulator.platform', |
| 31 'Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator', |
| 32 'Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift', |
| 33 'Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/' |
| 34 'usr/share/man', |
| 35 'Contents/Developer/Library/Xcode/Templates' |
| 36 ] |
| 37 |
| 38 |
| 39 def main(): |
| 40 parser = argparse.ArgumentParser() |
| 41 parser.add_argument('target_dir', |
| 42 help="Xcode installation directory.") |
| 43 parser.add_argument('args', nargs='*', help="run ibtool command") |
| 44 args = parser.parse_args() |
| 45 |
| 46 contents_dir = os.path.join(args.target_dir, 'Contents') |
| 47 plist_file = os.path.join(contents_dir, 'version.plist') |
| 48 try: |
| 49 info = plistlib.readPlist(plist_file) |
| 50 except: |
| 51 print "Invalid Xcode dir." |
| 52 return 0 |
| 53 build_version = info['ProductBuildVersion'] |
| 54 |
| 55 wildcard_filename = '%s/toolchain-%s-*.tgz' % (TOOLCHAIN_URL, build_version) |
| 56 p = subprocess.Popen(['gsutil.py', 'ls', wildcard_filename], |
| 57 stdout=subprocess.PIPE, |
| 58 stderr=subprocess.PIPE) |
| 59 |
| 60 output = p.communicate()[0] |
| 61 next_count = 1 |
| 62 if p.returncode == 0: |
| 63 next_count = len(output.split('\n')) |
| 64 sys.stdout.write("%s already exists (%s). " |
| 65 "Do you want to create another? [y/n] " |
| 66 % (build_version, next_count - 1)) |
| 67 |
| 68 if raw_input().lower() not in set(['yes','y', 'ye']): |
| 69 print "Skipping additional upload." |
| 70 return 0 |
| 71 |
| 72 os.chdir(args.target_dir) |
| 73 toolchain_file_name = "toolchain-%s-%s" % (build_version, next_count) |
| 74 toolchain_name = tempfile.mktemp(suffix='toolchain.tgz') |
| 75 print "Creating %s (%s)." % (toolchain_file_name, toolchain_name) |
| 76 os.environ["COPYFILE_DISABLE"] = "1" |
| 77 args = ['tar', '-cvzf', toolchain_name] |
| 78 args.extend(map('--exclude={0}'.format, EXCLUDE_FOLDERS)) |
| 79 args.extend(['.']) |
| 80 subprocess.check_call(args) |
| 81 |
| 82 print "Uploading %s toolchain." % toolchain_file_name |
| 83 destination_path = '%s/%s.tgz' % (TOOLCHAIN_URL, toolchain_file_name) |
| 84 subprocess.check_call(['gsutil.py', 'cp', '-n', '-a', 'public-read', |
| 85 toolchain_name, destination_path]) |
| 86 print "Done with %s upload." % toolchain_file_name |
| 87 return 0 |
| 88 |
| 89 if __name__ == '__main__': |
| 90 sys.exit(main()) |
OLD | NEW |