2017-10-02 23:24:00 +02:00
|
|
|
import os
|
2017-10-24 22:47:27 +02:00
|
|
|
import platform
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2017-10-29 17:55:05 +01:00
|
|
|
from compat import decode_utf8
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
if os.name == 'nt':
|
2017-10-04 23:21:32 +02:00
|
|
|
import sys
|
|
|
|
if sys.version_info < (3,):
|
|
|
|
import _winreg as winreg
|
|
|
|
else:
|
|
|
|
import winreg
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
def _reg_open_key(key, subkey):
|
|
|
|
try:
|
|
|
|
return winreg.OpenKey(key, subkey)
|
2017-10-29 17:55:05 +01:00
|
|
|
except (WindowsError, OSError):
|
2017-10-02 23:24:00 +02:00
|
|
|
if platform.architecture()[0] == '32bit':
|
|
|
|
bitness_sam = winreg.KEY_WOW64_64KEY
|
|
|
|
else:
|
|
|
|
bitness_sam = winreg.KEY_WOW64_32KEY
|
|
|
|
return winreg.OpenKey(key, subkey, 0, winreg.KEY_READ | bitness_sam)
|
|
|
|
|
|
|
|
|
2017-10-24 22:47:27 +02:00
|
|
|
def _reg_open_key_bits(key, subkey, bits):
|
|
|
|
sam = winreg.KEY_READ
|
|
|
|
|
|
|
|
if platform.architecture()[0] == '32bit':
|
|
|
|
if bits == '64':
|
|
|
|
# Force 32bit process to search in 64bit registry
|
|
|
|
sam |= winreg.KEY_WOW64_64KEY
|
|
|
|
else:
|
|
|
|
if bits == '32':
|
|
|
|
# Force 64bit process to search in 32bit registry
|
|
|
|
sam |= winreg.KEY_WOW64_32KEY
|
|
|
|
|
|
|
|
return winreg.OpenKey(key, subkey, 0, sam)
|
|
|
|
|
|
|
|
|
|
|
|
def _find_mono_in_reg(subkey, bits):
|
2017-10-02 23:24:00 +02:00
|
|
|
try:
|
2017-10-24 22:47:27 +02:00
|
|
|
with _reg_open_key_bits(winreg.HKEY_LOCAL_MACHINE, subkey, bits) as hKey:
|
2017-10-02 23:24:00 +02:00
|
|
|
value, regtype = winreg.QueryValueEx(hKey, 'SdkInstallRoot')
|
|
|
|
return value
|
2017-10-29 17:55:05 +01:00
|
|
|
except (WindowsError, OSError):
|
2017-10-02 23:24:00 +02:00
|
|
|
return None
|
|
|
|
|
2017-10-24 22:47:27 +02:00
|
|
|
|
|
|
|
def _find_mono_in_reg_old(subkey, bits):
|
2017-10-02 23:24:00 +02:00
|
|
|
try:
|
2017-10-24 22:47:27 +02:00
|
|
|
with _reg_open_key_bits(winreg.HKEY_LOCAL_MACHINE, subkey, bits) as hKey:
|
2017-10-02 23:24:00 +02:00
|
|
|
default_clr, regtype = winreg.QueryValueEx(hKey, 'DefaultCLR')
|
|
|
|
if default_clr:
|
2017-10-24 22:47:27 +02:00
|
|
|
return _find_mono_in_reg(subkey + '\\' + default_clr, bits)
|
2017-10-02 23:24:00 +02:00
|
|
|
return None
|
|
|
|
except (WindowsError, EnvironmentError):
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2017-10-24 22:47:27 +02:00
|
|
|
def find_mono_root_dir(bits):
|
|
|
|
root_dir = _find_mono_in_reg(r'SOFTWARE\Mono', bits)
|
|
|
|
if root_dir is not None:
|
2018-06-25 18:38:03 +02:00
|
|
|
return str(root_dir)
|
2017-10-24 22:47:27 +02:00
|
|
|
root_dir = _find_mono_in_reg_old(r'SOFTWARE\Novell\Mono', bits)
|
|
|
|
if root_dir is not None:
|
2018-06-25 18:38:03 +02:00
|
|
|
return str(root_dir)
|
2017-10-24 22:47:27 +02:00
|
|
|
return ''
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
def find_msbuild_tools_path_reg():
|
2017-10-24 22:47:27 +02:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
vswhere = os.getenv('PROGRAMFILES(X86)')
|
|
|
|
if not vswhere:
|
|
|
|
vswhere = os.getenv('PROGRAMFILES')
|
|
|
|
vswhere += r'\Microsoft Visual Studio\Installer\vswhere.exe'
|
|
|
|
|
2018-04-30 12:50:42 +02:00
|
|
|
vswhere_args = ['-latest', '-products', '*', '-requires', 'Microsoft.Component.MSBuild']
|
2017-10-24 22:47:27 +02:00
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
try:
|
2017-10-24 22:47:27 +02:00
|
|
|
lines = subprocess.check_output([vswhere] + vswhere_args).splitlines()
|
|
|
|
|
|
|
|
for line in lines:
|
2017-10-29 17:55:05 +01:00
|
|
|
parts = decode_utf8(line).split(':', 1)
|
2017-10-24 22:47:27 +02:00
|
|
|
|
|
|
|
if len(parts) < 2 or parts[0] != 'installationPath':
|
|
|
|
continue
|
|
|
|
|
|
|
|
val = parts[1].strip()
|
|
|
|
|
|
|
|
if not val:
|
|
|
|
raise ValueError('Value of `installationPath` entry is empty')
|
|
|
|
|
|
|
|
return os.path.join(val, "MSBuild\\15.0\\Bin")
|
|
|
|
|
|
|
|
raise ValueError('Cannot find `installationPath` entry')
|
|
|
|
except ValueError as e:
|
|
|
|
print('Error reading output from vswhere: ' + e.message)
|
|
|
|
except WindowsError:
|
|
|
|
pass # Fine, vswhere not found
|
2017-10-29 17:55:05 +01:00
|
|
|
except (subprocess.CalledProcessError, OSError):
|
2017-10-24 22:47:27 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
# Try to find 14.0 in the Registry
|
|
|
|
|
|
|
|
try:
|
|
|
|
subkey = r'SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0'
|
|
|
|
with _reg_open_key(winreg.HKEY_LOCAL_MACHINE, subkey) as hKey:
|
2017-10-02 23:24:00 +02:00
|
|
|
value, regtype = winreg.QueryValueEx(hKey, 'MSBuildToolsPath')
|
|
|
|
return value
|
2017-10-29 17:55:05 +01:00
|
|
|
except (WindowsError, OSError):
|
2017-10-24 22:47:27 +02:00
|
|
|
return ''
|
|
|
|
|
|
|
|
return ''
|