Chromium Code Reviews| Index: win_toolchain/install_universal_c_runtime.py |
| diff --git a/win_toolchain/install_universal_c_runtime.py b/win_toolchain/install_universal_c_runtime.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aefc60818abe48aed15f0cb61d958e95bd107e02 |
| --- /dev/null |
| +++ b/win_toolchain/install_universal_c_runtime.py |
| @@ -0,0 +1,68 @@ |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
|
scottmg
2016/01/14 03:10:28
2016
brucedawson
2016/01/14 21:14:17
Done.
|
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +""" |
| +Install the Windows 10 Universal C Runtime if needed. This is required so that |
| +the VS 2015 tools will run, and also helps with running Chromium debug |
| +components, which are dynamically linked. |
| +""" |
| + |
| +import os |
| +import platform |
| +import re |
| +import subprocess |
| +import sys |
| + |
| +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.
|
| + """Return the name of the Windows 10 Universal C Runtime installer for the |
| + current platform, or None if installer is not needed or not applicable. |
| + The registry has to be used instead of sys.getwindowsversion() because |
| + Python 2.7 is only manifested as being compatible up to Windows 8, so the |
| + version APIs helpfully return a maximum of 6.2 (Windows 8). |
| + """ |
| + ver_re = re.compile('.*REG_SZ * (\d+)\.(\d+)') |
| + key_name = '"HKLM\Software\Microsoft\Windows NT\CurrentVersion"' |
| + output = subprocess.check_output('reg query %s /v CurrentVersion' % key_name) |
| + match = ver_re.match(output.replace('\n', ' ')) |
| + if match.groups() == ('6', '1'): |
| + # Windows 7 and Windows Server 2008 R2 |
| + 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.
|
| + elif match.groups() == ('6', '2'): |
| + # Windows 8 and Windows Server 2012 |
| + update = 'Windows8-RT-KB2999226-x64.msu' |
| + elif match.groups() == ('6', '3'): |
| + # Windows 8.1 and Windows Server 2012 R2 |
| + update = 'Windows8.1-KB2999226-x64.msu' |
| + else: |
| + # Windows 10 or higher assumed |
| + update = None |
| + return update |
| + |
| +def main(): |
| + bitness = platform.architecture()[0] |
| + # When running 64-bit python the x64 DLLs will be in System32 |
| + x64_path = 'System32' if bitness == '64bit' else 'Sysnative' |
| + x64_path = os.path.join(r'C:\Windows', x64_path) |
|
scottmg
2016/01/14 03:10:28
WINDIR? Whatever.
|
| + 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
|
| + |
| + if os.path.exists(sample_crt_file): |
| + # Nothing to do. Exiting. |
| + sys.exit(0) |
| + |
| + 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.
|
| + |
| + installer = os.path.join(GetInstallerName()) |
| + command = r'wusa.exe /quiet "%s"' % installer |
| + print 'Running %s' % command |
| + |
| + try: |
| + subprocess.check_call(command) |
| + except WindowsError as e: |
| + if e.winerror == 740: # The requested operation requires elevation |
| + 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
|
| + installer) |
| + raise e |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |