Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

external-project: Add devenv support #13827

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/markdown/External-Project-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

*This is an experimental module, API could change.*

*Added 0.56.0*

This module allows building code that uses build systems other than
Meson. This module is intended to be used to build Autotools
subprojects as fallback if the dependency couldn't be found on the
Expand Down Expand Up @@ -47,7 +49,8 @@ Known limitations:
from `-uninstalled.pc` files. This is arguably a bug that could be fixed in
future version of pkg-config/pkgconf.

*Added 0.56.0*
*Since 1.7.0* [Meson devenv][Commands.md#devenv] setup `PATH` and
`LD_LIBRARY_PATH` to be able to run programs.

## Functions

Expand Down Expand Up @@ -78,7 +81,8 @@ Keyword arguments:
added in case some tags are not found in `configure_options`:
`'--prefix=@PREFIX@'`, `'--libdir=@PREFIX@/@LIBDIR@'`, and
`'--includedir=@PREFIX@/@INCLUDEDIR@'`. It was previously considered a fatal
error to not specify them.
error to not specify them. *Since 1.7.0* `@BINDIR@` and `'--bindir=@PREFIX@/@BINDIR@'`
default argument have been added.
- `cross_configure_options`: Extra options appended to `configure_options` only
when cross compiling. special tag `@HOST@` will be replaced by
`'{}-{}-{}'.format(host_machine.cpu_family(), build_machine.system(), host_machine.system()`.
Expand Down
7 changes: 7 additions & 0 deletions docs/markdown/snippets/external_project_devenv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Devenv support in external project module

The [external project module](External-Project-module.md) now setups `PATH` and
`LD_LIBRARY_PATH` to be able to run programs.

`@BINDIR@` is now substitued in arguments and `'--bindir=@PREFIX@/@BINDIR@'`
default argument have been added.
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
16 changes: 16 additions & 0 deletions mesonbuild/modules/external_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def __init__(self,
_l = self.env.coredata.get_option(OptionKey('libdir'))
assert isinstance(_l, str), 'for mypy'
self.libdir = Path(_l)
_l = self.env.coredata.get_option(OptionKey('bindir'))
assert isinstance(_l, str), 'for mypy'
self.bindir = Path(_l)
_i = self.env.coredata.get_option(OptionKey('includedir'))
assert isinstance(_i, str), 'for mypy'
self.includedir = Path(_i)
Expand Down Expand Up @@ -118,6 +121,7 @@ def _configure(self, state: 'ModuleState') -> None:

d = [('PREFIX', '--prefix=@PREFIX@', self.prefix.as_posix()),
('LIBDIR', '--libdir=@PREFIX@/@LIBDIR@', self.libdir.as_posix()),
('BINDIR', '--bindir=@PREFIX@/@BINDIR@', self.bindir.as_posix()),
('INCLUDEDIR', None, self.includedir.as_posix()),
]
self._validate_configure_options(d, state)
Expand Down Expand Up @@ -278,6 +282,7 @@ class ExternalProjectModule(ExtensionModule):

def __init__(self, interpreter: 'Interpreter'):
super().__init__(interpreter)
self.devenv: T.Optional[EnvironmentVariables] = None
self.methods.update({'add_project': self.add_project,
})

Expand All @@ -299,8 +304,19 @@ def add_project(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'AddProj
kwargs['env'],
kwargs['verbose'],
kwargs['depends'])
abs_libdir = Path(project.install_dir, project.rel_prefix, project.libdir).as_posix()
abs_bindir = Path(project.install_dir, project.rel_prefix, project.bindir).as_posix()
env = state.environment.get_env_for_paths({abs_libdir}, {abs_bindir})
if self.devenv is None:
self.devenv = env
else:
self.devenv.merge(env)
return ModuleReturnValue(project, project.targets)

def postconf_hook(self, b: build.Build) -> None:
if self.devenv is not None:
b.devenv.append(self.devenv)


def initialize(interp: 'Interpreter') -> ExternalProjectModule:
return ExternalProjectModule(interp)
Loading