OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ | 6 """ |
7 If should_use_hermetic_xcode.py emits "1", and the current toolchain is out of | 7 If should_use_hermetic_xcode.py emits "1", and the current toolchain is out of |
8 date: | 8 date: |
9 * Downloads the hermetic mac toolchain | 9 * Downloads the hermetic mac toolchain |
10 * Requires gsutil to be configured. | 10 * Requires gsutil to be configured. |
11 * Accepts the license. | 11 * Accepts the license. |
12 * If xcode-select and xcodebuild are not passwordless in sudoers, requires | 12 * If xcode-select and xcodebuild are not passwordless in sudoers, requires |
13 user interaction. | 13 user interaction. |
14 """ | 14 """ |
15 | 15 |
16 import os | 16 import os |
17 import plistlib | 17 import plistlib |
18 import shutil | 18 import shutil |
19 import subprocess | 19 import subprocess |
20 import sys | 20 import sys |
21 import tarfile | 21 import tarfile |
22 import time | 22 import time |
23 import tempfile | 23 import tempfile |
24 import urllib2 | 24 import urllib2 |
25 | 25 |
26 # This can be changed after running /build/package_mac_toolchain.py. | 26 # This can be changed after running /build/package_mac_toolchain.py. |
27 TOOLCHAIN_REVISION = '5B1008' | 27 MAC_TOOLCHAIN_VERSION = '5B1008' |
28 TOOLCHAIN_SUB_REVISION = 3 | 28 MAC_TOOLCHAIN_SUB_REVISION = 3 |
29 TOOLCHAIN_VERSION = '%s-%s' % (TOOLCHAIN_REVISION, TOOLCHAIN_SUB_REVISION) | 29 MAC_TOOLCHAIN_VERSION = '%s-%s' % (MAC_TOOLCHAIN_VERSION, |
| 30 MAC_TOOLCHAIN_SUB_REVISION) |
| 31 IOS_TOOLCHAIN_VERSION = '8B62' |
| 32 IOS_TOOLCHAIN_SUB_REVISION = 1 |
| 33 IOS_TOOLCHAIN_VERSION = '%s-%s' % (IOS_TOOLCHAIN_VERSION, |
| 34 IOS_TOOLCHAIN_SUB_REVISION) |
| 35 |
| 36 # Absolute path to src/ directory. |
| 37 REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 38 |
| 39 # Absolute path to a file with gclient solutions. |
| 40 GCLIENT_CONFIG = os.path.join(os.path.dirname(REPO_ROOT), '.gclient') |
30 | 41 |
31 BASE_DIR = os.path.abspath(os.path.dirname(__file__)) | 42 BASE_DIR = os.path.abspath(os.path.dirname(__file__)) |
32 TOOLCHAIN_BUILD_DIR = os.path.join(BASE_DIR, 'mac_files', 'Xcode.app') | 43 TOOLCHAIN_BUILD_DIR = os.path.join(BASE_DIR, 'mac_files', 'Xcode.app') |
33 STAMP_FILE = os.path.join(BASE_DIR, 'mac_files', 'toolchain_build_revision') | 44 STAMP_FILE = os.path.join(BASE_DIR, 'mac_files', 'toolchain_build_revision') |
34 TOOLCHAIN_URL = 'gs://chrome-mac-sdk/' | 45 TOOLCHAIN_URL = 'gs://chrome-mac-sdk/' |
35 | 46 |
| 47 def IsIOSPlatform(): |
| 48 try: |
| 49 env = {} |
| 50 execfile(GCLIENT_CONFIG, env, env) |
| 51 if 'ios' in env.get('target_os', []): |
| 52 return True |
| 53 except: |
| 54 pass |
| 55 return False |
| 56 |
36 | 57 |
37 def ReadStampFile(): | 58 def ReadStampFile(): |
38 """Return the contents of the stamp file, or '' if it doesn't exist.""" | 59 """Return the contents of the stamp file, or '' if it doesn't exist.""" |
39 try: | 60 try: |
40 with open(STAMP_FILE, 'r') as f: | 61 with open(STAMP_FILE, 'r') as f: |
41 return f.read().rstrip() | 62 return f.read().rstrip() |
42 except IOError: | 63 except IOError: |
43 return '' | 64 return '' |
44 | 65 |
45 | 66 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 186 |
166 | 187 |
167 def main(): | 188 def main(): |
168 if sys.platform != 'darwin': | 189 if sys.platform != 'darwin': |
169 return 0 | 190 return 0 |
170 | 191 |
171 if not _UseHermeticToolchain(): | 192 if not _UseHermeticToolchain(): |
172 print 'Using local toolchain.' | 193 print 'Using local toolchain.' |
173 return 0 | 194 return 0 |
174 | 195 |
175 toolchain_revision = os.environ.get('MAC_TOOLCHAIN_REVISION', | 196 if IsIOSPlatform(): |
176 TOOLCHAIN_VERSION) | 197 default_version = IOS_TOOLCHAIN_VERSION |
177 if ReadStampFile() == toolchain_revision: | 198 toolchain_filename = 'ios-toolchain-%s.tgz' |
178 print 'Toolchain (%s) is already up to date.' % toolchain_revision | 199 else: |
| 200 default_version = MAC_TOOLCHAIN_VERSION |
| 201 toolchain_filename = 'toolchain-%s.tgz' |
| 202 |
| 203 toolchain_version = os.environ.get('MAC_TOOLCHAIN_REVISION', |
| 204 default_version) |
| 205 |
| 206 if ReadStampFile() == toolchain_version: |
| 207 print 'Toolchain (%s) is already up to date.' % toolchain_version |
179 AcceptLicense() | 208 AcceptLicense() |
180 return 0 | 209 return 0 |
181 | 210 |
182 if not CanAccessToolchainBucket(): | 211 if not CanAccessToolchainBucket(): |
183 RequestGsAuthentication() | 212 RequestGsAuthentication() |
184 return 1 | 213 return 1 |
185 | 214 |
186 # Reset the stamp file in case the build is unsuccessful. | 215 # Reset the stamp file in case the build is unsuccessful. |
187 WriteStampFile('') | 216 WriteStampFile('') |
188 | 217 |
189 toolchain_file = '%s.tgz' % toolchain_revision | 218 toolchain_file = '%s.tgz' % toolchain_version |
190 toolchain_full_url = TOOLCHAIN_URL + toolchain_file | 219 toolchain_full_url = TOOLCHAIN_URL + toolchain_file |
191 | 220 |
192 print 'Updating toolchain to %s...' % toolchain_revision | 221 print 'Updating toolchain to %s...' % toolchain_version |
193 try: | 222 try: |
194 toolchain_file = 'toolchain-%s.tgz' % toolchain_revision | 223 toolchain_file = toolchain_filename % toolchain_version |
195 toolchain_full_url = TOOLCHAIN_URL + toolchain_file | 224 toolchain_full_url = TOOLCHAIN_URL + toolchain_file |
196 DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR) | 225 DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR) |
197 AcceptLicense() | 226 AcceptLicense() |
198 | 227 |
199 print 'Toolchain %s unpacked.' % toolchain_revision | 228 print 'Toolchain %s unpacked.' % toolchain_version |
200 WriteStampFile(toolchain_revision) | 229 WriteStampFile(toolchain_version) |
201 return 0 | 230 return 0 |
202 except Exception as e: | 231 except Exception as e: |
203 print 'Failed to download toolchain %s.' % toolchain_file | 232 print 'Failed to download toolchain %s.' % toolchain_file |
204 print 'Exception %s' % e | 233 print 'Exception %s' % e |
205 print 'Exiting.' | 234 print 'Exiting.' |
206 return 1 | 235 return 1 |
207 | 236 |
208 if __name__ == '__main__': | 237 if __name__ == '__main__': |
209 sys.exit(main()) | 238 sys.exit(main()) |
OLD | NEW |