Skip to content

Commit

Permalink
Move LD_LIBRARY_PATH logic to environment object
Browse files Browse the repository at this point in the history
  • Loading branch information
xclaesse committed Oct 28, 2024
1 parent db82c2d commit 3309ea0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
22 changes: 1 addition & 21 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1987,12 +1987,9 @@ def get_introspection_data(self, target_id: str, target: build.Target) -> T.List
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:
Expand All @@ -2012,24 +2009,7 @@ def get_devenv(self) -> mesonlib.EnvironmentVariables:
# 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@',
Expand Down
22 changes: 22 additions & 0 deletions mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,3 +1000,25 @@ def get_exe_wrapper(self) -> T.Optional[ExternalProgram]:

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

0 comments on commit 3309ea0

Please sign in to comment.