From 44618a84fd5ad23ee58917693bd3e91f6dd86510 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sat, 26 Oct 2024 17:49:10 -0400 Subject: [PATCH] external-project: Setup devenv to run programs --- docs/markdown/External-Project-module.md | 8 ++++++-- .../markdown/snippets/external_project_devenv.md | 7 +++++++ mesonbuild/modules/external_project.py | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 docs/markdown/snippets/external_project_devenv.md diff --git a/docs/markdown/External-Project-module.md b/docs/markdown/External-Project-module.md index 615c6c117d0c..39449fe21102 100644 --- a/docs/markdown/External-Project-module.md +++ b/docs/markdown/External-Project-module.md @@ -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 @@ -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 @@ -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()`. diff --git a/docs/markdown/snippets/external_project_devenv.md b/docs/markdown/snippets/external_project_devenv.md new file mode 100644 index 000000000000..1927bd32f4e9 --- /dev/null +++ b/docs/markdown/snippets/external_project_devenv.md @@ -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. diff --git a/mesonbuild/modules/external_project.py b/mesonbuild/modules/external_project.py index fb82a384d919..9e283e026b36 100644 --- a/mesonbuild/modules/external_project.py +++ b/mesonbuild/modules/external_project.py @@ -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) @@ -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) @@ -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, }) @@ -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)