OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 """Extracts a Windows VS2013 toolchain from various downloadable pieces.""" | 6 """Extracts a Windows VS2013 toolchain from various downloadable pieces.""" |
7 | 7 |
8 | 8 |
9 import ctypes | 9 import ctypes |
10 import optparse | 10 import optparse |
11 import os | 11 import os |
12 import shutil | 12 import shutil |
13 import subprocess | 13 import subprocess |
14 import sys | 14 import sys |
15 import tempfile | 15 import tempfile |
16 import urllib2 | 16 import urllib2 |
17 | 17 |
18 | 18 |
19 BASEDIR = os.path.dirname(os.path.abspath(__file__)) | 19 BASEDIR = os.path.dirname(os.path.abspath(__file__)) |
20 g_temp_dirs = [] | 20 g_temp_dirs = [] |
21 | 21 |
22 | 22 |
23 sys.path.append(os.path.join(BASEDIR, '..')) | |
24 import download_from_google_storage | |
25 | |
26 | |
23 def GetLongPathName(path): | 27 def GetLongPathName(path): |
24 """Converts any 8dot3 names in the path to the full name.""" | 28 """Converts any 8dot3 names in the path to the full name.""" |
25 buf = ctypes.create_unicode_buffer(260) | 29 buf = ctypes.create_unicode_buffer(260) |
26 size = ctypes.windll.kernel32.GetLongPathNameW(unicode(path), buf, 260) | 30 size = ctypes.windll.kernel32.GetLongPathNameW(unicode(path), buf, 260) |
27 if (size > 260): | 31 if (size > 260): |
28 sys.exit('Long form of path longer than 260 chars: %s' % path) | 32 sys.exit('Long form of path longer than 260 chars: %s' % path) |
29 return buf.value | 33 return buf.value |
30 | 34 |
31 | 35 |
32 def RunOrDie(command): | 36 def RunOrDie(command): |
(...skipping 16 matching lines...) Expand all Loading... | |
49 sys.stdout.write('Cleaning up temporaries...\n') | 53 sys.stdout.write('Cleaning up temporaries...\n') |
50 for temp in g_temp_dirs: | 54 for temp in g_temp_dirs: |
51 # shutil.rmtree errors out on read only attributes. | 55 # shutil.rmtree errors out on read only attributes. |
52 RunOrDie('rmdir /s/q "%s"' % temp) | 56 RunOrDie('rmdir /s/q "%s"' % temp) |
53 g_temp_dirs = [] | 57 g_temp_dirs = [] |
54 | 58 |
55 | 59 |
56 def GetIsoUrl(pro): | 60 def GetIsoUrl(pro): |
57 """Gets the .iso URL. | 61 """Gets the .iso URL. |
58 | 62 |
59 If |pro| is False, downloads the Express edition. | 63 If |pro| is False, downloads the Express edition. If |CHROME_HEADLESS| is |
64 set in the environment, then we assume we're on an internal bot, and download | |
65 from internal google storage instead. | |
60 """ | 66 """ |
61 prefix = 'http://download.microsoft.com/download/' | 67 prefix = 'http://download.microsoft.com/download/' |
62 if pro: | 68 if pro: |
63 return (prefix + | 69 return (prefix + |
64 'A/F/1/AF128362-A6A8-4DB3-A39A-C348086472CC/VS2013_RTM_PRO_ENU.iso') | 70 'A/F/1/AF128362-A6A8-4DB3-A39A-C348086472CC/VS2013_RTM_PRO_ENU.iso') |
65 else: | 71 else: |
66 return (prefix + | 72 return (prefix + |
67 '7/2/E/72E0F986-D247-4289-B9DC-C4FB07374894/VS2013_RTM_DskExp_ENU.iso') | 73 '7/2/E/72E0F986-D247-4289-B9DC-C4FB07374894/VS2013_RTM_DskExp_ENU.iso') |
68 | 74 |
69 | 75 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 rc = os.system(target_path + ' /quiet ' | 152 rc = os.system(target_path + ' /quiet ' |
147 '/features OptionId.WindowsDesktopDebuggers ' | 153 '/features OptionId.WindowsDesktopDebuggers ' |
148 '/layout ' + standalone_path) | 154 '/layout ' + standalone_path) |
149 if rc == 0: | 155 if rc == 0: |
150 return standalone_path | 156 return standalone_path |
151 count += 1 | 157 count += 1 |
152 sys.stdout.write('Windows 8 SDK failed to download, retrying.\n') | 158 sys.stdout.write('Windows 8 SDK failed to download, retrying.\n') |
153 raise SystemExit("After multiple retries, couldn't download Win8 SDK") | 159 raise SystemExit("After multiple retries, couldn't download Win8 SDK") |
154 | 160 |
155 | 161 |
162 def DownloadUsingGsutil(filename): | |
163 """Downloads the given file from Google Storage chrome-wintoolchain bucket.""" | |
164 temp_dir = TempDir() | |
165 assert os.path.basename(filename) == filename | |
166 target_path = os.path.join(temp_dir, filename) | |
167 gsutil = download_from_google_storage.Gsutil( | |
168 download_from_google_storage.GSUTIL_DEFAULT_PATH, os.devnull) | |
Ryan Tseng
2014/01/28 00:55:58
Don't use os.devnull. I assume this is an authent
scottmg
2014/01/28 01:11:44
Done. (It's not optional in __init__.)
| |
169 code, _, err = gsutil.check_call( | |
170 'cp', 'gs://chrome-wintoolchain/' + filename, target_path) | |
171 if code != 0: | |
172 raise SystemExit('gsutil error: %s' % err) | |
173 return target_path | |
174 | |
175 | |
176 def GetVSInternal(): | |
177 """Uses gsutil to pull the toolchain from internal Google Storage bucket.""" | |
178 return DownloadUsingGsutil('VS2013_RTM_PRO_ENU.iso') | |
179 | |
180 | |
181 def GetSDKInternal(): | |
182 """Downloads a zipped copy of the SDK from internal Google Storage bucket, | |
183 and extracts it.""" | |
184 zip_file = DownloadUsingGsutil('Standalone.zip') | |
185 return ExtractIso(zip_file) | |
186 | |
187 | |
156 class SourceImages(object): | 188 class SourceImages(object): |
157 def __init__(self, vs_path, sdk8_path): | 189 def __init__(self, vs_path, sdk8_path): |
158 self.vs_path = vs_path | 190 self.vs_path = vs_path |
159 self.sdk8_path = sdk8_path | 191 self.sdk8_path = sdk8_path |
160 | 192 |
161 | 193 |
162 def GetSourceImages(local_dir, pro): | 194 def GetSourceImages(local_dir, pro): |
163 url = GetIsoUrl(pro) | 195 url = GetIsoUrl(pro) |
164 if local_dir: | 196 if os.environ.get('CHROME_HEADLESS'): |
197 return SourceImages(GetVSInternal(), GetSDKInternal()) | |
198 elif local_dir: | |
165 return SourceImages(os.path.join(local_dir, os.path.basename(url)), | 199 return SourceImages(os.path.join(local_dir, os.path.basename(url)), |
166 os.path.join(local_dir, 'Standalone')) | 200 os.path.join(local_dir, 'Standalone')) |
167 else: | 201 else: |
168 # Note that we do the SDK first, as it might cause an elevation prompt. | 202 # Note that we do the SDK first, as it might cause an elevation prompt. |
169 sdk8_path = DownloadSDK8() | 203 sdk8_path = DownloadSDK8() |
170 vs_path = DownloadMainIso(url) | 204 vs_path = DownloadMainIso(url) |
171 return SourceImages(vs_path, sdk8_path) | 205 return SourceImages(vs_path, sdk8_path) |
172 | 206 |
173 | 207 |
174 def ExtractMsiList(root_dir, packages): | 208 def ExtractMsiList(root_dir, packages): |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 CopyToFinalLocation(extracted, target_dir) | 368 CopyToFinalLocation(extracted, target_dir) |
335 | 369 |
336 GenerateSetEnvCmd(target_dir, not options.express) | 370 GenerateSetEnvCmd(target_dir, not options.express) |
337 finally: | 371 finally: |
338 if options.clean: | 372 if options.clean: |
339 DeleteAllTempDirs() | 373 DeleteAllTempDirs() |
340 | 374 |
341 | 375 |
342 if __name__ == '__main__': | 376 if __name__ == '__main__': |
343 sys.exit(main()) | 377 sys.exit(main()) |
OLD | NEW |