Commit 0071999c authored by Nirbheek Chauhan's avatar Nirbheek Chauhan 🐜
Browse files

cerbero/genlib: Reuse msvc env found at startup

Since Visual Studio is optional now, this patch is non-trivial.

Part-of: <gstreamer/cerbero!480>
parent 576ddac5
......@@ -116,13 +116,10 @@ class GenLib(object):
# No Visual Studio tools while cross-compiling
if platform != Platform.WINDOWS:
return None, None
try:
from cerbero.ide.vs.env import get_msvc_env
msvc_env = get_msvc_env('x86', target_arch, False, self.config.vs_install_version,
self.config.vs_install_path)[0]
except FatalError:
# Visual Studio not installed
if 'PATH' not in self.config.msvc_env_for_toolchain:
return None, None
paths = msvc_env['PATH']
paths = self.config.msvc_env_for_toolchain['PATH'].get()
return shutil.which('lib', path=paths), paths
class GenGnuLib(GenLib):
......
......@@ -3,7 +3,7 @@
# shouldn't be modified unless you now what you are doing.
# PLEASE, DO NOT EDIT THIS FILE
from cerbero.config import Architecture, Platform
from cerbero.config import Architecture, Platform, FatalError
from cerbero.utils import EnvValue, EnvValueArg, EnvValueCmd, EnvValuePath
# We don't want anything from mingw or msys detected in configure and
......@@ -174,22 +174,33 @@ if platform == Platform.WINDOWS:
# Only use one process to make the build more reliable.
allow_parallel_build = False
if platform == Platform.WINDOWS and variants.visualstudio:
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
msvc_env, msvc_version = get_msvc_env(arch, target_arch, variants.uwp,
vs_install_version, vs_install_path)
for key, value in msvc_env.items():
msvc_env_for_toolchain[key] = EnvValue.from_key(key, value)
# We want the MSVC compiler and linker to find the headers and libraries
# provided by recipes built by us, so append to INCLUDE and LIB.
# NOTE: We do not want to add the MinGW toolchain paths here
msvc_env_for_toolchain['INCLUDE'] += [os.path.join(prefix, 'include')]
msvc_env_for_toolchain['LIB'] += [os.path.join(prefix, 'lib' + lib_suffix)]
msvc_env_for_toolchain['WINDRES'] = EnvValueCmd('rc')
if variants.uwp:
meson_properties['needs_exe_wrapper'] = 'true'
# Always try to fetch msvc env vars on Windows, since we optionally use it
# for finding `lib.exe`
have_visualstudio = False
try:
# Contains only the env vars that MSVC needs, including any existing vars
# that were appended/prepended and have new values
msvc_env, msvc_version = get_msvc_env(arch, target_arch, variants.uwp,
vs_install_version, vs_install_path)
have_visualstudio = True
except FatalError as e:
if variants.visualstudio:
raise e
print('Could not find Visual Studio; will only use MinGW')
if have_visualstudio:
for key, value in msvc_env.items():
msvc_env_for_toolchain[key] = EnvValue.from_key(key, value)
# We want the MSVC compiler and linker to find the headers and libraries
# provided by recipes built by us, so append to INCLUDE and LIB.
# NOTE: We do not want to add the MinGW toolchain paths here
msvc_env_for_toolchain['INCLUDE'] += [os.path.join(prefix, 'include')]
msvc_env_for_toolchain['LIB'] += [os.path.join(prefix, 'lib' + lib_suffix)]
msvc_env_for_toolchain['WINDRES'] = EnvValueCmd('rc')
if variants.uwp:
meson_properties['needs_exe_wrapper'] = 'true'
# Export the env for a shell
if for_shell:
......
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