From 6823cabb83c77fa19ebf594acceea7314b9e8fd7 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 16 Apr 2023 23:08:05 -0400 Subject: [PATCH] extend install scripts to allow specific directory variable exports This is useful for internal scripts that want to know about something other than MESON_INSTALL_PREFIX and MESON_INSTALL_DESTDIR_PREFIX, which is very specific to the prefix. --- mesonbuild/backend/backends.py | 5 +++-- mesonbuild/minstall.py | 13 ++++++++++--- mesonbuild/utils/core.py | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 4972eabad..a13c0ec88 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -499,7 +499,8 @@ class Backend: feed: T.Optional[bool] = None, env: T.Optional[build.EnvironmentVariables] = None, tag: T.Optional[str] = None, - verbose: bool = False) -> 'ExecutableSerialisation': + verbose: bool = False, + installdir_map: T.Optional[T.Dict[str, str]] = None) -> 'ExecutableSerialisation': # XXX: cmd_args either need to be lowered to strings, or need to be checked for non-string arguments, right? exe, *raw_cmd_args = cmd @@ -560,7 +561,7 @@ class Backend: workdir = workdir or self.environment.get_build_dir() return ExecutableSerialisation(exe_cmd + cmd_args, env, exe_wrapper, workdir, - extra_paths, capture, feed, tag, verbose) + extra_paths, capture, feed, tag, verbose, installdir_map) def as_meson_exe_cmdline(self, exe: T.Union[str, mesonlib.File, build.BuildTarget, build.CustomTarget, programs.ExternalProgram], cmd_args: T.Sequence[T.Union[str, mesonlib.File, build.BuildTarget, build.CustomTarget, programs.ExternalProgram]], diff --git a/mesonbuild/minstall.py b/mesonbuild/minstall.py index b9fe7d58d..ec01fe729 100644 --- a/mesonbuild/minstall.py +++ b/mesonbuild/minstall.py @@ -672,8 +672,6 @@ class Installer: def run_install_script(self, d: InstallData, destdir: str, fullprefix: str) -> None: env = {'MESON_SOURCE_ROOT': d.source_dir, 'MESON_BUILD_ROOT': d.build_dir, - 'MESON_INSTALL_PREFIX': d.prefix, - 'MESON_INSTALL_DESTDIR_PREFIX': fullprefix, 'MESONINTROSPECT': ' '.join([shlex.quote(x) for x in d.mesonintrospect]), } if self.options.quiet: @@ -684,6 +682,15 @@ class Installer: for i in d.install_scripts: if not self.should_install(i): continue + + if i.installdir_map is not None: + mapp = i.installdir_map + else: + mapp = {'prefix': d.prefix} + localenv = env.copy() + localenv.update({'MESON_INSTALL_'+k.upper(): os.path.join(d.prefix, v) for k, v in mapp.items()}) + localenv.update({'MESON_INSTALL_DESTDIR_'+k.upper(): get_destdir_path(destdir, fullprefix, v) for k, v in mapp.items()}) + name = ' '.join(i.cmd_args) if i.skip_if_destdir and destdir: self.log(f'Skipping custom install script because DESTDIR is set {name!r}') @@ -691,7 +698,7 @@ class Installer: self.did_install_something = True # Custom script must report itself if it does nothing. self.log(f'Running custom install script {name!r}') try: - rc = self.run_exe(i, env) + rc = self.run_exe(i, localenv) except OSError: print(f'FAILED: install script \'{name}\' could not be run, stopped') # POSIX shells return 127 when a command could not be found diff --git a/mesonbuild/utils/core.py b/mesonbuild/utils/core.py index 03a8c6314..eee88b94d 100644 --- a/mesonbuild/utils/core.py +++ b/mesonbuild/utils/core.py @@ -152,6 +152,7 @@ class ExecutableSerialisation: feed: T.Optional[bool] = None tag: T.Optional[str] = None verbose: bool = False + installdir_map: T.Optional[T.Dict[str, str]] = None def __post_init__(self) -> None: self.pickled = False