Cache the scripts used for postconf and install phases

Cache the absolute dir that the script is searched in and the name of
the script. These are the only two things that change.

Update the test to test for both #1235 and the case when a script of the
same name is in a different directory (which also covers the subproject
case).

Closes #1235
pull/1239/head
Nirbheek Chauhan 8 years ago committed by Jussi Pakkanen
parent 9bc07a0941
commit 589a56e78f
  1. 2
      mesonbuild/backend/backends.py
  2. 4
      mesonbuild/build.py
  3. 34
      mesonbuild/interpreter.py
  4. 4
      mesonbuild/modules/gnome.py
  5. 2
      mesonbuild/modules/i18n.py
  6. 2
      test cases/common/60 install script/installed_files.txt
  7. 3
      test cases/common/60 install script/meson.build
  8. 1
      test cases/common/60 install script/src/meson.build
  9. 12
      test cases/common/60 install script/src/myinstall.py

@ -641,7 +641,7 @@ class Backend():
child_env.update(env)
for s in self.build.postconf_scripts:
cmd = s['exe'].get_command() + s['args']
cmd = s['exe'] + s['args']
subprocess.check_call(cmd, env=child_env)
# Subprojects of subprojects may cause the same dep args to be used

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

@ -987,6 +987,7 @@ class MesonMain(InterpreterObject):
InterpreterObject.__init__(self)
self.build = build
self.interpreter = interpreter
self._found_source_scripts = {}
self.methods.update({'get_compiler': self.get_compiler_method,
'is_cross_build' : self.is_cross_build_method,
'has_exe_wrapper' : self.has_exe_wrapper_method,
@ -1006,27 +1007,34 @@ class MesonMain(InterpreterObject):
'backend' : self.backend_method,
})
def _find_source_script(self, name, args):
# Prefer scripts in the current source directory
search_dir = os.path.join(self.interpreter.environment.source_dir,
self.interpreter.subdir)
key = (name, search_dir)
if key in self._found_source_scripts:
found = self._found_source_scripts[key]
else:
found = dependencies.ExternalProgram(name, search_dir=search_dir)
if found:
self._found_source_scripts[key] = found
else:
raise InterpreterException('Script {!r} not found'.format(name))
return build.RunScript(found.get_command(), args)
def add_install_script_method(self, args, kwargs):
if len(args) < 1:
raise InterpreterException('add_install_script takes one or more arguments')
check_stringlist(args, 'add_install_script args must be strings')
scriptbase = args[0]
search_dir = os.path.join(self.interpreter.environment.source_dir,
self.interpreter.subdir)
script = dependencies.ExternalProgram(scriptbase, search_dir=search_dir)
extras = args[1:]
self.build.install_scripts.append({'exe': script.get_command(), 'args': extras})
script = self._find_source_script(args[0], args[1:])
self.build.install_scripts.append(script)
def add_postconf_script_method(self, args, kwargs):
if len(args) < 1:
raise InterpreterException('add_postconf_script takes one or more arguments')
check_stringlist(args, 'add_postconf_script arguments must be strings')
scriptbase = args[0]
search_dir = os.path.join(self.interpreter.environment.source_dir,
self.interpreter.subdir)
script = dependencies.ExternalProgram(scriptbase, search_dir=search_dir)
extras = args[1:]
self.build.postconf_scripts.append({'exe': script, 'args': extras})
script = self._find_source_script(args[0], args[1:])
self.build.postconf_scripts.append(script)
def current_source_dir_method(self, args, kwargs):
src = self.interpreter.environment.source_dir
@ -1236,7 +1244,7 @@ class Interpreter(InterpreterBase):
outvalues.append(GeneratedListHolder(v))
elif isinstance(v, build.RunTarget):
self.add_target(v.name, v)
elif isinstance(v, build.InstallScript):
elif isinstance(v, build.RunScript):
self.build.install_scripts.append(v)
elif isinstance(v, build.Data):
self.build.data.append(v)

@ -615,7 +615,7 @@ can not be used with the current version of glib-compiled-resources, due to
args.append('--media=' + '@@'.join(media))
if langs:
args.append('--langs=' + '@@'.join(langs))
inscript = build.InstallScript(script, args)
inscript = build.RunScript(script, args)
potargs = [state.environment.get_build_command(), '--internal', 'yelphelper', 'pot',
'--subdir=' + state.subdir,
@ -699,7 +699,7 @@ can not be used with the current version of glib-compiled-resources, due to
args += self._get_build_args(kwargs, state)
res = [build.RunTarget(targetname, command[0], command[1:] + args, [], state.subdir)]
if kwargs.get('install', True):
res.append(build.InstallScript(command, args))
res.append(build.RunScript(command, args))
return res
def _get_build_args(self, kwargs, state):

@ -109,7 +109,7 @@ class I18nModule:
pkg_arg]
if lang_arg:
args.append(lang_arg)
iscript = build.InstallScript(script, args)
iscript = build.RunScript(script, args)
return [pottarget, gmotarget, iscript, updatepotarget]

@ -1,2 +1,4 @@
usr/bin/prog?exe
usr/diiba/daaba/file.dat
usr/this/should/also-work.dat
usr/this/does/something-different.dat.in

@ -2,3 +2,6 @@ project('custom install script', 'c')
executable('prog', 'prog.c', install : true)
meson.add_install_script('myinstall.py', 'diiba/daaba', 'file.dat')
meson.add_install_script('myinstall.py', 'this/should', 'also-work.dat')
subdir('src')

@ -0,0 +1 @@
meson.add_install_script('myinstall.py', 'this/does', 'something-different.dat')

@ -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] + '.in'), 'w') as f:
f.write('')
Loading…
Cancel
Save