Commit 3fb4d5cf authored by Nirbheek Chauhan's avatar Nirbheek Chauhan 🐜

cerbero/msvc: Slightly rework MSVC env fetching

Instead of computing the vcvarsall at the module level, add a function
for it and use that. This also allows us to target a specific version
of Visual Studio (2015/2017/etc).
parent cee2200a
......@@ -25,25 +25,25 @@ from cerbero.errors import FatalError
# We only support Visual Studio 2015 as of now
vcvarsalls = {
'14.0': [r'Microsoft Visual Studio 14.0\VC\vcvarsall.bat'],
'15.0': [r'Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat',
'2015': [r'Microsoft Visual Studio 14.0\VC\vcvarsall.bat'],
'2017': [r'Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat',
r'Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat'],
}
program_files = Path(os.environ['PROGRAMFILES(X86)'])
vcvarsall = None
for version in sorted(vcvarsalls.keys(), reverse=True):
if vcvarsall:
break
for path in vcvarsalls[version]:
path = program_files / path
# Find the location of the Visual Studio installation
if path.is_file():
vcvarsall = path.as_posix()
break
if not vcvarsall:
versions = ', '.join(vcvarsalls.keys())
raise FatalError('Microsoft Visual Studio not found, please file a bug. We looked for: ' + versions)
def get_vcvarsall(version=None):
if version is not None:
versions = [version]
else:
versions = sorted(vcvarsalls.keys(), reverse=True)
for version in versions:
for path in vcvarsalls[version]:
path = program_files / path
# Find the location of the Visual Studio installation
if path.is_file():
return path.as_posix()
raise FatalError('Microsoft Visual Studio not found, please file a bug. '
'We looked for: ' + ', '.join(versions))
def append_path(var, path, sep=';'):
if var and not var.endswith(sep):
......@@ -89,10 +89,9 @@ def get_envvar_msvc_values(msvc, nomsvc, sep=';'):
index = msvc.index(nomsvc)
return msvc[0:index]
def get_msvc_env(vcvarsall, arch, target_arch):
def get_msvc_env(arch, target_arch, version=None):
ret_env = {}
if not os.path.isfile(vcvarsall):
raise FatalError("'{0}' not found".format(vcvarsall))
vcvarsall = get_vcvarsall(version)
without_msvc = run_and_get_env('set')
arg = get_vcvarsall_arg(arch, target_arch)
......
......@@ -87,15 +87,17 @@ if platform == Platform.WINDOWS:
allow_parallel_build = False
os.environ['ACLOCAL'] = 'aclocal-1.11'
# We use Visual Studio by default on Windows
if 'novisualstudio' not in variants:
variants.append('visualstudio')
from cerbero.ide.vs.env import vcvarsall, get_msvc_env, append_path
from cerbero.ide.vs.env import get_msvc_env, append_path
# Contains only the env vars that MSVC needs, including any existing vars
# that were appended/prepended and have new values
# FIXME: Use EnvVarOp class from cerbero/build/build.py
msvc_toolchain_env = {}
for key, value in get_msvc_env(vcvarsall, arch, target_arch).items():
for key, value in get_msvc_env(arch, target_arch).items():
if key in ('PATH', 'PATHEXT', 'INCLUDE', 'LIB'):
sep = separator
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment