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.
pull/11530/head
Eli Schwartz 2 years ago
parent 7c78c2b5a0
commit 6823cabb83
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 5
      mesonbuild/backend/backends.py
  2. 13
      mesonbuild/minstall.py
  3. 1
      mesonbuild/utils/core.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]],

@ -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

@ -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

Loading…
Cancel
Save