Allow passing arguments to install scripts

Closes #1213
pull/1046/merge
Nirbheek Chauhan 8 years ago committed by Jussi Pakkanen
parent 67c106a001
commit c693bd9bb4
  1. 11
      mesonbuild/build.py
  2. 24
      mesonbuild/interpreter.py
  3. 23
      mesonbuild/modules/gnome.py
  4. 14
      mesonbuild/modules/i18n.py
  5. 27
      mesonbuild/scripts/meson_install.py
  6. 8
      test cases/common/60 install script/meson.build
  7. 12
      test cases/common/60 install script/myinstall.py
  8. 10
      test cases/common/60 install script/myinstall.sh

@ -1482,7 +1482,10 @@ class Data():
for s in self.sources: for s in self.sources:
assert(isinstance(s, File)) assert(isinstance(s, File))
class InstallScript: class InstallScript(dict):
def __init__(self, cmd_arr): def __init__(self, script, args):
assert(isinstance(cmd_arr, list)) super(InstallScript, self).__init__()
self.cmd_arr = cmd_arr assert(isinstance(script, list))
assert(isinstance(args, list))
self['exe'] = script
self['args'] = args

@ -1007,26 +1007,26 @@ class MesonMain(InterpreterObject):
}) })
def add_install_script_method(self, args, kwargs): def add_install_script_method(self, args, kwargs):
if len(args) != 1: if len(args) < 1:
raise InterpreterException('Set_install_script takes exactly one argument.') raise InterpreterException('add_install_script takes one or more arguments')
check_stringlist(args) check_stringlist(args, 'add_install_script args must be strings')
scriptbase = args[0] scriptbase = args[0]
scriptfile = os.path.join(self.interpreter.environment.source_dir, search_dir = os.path.join(self.interpreter.environment.source_dir,
self.interpreter.subdir, scriptbase) self.interpreter.subdir)
if not os.path.isfile(scriptfile): script = dependencies.ExternalProgram(scriptbase, search_dir=search_dir)
raise InterpreterException('Can not find install script %s.' % scriptbase) extras = args[1:]
self.build.install_scripts.append(build.InstallScript([scriptfile])) self.build.install_scripts.append({'exe': script.get_command(), 'args': extras})
def add_postconf_script_method(self, args, kwargs): def add_postconf_script_method(self, args, kwargs):
if len(args) < 1: if len(args) < 1:
raise InterpreterException('Not enough arguments') raise InterpreterException('add_postconf_script takes one or more arguments')
check_stringlist(args, 'add_postconf_script arguments must be strings.') check_stringlist(args, 'add_postconf_script arguments must be strings')
scriptbase = args[0] scriptbase = args[0]
search_dir = os.path.join(self.interpreter.environment.source_dir, search_dir = os.path.join(self.interpreter.environment.source_dir,
self.interpreter.subdir) self.interpreter.subdir)
exe = dependencies.ExternalProgram(scriptbase, search_dir=search_dir) script = dependencies.ExternalProgram(scriptbase, search_dir=search_dir)
extras = args[1:] extras = args[1:]
self.build.postconf_scripts.append({'exe': exe, 'args': extras}) self.build.postconf_scripts.append({'exe': script, 'args': extras})
def current_source_dir_method(self, args, kwargs): def current_source_dir_method(self, args, kwargs):
src = self.interpreter.environment.source_dir src = self.interpreter.environment.source_dir

@ -599,10 +599,8 @@ can not be used with the current version of glib-compiled-resources, due to
if kwargs: if kwargs:
raise MesonException('Unknown arguments passed: {}'.format(', '.join(kwargs.keys()))) raise MesonException('Unknown arguments passed: {}'.format(', '.join(kwargs.keys())))
install_cmd = [ script = [sys.executable, state.environment.get_build_command()]
sys.executable, args = ['--internal',
state.environment.get_build_command(),
'--internal',
'yelphelper', 'yelphelper',
'install', 'install',
'--subdir=' + state.subdir, '--subdir=' + state.subdir,
@ -611,12 +609,12 @@ can not be used with the current version of glib-compiled-resources, due to
'--sources=' + source_str, '--sources=' + source_str,
] ]
if symlinks: if symlinks:
install_cmd.append('--symlinks=true') args.append('--symlinks=true')
if media: if media:
install_cmd.append('--media=' + '@@'.join(media)) args.append('--media=' + '@@'.join(media))
if langs: if langs:
install_cmd.append('--langs=' + '@@'.join(langs)) args.append('--langs=' + '@@'.join(langs))
inscript = build.InstallScript(install_cmd) inscript = build.InstallScript(script, args)
potargs = [state.environment.get_build_command(), '--internal', 'yelphelper', 'pot', potargs = [state.environment.get_build_command(), '--internal', 'yelphelper', 'pot',
'--subdir=' + state.subdir, '--subdir=' + state.subdir,
@ -654,7 +652,7 @@ can not be used with the current version of glib-compiled-resources, due to
raise MesonException('You can only specify main_xml or main_sgml, not both.') raise MesonException('You can only specify main_xml or main_sgml, not both.')
main_file = main_xml main_file = main_xml
targetname = modulename + '-doc' targetname = modulename + '-doc'
command = [state.environment.get_build_command(), '--internal', 'gtkdoc'] command = [sys.executable, state.environment.get_build_command()]
namespace = kwargs.get('namespace', '') namespace = kwargs.get('namespace', '')
mode = kwargs.get('mode', 'auto') mode = kwargs.get('mode', 'auto')
@ -677,7 +675,8 @@ can not be used with the current version of glib-compiled-resources, due to
else: else:
header_dirs.append(src_dir) header_dirs.append(src_dir)
args = ['--sourcedir=' + state.environment.get_source_dir(), args = ['--internal', 'gtkdoc',
'--sourcedir=' + state.environment.get_source_dir(),
'--builddir=' + state.environment.get_build_dir(), '--builddir=' + state.environment.get_build_dir(),
'--subdir=' + state.subdir, '--subdir=' + state.subdir,
'--headerdirs=' + '@@'.join(header_dirs), '--headerdirs=' + '@@'.join(header_dirs),
@ -697,9 +696,9 @@ can not be used with the current version of glib-compiled-resources, due to
args += self._unpack_args('--ignore-headers=', 'ignore_headers', kwargs) args += self._unpack_args('--ignore-headers=', 'ignore_headers', kwargs)
args += self._unpack_args('--installdir=', 'install_dir', kwargs, state) args += self._unpack_args('--installdir=', 'install_dir', kwargs, state)
args += self._get_build_args(kwargs, state) args += self._get_build_args(kwargs, state)
res = [build.RunTarget(targetname, command[0], command[1:] + args, [], state.subdir)] res = [build.RunTarget(targetname, command[0], command[1:] + sargs, [], state.subdir)]
if kwargs.get('install', True): if kwargs.get('install', True):
res.append(build.InstallScript(command + args)) res.append(build.InstallScript(command, args))
return res return res
def _get_build_args(self, kwargs, state): def _get_build_args(self, kwargs, state):

@ -102,14 +102,14 @@ class I18nModule:
updatepoargs.append(extra_args) updatepoargs.append(extra_args)
updatepotarget = build.RunTarget(packagename + '-update-po', sys.executable, updatepoargs, [], state.subdir) updatepotarget = build.RunTarget(packagename + '-update-po', sys.executable, updatepoargs, [], state.subdir)
installcmd = [sys.executable, state.environment.get_build_command(), script = [sys.executable, state.environment.get_build_command()]
'--internal', 'gettext', 'install', args = ['--internal', 'gettext', 'install',
'--subdir=' + state.subdir, '--subdir=' + state.subdir,
'--localedir=' + state.environment.coredata.get_builtin_option('localedir'), '--localedir=' + state.environment.coredata.get_builtin_option('localedir'),
pkg_arg] pkg_arg]
if lang_arg: if lang_arg:
installcmd.append(lang_arg) args.append(lang_arg)
iscript = build.InstallScript(installcmd) iscript = build.InstallScript(script, args)
return [pottarget, gmotarget, iscript, updatepotarget] return [pottarget, gmotarget, iscript, updatepotarget]

@ -132,34 +132,23 @@ def install_headers(d):
def run_install_script(d): def run_install_script(d):
env = {'MESON_SOURCE_ROOT' : d.source_dir, env = {'MESON_SOURCE_ROOT' : d.source_dir,
'MESON_BUILD_ROOT' : d.build_dir, 'MESON_BUILD_ROOT' : d.build_dir,
'MESON_INSTALL_PREFIX' : d.prefix 'MESON_INSTALL_PREFIX' : d.prefix,
'MESON_INSTALL_DESTDIR_PREFIX' : d.fullprefix,
} }
child_env = os.environ.copy() child_env = os.environ.copy()
child_env.update(env) child_env.update(env)
for i in d.install_scripts: for i in d.install_scripts:
final_command = i.cmd_arr script = i['exe']
script = i.cmd_arr[0] args = i['args']
print('Running custom install script %s' % script) name = ' '.join(script + args)
suffix = os.path.splitext(script)[1].lower() print('Running custom install script {!r}'.format(name))
if platform.system().lower() == 'windows' and suffix != '.bat':
with open(script, encoding='latin_1', errors='ignore') as f:
first_line = f.readline().strip()
if first_line.startswith('#!'):
if shutil.which(first_line[2:]):
commands = [first_line[2:]]
else:
commands = first_line[2:].split('#')[0].strip().split()
commands[0] = shutil.which(commands[0].split('/')[-1])
if commands[0] is None:
raise RuntimeError("Don't know how to run script %s." % script)
final_command = commands + [script] + i.cmd_arr[1:]
try: try:
rc = subprocess.call(final_command, env=child_env) rc = subprocess.call(script + args, env=child_env)
if rc != 0: if rc != 0:
sys.exit(rc) sys.exit(rc)
except: except:
print('Failed to run install script:', *i.cmd_arr) print('Failed to run install script {!r}'.format(name))
sys.exit(1) sys.exit(1)
def is_elf_platform(): def is_elf_platform():

@ -1,8 +1,4 @@
project('custom install script', 'c') project('custom install script', 'c')
if meson.get_compiler('c').get_id() == 'msvc' executable('prog', 'prog.c', install : true)
install_data('no-installed-files', install_dir : '') meson.add_install_script('myinstall.py', 'diiba/daaba', 'file.dat')
else
meson.add_install_script('myinstall.sh')
executable('prog', 'prog.c', install : true)
endif

@ -0,0 +1,12 @@
#!/usr/bin/env python
import os
import sys
prefix = os.environ['MESON_INSTALL_DESTDIR_PREFIX']
dirname = os.path.join(prefix, sys.argv[1])
os.makedirs(dirname)
with open(os.path.join(dirname, sys.argv[2]), 'w') as f:
f.write('')

@ -1,10 +0,0 @@
#!/bin/sh
set -eu
echo Starting custom installation step
mkdir -p "${DESTDIR}${MESON_INSTALL_PREFIX}/diiba/daaba"
touch "${DESTDIR}${MESON_INSTALL_PREFIX}/diiba/daaba/file.dat"
echo Finished custom install step
Loading…
Cancel
Save