Move LD_LIBRARY_PATH logic to environment object

pull/13237/merge
Xavier Claessens 4 weeks ago committed by Xavier Claessens
parent b131b2dc76
commit 38dc9894ad
  1. 22
      mesonbuild/backend/backends.py
  2. 22
      mesonbuild/environment.py

@ -1987,12 +1987,9 @@ class Backend:
return []
def get_devenv(self) -> mesonlib.EnvironmentVariables:
env = mesonlib.EnvironmentVariables()
extra_paths = set()
library_paths = set()
build_machine = self.environment.machines[MachineChoice.BUILD]
host_machine = self.environment.machines[MachineChoice.HOST]
need_wine = not build_machine.is_windows() and host_machine.is_windows()
for t in self.build.get_targets().values():
in_default_dir = t.should_install() and not t.get_install_dir()[2]
if t.for_machine != MachineChoice.HOST or not in_default_dir:
@ -2012,24 +2009,7 @@ class Backend:
# LD_LIBRARY_PATH. This allows running system applications using
# that library.
library_paths.add(tdir)
if need_wine:
# Executable paths should be in both PATH and WINEPATH.
# - Having them in PATH makes bash completion find it,
# and make running "foo.exe" find it when wine-binfmt is installed.
# - Having them in WINEPATH makes "wine foo.exe" find it.
library_paths.update(extra_paths)
if library_paths:
if need_wine:
env.prepend('WINEPATH', list(library_paths), separator=';')
elif host_machine.is_windows() or host_machine.is_cygwin():
extra_paths.update(library_paths)
elif host_machine.is_darwin():
env.prepend('DYLD_LIBRARY_PATH', list(library_paths))
else:
env.prepend('LD_LIBRARY_PATH', list(library_paths))
if extra_paths:
env.prepend('PATH', list(extra_paths))
return env
return self.environment.get_env_for_paths(library_paths, extra_paths)
def compiler_to_generator_args(self, target: build.BuildTarget,
compiler: 'Compiler', output: str = '@OUTPUT@',

@ -1000,3 +1000,25 @@ class Environment:
def has_exe_wrapper(self) -> bool:
return self.exe_wrapper and self.exe_wrapper.found()
def get_env_for_paths(self, library_paths: T.Set[str], extra_paths: T.Set[str]) -> mesonlib.EnvironmentVariables:
env = mesonlib.EnvironmentVariables()
need_wine = not self.machines.build.is_windows() and self.machines.host.is_windows()
if need_wine:
# Executable paths should be in both PATH and WINEPATH.
# - Having them in PATH makes bash completion find it,
# and make running "foo.exe" find it when wine-binfmt is installed.
# - Having them in WINEPATH makes "wine foo.exe" find it.
library_paths.update(extra_paths)
if library_paths:
if need_wine:
env.prepend('WINEPATH', list(library_paths), separator=';')
elif self.machines.host.is_windows() or self.machines.host.is_cygwin():
extra_paths.update(library_paths)
elif self.machines.host.is_darwin():
env.prepend('DYLD_LIBRARY_PATH', list(library_paths))
else:
env.prepend('LD_LIBRARY_PATH', list(library_paths))
if extra_paths:
env.prepend('PATH', list(extra_paths))
return env

Loading…
Cancel
Save