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

Side by Side Diff: build/mac_toolchain.py

Issue 2412353003: Remove direct references to hermetic mac toolchain. (Closed)
Patch Set: Remove unused import. Created 4 years, 2 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
OLDNEW
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
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
(...skipping 21 matching lines...) Expand all
32 TOOLCHAIN_REVISION = '5B1008' 32 TOOLCHAIN_REVISION = '5B1008'
33 TOOLCHAIN_SUB_REVISION = 3 33 TOOLCHAIN_SUB_REVISION = 3
34 TOOLCHAIN_VERSION = '%s-%s' % (TOOLCHAIN_REVISION, TOOLCHAIN_SUB_REVISION) 34 TOOLCHAIN_VERSION = '%s-%s' % (TOOLCHAIN_REVISION, TOOLCHAIN_SUB_REVISION)
35 35
36 BASE_DIR = os.path.abspath(os.path.dirname(__file__)) 36 BASE_DIR = os.path.abspath(os.path.dirname(__file__))
37 TOOLCHAIN_BUILD_DIR = os.path.join(BASE_DIR, 'mac_files', 'Xcode.app') 37 TOOLCHAIN_BUILD_DIR = os.path.join(BASE_DIR, 'mac_files', 'Xcode.app')
38 STAMP_FILE = os.path.join(BASE_DIR, 'mac_files', 'toolchain_build_revision') 38 STAMP_FILE = os.path.join(BASE_DIR, 'mac_files', 'toolchain_build_revision')
39 TOOLCHAIN_URL = 'gs://chrome-mac-sdk/' 39 TOOLCHAIN_URL = 'gs://chrome-mac-sdk/'
40 40
41 41
42 def GetToolchainDirectory():
43 if sys.platform == 'darwin' and not UseLocalMacSDK():
44 return TOOLCHAIN_BUILD_DIR
45 else:
46 return None
47
48
49 def SetToolchainEnvironment():
50 mac_toolchain_dir = GetToolchainDirectory()
51 if mac_toolchain_dir:
52 os.environ['DEVELOPER_DIR'] = mac_toolchain_dir
53
54
55 def ReadStampFile(): 42 def ReadStampFile():
56 """Return the contents of the stamp file, or '' if it doesn't exist.""" 43 """Return the contents of the stamp file, or '' if it doesn't exist."""
57 try: 44 try:
58 with open(STAMP_FILE, 'r') as f: 45 with open(STAMP_FILE, 'r') as f:
59 return f.read().rstrip() 46 return f.read().rstrip()
60 except IOError: 47 except IOError:
61 return '' 48 return ''
62 49
63 50
64 def WriteStampFile(s): 51 def WriteStampFile(s):
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 old_path = subprocess.Popen(['/usr/bin/xcode-select', '-p'], 131 old_path = subprocess.Popen(['/usr/bin/xcode-select', '-p'],
145 stdout=subprocess.PIPE).communicate()[0].strip() 132 stdout=subprocess.PIPE).communicate()[0].strip()
146 try: 133 try:
147 build_dir = os.path.join(TOOLCHAIN_BUILD_DIR, 'Contents/Developer') 134 build_dir = os.path.join(TOOLCHAIN_BUILD_DIR, 'Contents/Developer')
148 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', build_dir]) 135 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', build_dir])
149 subprocess.check_call(['sudo', '/usr/bin/xcodebuild', '-license', 'accept']) 136 subprocess.check_call(['sudo', '/usr/bin/xcodebuild', '-license', 'accept'])
150 finally: 137 finally:
151 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', old_path]) 138 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', old_path])
152 139
153 140
154 def UseLocalMacSDK(): 141 def _UseLocalMacSDK():
155 force_pull = os.environ.has_key('FORCE_MAC_TOOLCHAIN') 142 force_pull = os.environ.has_key('FORCE_MAC_TOOLCHAIN')
156 143
157 # Don't update the toolchain if there's already one installed outside of the 144 # Don't update the toolchain if there's already one installed outside of the
158 # expected location for a Chromium mac toolchain, unless |force_pull| is set. 145 # expected location for a Chromium mac toolchain, unless |force_pull| is set.
159 proc = subprocess.Popen(['xcode-select', '-p'], stdout=subprocess.PIPE) 146 proc = subprocess.Popen(['xcode-select', '-p'], stdout=subprocess.PIPE)
160 xcode_select_dir = proc.communicate()[0] 147 xcode_select_dir = proc.communicate()[0]
161 rc = proc.returncode 148 rc = proc.returncode
162 return (not force_pull and rc == 0 and 149 return (not force_pull and rc == 0 and
163 TOOLCHAIN_BUILD_DIR not in xcode_select_dir) 150 TOOLCHAIN_BUILD_DIR not in xcode_select_dir)
164 151
165 152
166 def main(): 153 def main():
167 if sys.platform != 'darwin': 154 if sys.platform != 'darwin':
168 return 0 155 return 0
169 156
170 # TODO(justincohen): Add support for GN per crbug.com/570091 157 if _UseLocalMacSDK():
171 if UseLocalMacSDK():
172 print 'Using local toolchain.' 158 print 'Using local toolchain.'
173 return 0 159 return 0
174 160
175 toolchain_revision = os.environ.get('MAC_TOOLCHAIN_REVISION', 161 toolchain_revision = os.environ.get('MAC_TOOLCHAIN_REVISION',
176 TOOLCHAIN_VERSION) 162 TOOLCHAIN_VERSION)
177 if ReadStampFile() == toolchain_revision: 163 if ReadStampFile() == toolchain_revision:
178 print 'Toolchain (%s) is already up to date.' % toolchain_revision 164 print 'Toolchain (%s) is already up to date.' % toolchain_revision
179 AcceptLicense() 165 AcceptLicense()
180 return 0 166 return 0
181 167
(...skipping 18 matching lines...) Expand all
200 WriteStampFile(toolchain_revision) 186 WriteStampFile(toolchain_revision)
201 return 0 187 return 0
202 except Exception as e: 188 except Exception as e:
203 print 'Failed to download toolchain %s.' % toolchain_file 189 print 'Failed to download toolchain %s.' % toolchain_file
204 print 'Exception %s' % e 190 print 'Exception %s' % e
205 print 'Exiting.' 191 print 'Exiting.'
206 return 1 192 return 1
207 193
208 if __name__ == '__main__': 194 if __name__ == '__main__':
209 sys.exit(main()) 195 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698