Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
|
scottmg
2016/01/14 03:10:28
2016
brucedawson
2016/01/14 21:14:17
Done.
| |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """ | |
| 6 Install the Windows 10 Universal C Runtime if needed. This is required so that | |
| 7 the VS 2015 tools will run, and also helps with running Chromium debug | |
| 8 components, which are dynamically linked. | |
| 9 """ | |
| 10 | |
| 11 import os | |
| 12 import platform | |
| 13 import re | |
| 14 import subprocess | |
| 15 import sys | |
| 16 | |
| 17 def GetInstallerName(): | |
|
scottmg
2016/01/14 03:10:28
Two blank lines between top-level statements in Py
brucedawson
2016/01/14 21:14:17
Done.
| |
| 18 """Return the name of the Windows 10 Universal C Runtime installer for the | |
| 19 current platform, or None if installer is not needed or not applicable. | |
| 20 The registry has to be used instead of sys.getwindowsversion() because | |
| 21 Python 2.7 is only manifested as being compatible up to Windows 8, so the | |
| 22 version APIs helpfully return a maximum of 6.2 (Windows 8). | |
| 23 """ | |
| 24 ver_re = re.compile('.*REG_SZ * (\d+)\.(\d+)') | |
| 25 key_name = '"HKLM\Software\Microsoft\Windows NT\CurrentVersion"' | |
| 26 output = subprocess.check_output('reg query %s /v CurrentVersion' % key_name) | |
| 27 match = ver_re.match(output.replace('\n', ' ')) | |
| 28 if match.groups() == ('6', '1'): | |
| 29 # Windows 7 and Windows Server 2008 R2 | |
| 30 update = 'Windows6.1-KB2999226-x64.msu' | |
|
scottmg
2016/01/14 03:10:28
Could probably just return X rather than than havi
brucedawson
2016/01/14 21:14:17
Done.
| |
| 31 elif match.groups() == ('6', '2'): | |
| 32 # Windows 8 and Windows Server 2012 | |
| 33 update = 'Windows8-RT-KB2999226-x64.msu' | |
| 34 elif match.groups() == ('6', '3'): | |
| 35 # Windows 8.1 and Windows Server 2012 R2 | |
| 36 update = 'Windows8.1-KB2999226-x64.msu' | |
| 37 else: | |
| 38 # Windows 10 or higher assumed | |
| 39 update = None | |
| 40 return update | |
| 41 | |
| 42 def main(): | |
| 43 bitness = platform.architecture()[0] | |
| 44 # When running 64-bit python the x64 DLLs will be in System32 | |
| 45 x64_path = 'System32' if bitness == '64bit' else 'Sysnative' | |
| 46 x64_path = os.path.join(r'C:\Windows', x64_path) | |
|
scottmg
2016/01/14 03:10:28
WINDIR? Whatever.
| |
| 47 sample_crt_file = os.path.join(x64_path, 'api-ms-win-crt-math-l1-1-0.dll') | |
|
scottmg
2016/01/14 03:10:28
Is 1-1-0 always going to be around in Win10+ forev
brucedawson
2016/01/14 21:14:17
I don't know for sure. I think so.
An alternative
| |
| 48 | |
| 49 if os.path.exists(sample_crt_file): | |
| 50 # Nothing to do. Exiting. | |
| 51 sys.exit(0) | |
| 52 | |
| 53 print '%s does not exist - installing' % sample_crt_file | |
|
scottmg
2016/01/14 03:10:28
'...installing Windows 10 Universal CRT'
brucedawson
2016/01/14 21:14:17
Done.
| |
| 54 | |
| 55 installer = os.path.join(GetInstallerName()) | |
| 56 command = r'wusa.exe /quiet "%s"' % installer | |
| 57 print 'Running %s' % command | |
| 58 | |
| 59 try: | |
| 60 subprocess.check_call(command) | |
| 61 except WindowsError as e: | |
| 62 if e.winerror == 740: # The requested operation requires elevation | |
| 63 raise Exception('Elevation required. You must manually install %s' % | |
|
scottmg
2016/01/14 03:10:28
Instead of raise'ing here, a well formatted messag
brucedawson
2016/01/14 21:14:17
Are you suggesting not doing a raise at all? My as
scottmg
2016/01/14 21:47:31
I was suggesting print ...; system.exit(1) or some
| |
| 64 installer) | |
| 65 raise e | |
| 66 | |
| 67 if __name__ == '__main__': | |
| 68 sys.exit(main()) | |
| OLD | NEW |