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 """Download necessary mac toolchain files under certain conditions. If | 6 """Download necessary mac toolchain files under certain conditions. If |
7 xcode-select is already set and points to an external folder | 7 xcode-select is already set and points to an external folder |
Nico
2016/11/01 01:07:34
This is no longer true now, right?
erikchen
2016/11/01 19:33:48
Updated Comment.
| |
8 (e.g. /Application/Xcode.app), this script only runs if the GYP_DEFINE | 8 (e.g. /Application/Xcode.app), this script only runs if the GYP_DEFINE |
9 |force_mac_toolchain| is set. To override the values in | 9 |force_mac_toolchain| is set. To override the values in |
10 |TOOLCHAIN_REVISION|-|TOOLCHAIN_SUB_REVISION| below, GYP_DEFINE | 10 |TOOLCHAIN_REVISION|-|TOOLCHAIN_SUB_REVISION| below, GYP_DEFINE |
11 mac_toolchain_revision can be used instead. | 11 mac_toolchain_revision can be used instead. |
12 | 12 |
13 This script will only run on machines if /usr/bin/xcodebuild and | 13 This script will only run on machines if /usr/bin/xcodebuild and |
14 /usr/bin/xcode-select has been added to the sudoers list so the license can be | 14 /usr/bin/xcode-select has been added to the sudoers list so the license can be |
15 accepted. | 15 accepted. |
16 | 16 |
17 Otherwise, user input would be required to complete the script. Perhaps future | 17 Otherwise, user input would be required to complete the script. Perhaps future |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 old_path = subprocess.Popen(['/usr/bin/xcode-select', '-p'], | 131 old_path = subprocess.Popen(['/usr/bin/xcode-select', '-p'], |
132 stdout=subprocess.PIPE).communicate()[0].strip() | 132 stdout=subprocess.PIPE).communicate()[0].strip() |
133 try: | 133 try: |
134 build_dir = os.path.join(TOOLCHAIN_BUILD_DIR, 'Contents/Developer') | 134 build_dir = os.path.join(TOOLCHAIN_BUILD_DIR, 'Contents/Developer') |
135 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', build_dir]) | 135 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', build_dir]) |
136 subprocess.check_call(['sudo', '/usr/bin/xcodebuild', '-license', 'accept']) | 136 subprocess.check_call(['sudo', '/usr/bin/xcodebuild', '-license', 'accept']) |
137 finally: | 137 finally: |
138 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', old_path]) | 138 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', old_path]) |
139 | 139 |
140 | 140 |
141 def _UseLocalMacSDK(): | 141 def _UseHermeticToolchain(): |
142 force_pull = os.environ.has_key('FORCE_MAC_TOOLCHAIN') | 142 current_dir = os.path.dirname(os.path.realpath(__file__)) |
143 script_path = os.path.join(current_dir, 'mac/should_use_hermetic_xcode.py') | |
144 proc = subprocess.Popen([script_path], stdout=subprocess.PIPE) | |
Nico
2016/11/01 01:07:34
https://cs.chromium.org/chromium/tools/depot_tools
erikchen
2016/11/01 19:33:48
Hm.
"""
if (HaveSrcInternalAccess() or
| |
145 return '1' in proc.stdout.readline() | |
143 | 146 |
144 # Don't update the toolchain if there's already one installed outside of the | 147 |
145 # expected location for a Chromium mac toolchain, unless |force_pull| is set. | 148 def RequestGsAuthentication(): |
146 proc = subprocess.Popen(['xcode-select', '-p'], stdout=subprocess.PIPE) | 149 """Requests that the user authenticate to be able to access gs://. |
Nico
2016/11/01 01:07:34
(at least this is gone)
| |
147 xcode_select_dir = proc.communicate()[0] | 150 """ |
148 rc = proc.returncode | 151 print 'Access to ' + TOOLCHAIN_URL + ' not configured.' |
149 return (not force_pull and rc == 0 and | 152 print '-----------------------------------------------------------------' |
150 TOOLCHAIN_BUILD_DIR not in xcode_select_dir) | 153 print |
154 print 'You appear to be a Googler.' | |
155 print | |
156 print 'I\'m sorry for the hassle, but you need to do a one-time manual' | |
157 print 'authentication. Please run:' | |
158 print | |
159 print ' download_from_google_storage --config' | |
160 print | |
161 print 'and follow the instructions.' | |
162 print | |
163 print 'NOTE 1: Use your google.com credentials, not chromium.org.' | |
164 print 'NOTE 2: Enter 0 when asked for a "project-id".' | |
165 print | |
166 print '-----------------------------------------------------------------' | |
167 print | |
168 sys.stdout.flush() | |
169 sys.exit(1) | |
151 | 170 |
152 | 171 |
153 def main(): | 172 def main(): |
154 if sys.platform != 'darwin': | 173 if sys.platform != 'darwin': |
155 return 0 | 174 return 0 |
156 | 175 |
157 if _UseLocalMacSDK(): | 176 if not _UseHermeticToolchain(): |
158 print 'Using local toolchain.' | 177 print 'Using local toolchain.' |
159 return 0 | 178 return 0 |
160 | 179 |
161 toolchain_revision = os.environ.get('MAC_TOOLCHAIN_REVISION', | 180 toolchain_revision = os.environ.get('MAC_TOOLCHAIN_REVISION', |
162 TOOLCHAIN_VERSION) | 181 TOOLCHAIN_VERSION) |
163 if ReadStampFile() == toolchain_revision: | 182 if ReadStampFile() == toolchain_revision: |
164 print 'Toolchain (%s) is already up to date.' % toolchain_revision | 183 print 'Toolchain (%s) is already up to date.' % toolchain_revision |
165 AcceptLicense() | 184 AcceptLicense() |
166 return 0 | 185 return 0 |
167 | 186 |
168 if not CanAccessToolchainBucket(): | 187 if not CanAccessToolchainBucket(): |
169 print 'Cannot access toolchain bucket.' | 188 RequestGsAuthentication() |
170 return 0 | 189 return 1 |
171 | 190 |
172 # Reset the stamp file in case the build is unsuccessful. | 191 # Reset the stamp file in case the build is unsuccessful. |
173 WriteStampFile('') | 192 WriteStampFile('') |
174 | 193 |
175 toolchain_file = '%s.tgz' % toolchain_revision | 194 toolchain_file = '%s.tgz' % toolchain_revision |
176 toolchain_full_url = TOOLCHAIN_URL + toolchain_file | 195 toolchain_full_url = TOOLCHAIN_URL + toolchain_file |
177 | 196 |
178 print 'Updating toolchain to %s...' % toolchain_revision | 197 print 'Updating toolchain to %s...' % toolchain_revision |
179 try: | 198 try: |
180 toolchain_file = 'toolchain-%s.tgz' % toolchain_revision | 199 toolchain_file = 'toolchain-%s.tgz' % toolchain_revision |
181 toolchain_full_url = TOOLCHAIN_URL + toolchain_file | 200 toolchain_full_url = TOOLCHAIN_URL + toolchain_file |
182 DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR) | 201 DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR) |
183 AcceptLicense() | 202 AcceptLicense() |
184 | 203 |
185 print 'Toolchain %s unpacked.' % toolchain_revision | 204 print 'Toolchain %s unpacked.' % toolchain_revision |
186 WriteStampFile(toolchain_revision) | 205 WriteStampFile(toolchain_revision) |
187 return 0 | 206 return 0 |
188 except Exception as e: | 207 except Exception as e: |
189 print 'Failed to download toolchain %s.' % toolchain_file | 208 print 'Failed to download toolchain %s.' % toolchain_file |
190 print 'Exception %s' % e | 209 print 'Exception %s' % e |
191 print 'Exiting.' | 210 print 'Exiting.' |
192 return 1 | 211 return 1 |
Nico
2016/10/26 20:12:08
could this return the "are we using system" bit to
erikchen
2016/10/26 20:21:10
This is invoked during "gclient sync", which is de
| |
193 | 212 |
194 if __name__ == '__main__': | 213 if __name__ == '__main__': |
195 sys.exit(main()) | 214 sys.exit(main()) |
OLD | NEW |