Skip to content

Commit

Permalink
external-project: Setup devenv to run programs
Browse files Browse the repository at this point in the history
  • Loading branch information
xclaesse committed Oct 26, 2024
1 parent a0632b7 commit 0ca2b2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
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.
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)

0 comments on commit 0ca2b2a

Please sign in to comment.