Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: build/mac_toolchain.py

Issue 1759793003: Scripts to upload and update the mac toolchain. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change data file name Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « DEPS ('k') | build/package_mac_toolchain.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2012 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 """This script is used to download necessary mac toolchain files."""
7
8 import os
9 import shutil
10 import subprocess
11 import sys
12 import tarfile
13 import time
14 import tempfile
15 import urllib2
16
17 # Update sys.path to import gyp.
18 script_dir = os.path.dirname(os.path.realpath(__file__))
19 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
20 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
21 import gyp
22
23 TOOLCHAIN_REVISION = '7C68'
24 TOOLCHAIN_SUB_REVISION = 1
25 TOOLCHAIN_VERSION = "%s-%s" % (TOOLCHAIN_REVISION, TOOLCHAIN_SUB_REVISION)
26
27 BASE_DIR = os.path.abspath(os.path.dirname(__file__))
28 TOOLCHAIN_BUILD_DIR = os.path.join(BASE_DIR, 'mac_files', 'Xcode.app')
29 STAMP_FILE = os.path.join(BASE_DIR, 'mac_files', 'toolchain_build_revision')
30 TOOLCHAIN_URL = 'gs://chrome-mac-sdk/'
31
32 def ReadStampFile():
33 """Return the contents of the stamp file, or '' if it doesn't exist."""
34 try:
35 with open(STAMP_FILE, 'r') as f:
36 return f.read().rstrip()
37 except IOError:
38 return ''
39
40
41 def WriteStampFile(s):
42 """Write s to the stamp file."""
43 EnsureDirExists(os.path.dirname(STAMP_FILE))
44 with open(STAMP_FILE, 'w') as f:
45 f.write(s)
46 f.write('\n')
47
48
49 def EnsureDirExists(path):
50 if not os.path.exists(path):
51 os.makedirs(path)
52
53
54 def DownloadAndUnpack(url, output_dir):
55 temp_name = tempfile.mktemp(prefix='mac_toolchain')
56 print 'Downloading new toolchain.'
57 subprocess.check_call(['gsutil.py', 'cp', url, temp_name])
58 if os.path.exists(output_dir):
59 print 'Deleting old toolchain.'
60 shutil.rmtree(output_dir)
61 EnsureDirExists(output_dir)
62 print 'Unpacking new toolchain.'
63 tarfile.open(mode='r:gz', name=temp_name).extractall(path=output_dir)
64 os.unlink(temp_name)
65
66
67 def CanAccessToolchainBucket():
68 """Checks whether the user has access to |TOOLCHAIN_URL|."""
69 proc = subprocess.Popen(['gsutil.py', 'ls', TOOLCHAIN_URL],
70 stdout=subprocess.PIPE)
71 proc.communicate()
72 return proc.returncode == 0
73
74
75 def SwitchToolchain(directory):
76 print 'Setting xcode-select to %s.' % directory
77 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', directory])
78 subprocess.check_call(['sudo', '/usr/bin/xcodebuild', '-license', 'accept'])
79
80
81 def main():
82 gyp_defines = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
83 force_pull = 'force_mac_toolchain' in gyp_defines
84 toolchain_revision = gyp_defines.get('mac_toolchain_revision',
85 TOOLCHAIN_VERSION)
86
87 proc = subprocess.Popen(['xcode-select', '-p'], stdout=subprocess.PIPE)
88 xcode_select_dir = proc.communicate()[0]
89 rc = proc.returncode
90 if not force_pull and rc == 0 and TOOLCHAIN_BUILD_DIR not in xcode_select_dir:
91 print 'Using local toolchain.'
92 return 0
93
94 if ReadStampFile() == toolchain_revision:
95 print 'Toolchain (%s) is already up to date.' % toolchain_revision
96 SwitchToolchain(TOOLCHAIN_BUILD_DIR)
erikchen 2016/03/03 22:43:12 if the toolchain is already up to date, why do we
97 return 0
98
99 if not CanAccessToolchainBucket():
100 print 'Cannot access toolchain bucket.'
101 return 0
102
103 # Reset the stamp file in case the build is unsuccessful.
104 WriteStampFile('')
105
106 toolchain_file = "%s.tgz" % toolchain_revision
107 toolchain_full_url = TOOLCHAIN_URL + toolchain_file
108
109 print 'Updating toolchain to %s...' % toolchain_revision
110 try:
111 toolchain_file = "toolchain-%s.tgz" % toolchain_revision
112 toolchain_full_url = TOOLCHAIN_URL + toolchain_file
113 DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR)
114 SwitchToolchain(TOOLCHAIN_BUILD_DIR)
115
116 print 'Toolchain %s unpacked.' % toolchain_revision
117 WriteStampFile(toolchain_revision)
118
119 return 0
120 except:
121 print 'Failed to download toolchain %s.' % toolchain_file
122 print 'Exiting.'
123 return 1
124
125 if __name__ == '__main__':
126 sys.exit(main())
OLDNEW
« no previous file with comments | « DEPS ('k') | build/package_mac_toolchain.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698