OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
scottmg
2016/03/21 20:42:20
No (c)
justincohen
2016/03/22 17:16:10
Done.
| |
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 | |
21 # It's important to at least remove unused Platform folders to cut down on the | |
22 # size of the toolchain folder. There are other various unused folders that | |
23 # have been removed through trial and error. If future versions of Xcode become | |
24 # problematic it's possible this list is incorrect, and can be reduced to just | |
25 # the unused platforms. On the flip side, it's likely more directories can be | |
26 # excluded. | |
27 EXCLUDE_FOLDERS = [ | |
28 'Contents/Applications', | |
29 'Contents/Developer/Documentation', | |
30 'Contents/Developer/Platforms/AppleTVOS.platform', | |
31 'Contents/Developer/Platforms/AppleTVSimulator.platform', | |
32 'Contents/Developer/Platforms/WatchOS.platform', | |
33 'Contents/Developer/Platforms/WatchSimulator.platform', | |
34 'Contents/Developer/Platforms/iPhoneOS.platform', | |
35 'Contents/Developer/Platforms/iPhoneSimulator.platform', | |
36 'Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator', | |
37 'Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift', | |
38 'Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/' | |
39 'usr/share/man', | |
40 'Contents/Developer/Library/Xcode/Templates' | |
41 ] | |
42 | |
43 | |
44 def main(): | |
45 """Compress |target_dir| and upload to |TOOLCHAIN_URL|""" | |
46 parser = argparse.ArgumentParser() | |
47 parser.add_argument('target_dir', | |
48 help="Xcode installation directory.") | |
49 parser.add_argument('args', nargs='*', help="run ibtool command") | |
scottmg
2016/03/21 20:42:21
This looks unused (and maybe has the wrong help= i
justincohen
2016/03/22 17:16:10
Done.
| |
50 args = parser.parse_args() | |
51 | |
52 # Verify this looks like an Xcode directory. | |
53 contents_dir = os.path.join(args.target_dir, 'Contents') | |
54 plist_file = os.path.join(contents_dir, 'version.plist') | |
55 try: | |
56 info = plistlib.readPlist(plist_file) | |
57 except: | |
58 print "Invalid Xcode dir." | |
59 return 0 | |
60 build_version = info['ProductBuildVersion'] | |
61 | |
62 # Look for previous toolchain tgz files with the same |build_version|. | |
63 wildcard_filename = '%s/toolchain-%s-*.tgz' % (TOOLCHAIN_URL, build_version) | |
64 p = subprocess.Popen(['gsutil.py', 'ls', wildcard_filename], | |
65 stdout=subprocess.PIPE, | |
66 stderr=subprocess.PIPE) | |
67 output = p.communicate()[0] | |
68 next_count = 1 | |
69 if p.returncode == 0: | |
70 next_count = len(output.split('\n')) | |
71 sys.stdout.write("%s already exists (%s). " | |
72 "Do you want to create another? [y/n] " | |
73 % (build_version, next_count - 1)) | |
74 | |
75 if raw_input().lower() not in set(['yes','y', 'ye']): | |
76 print "Skipping duplicate upload." | |
77 return 0 | |
78 | |
scottmg
2016/03/21 20:42:21
extra \n here
justincohen
2016/03/22 17:16:10
Done.
| |
79 | |
80 os.chdir(args.target_dir) | |
81 toolchain_file_name = "toolchain-%s-%s" % (build_version, next_count) | |
82 toolchain_name = tempfile.mktemp(suffix='toolchain.tgz') | |
83 | |
84 print "Creating %s (%s)." % (toolchain_file_name, toolchain_name) | |
85 os.environ["COPYFILE_DISABLE"] = "1" | |
86 args = ['tar', '-cvzf', toolchain_name] | |
87 args.extend(map('--exclude={0}'.format, EXCLUDE_FOLDERS)) | |
88 args.extend(['.']) | |
89 subprocess.check_call(args) | |
90 | |
91 print "Uploading %s toolchain." % toolchain_file_name | |
92 destination_path = '%s/%s.tgz' % (TOOLCHAIN_URL, toolchain_file_name) | |
93 subprocess.check_call(['gsutil.py', 'cp', '-n', '-a', 'public-read', | |
94 toolchain_name, destination_path]) | |
95 | |
96 print "Done with %s upload." % toolchain_file_name | |
97 return 0 | |
98 | |
99 if __name__ == '__main__': | |
100 sys.exit(main()) | |
OLD | NEW |