in python/treelite/contrib/msvc.py [0:0]
def _varsall_bat_path():
# if a custom location is given, try that first
if 'TREELITE_VCVARSALL' in os.environ:
candidate = os.environ['TREELITE_VCVARSALL']
if os.path.basename(candidate).lower() != 'vcvarsall.bat':
raise OSError('Environment variable TREELITE_VCVARSALL must point to '+\
'file vcvarsall.bat')
if os.path.isfile(candidate):
return candidate
raise OSError('Environment variable TREELITE_VCVARSALL does not refer '+\
'to existing vcvarsall.bat')
## Bunch of heuristics to locate vcvarsall.bat
candidate_paths = [] # List of possible paths to vcvarsall.bat
try:
import winreg # pylint: disable=E0401
if _is_64bit_windows():
key_name = 'SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7'
else:
key_name = 'SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VC7'
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_name)
i = 0
while True:
try:
version, vcroot, _ = winreg.EnumValue(key, i)
if StrictVersion(version) >= StrictVersion('15.0'):
# Visual Studio 2017 revamped directory structure
candidate_paths.append(os.path.join(vcroot, 'VC\\Auxiliary\\Build\\vcvarsall.bat'))
else:
candidate_paths.append(os.path.join(vcroot, 'VC\\vcvarsall.bat'))
except WindowsError: # pylint: disable=E0602
break
i += 1
except FileNotFoundError:
pass # No registry key found
except ImportError:
pass # No winreg module
for candidate in candidate_paths:
if os.path.isfile(candidate):
return candidate
# If registry method fails, try a bunch of pre-defined paths
# Visual Studio 2017 and higher
for vcroot in glob.glob('C:\\Program Files (x86)\\Microsoft Visual Studio\\*') + \
glob.glob('C:\\Program Files\\Microsoft Visual Studio\\*'):
if re.fullmatch(r'[0-9]+', os.path.basename(vcroot)):
for candidate in glob.glob(vcroot + '\\*\\VC\\Auxiliary\\Build\\vcvarsall.bat'):
if os.path.isfile(candidate):
return candidate
# Previous versions of Visual Studio
pattern = '\\Microsoft Visual Studio*\\VC\\vcvarsall.bat'
for candidate in glob.glob('C:\\Program Files (x86)' + pattern) + \
glob.glob('C:\\Program Files' + pattern):
if os.path.isfile(candidate):
return candidate
raise OSError('vcvarsall.bat not found; please specify its full path in '+\
'the environment variable TREELITE_VCVARSALL')