Skip to content

Commit 589a56e

Browse files
nirbheekjpakkane
authored andcommitted
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
1 parent 9bc07a0 commit 589a56e

File tree

9 files changed

+45
-19
lines changed

9 files changed

+45
-19
lines changed

mesonbuild/backend/backends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def run_postconf_scripts(self):
641641
child_env.update(env)
642642

643643
for s in self.build.postconf_scripts:
644-
cmd = s['exe'].get_command() + s['args']
644+
cmd = s['exe'] + s['args']
645645
subprocess.check_call(cmd, env=child_env)
646646

647647
# Subprojects of subprojects may cause the same dep args to be used

mesonbuild/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,9 +1482,9 @@ def __init__(self, sources, install_dir):
14821482
for s in self.sources:
14831483
assert(isinstance(s, File))
14841484

1485-
class InstallScript(dict):
1485+
class RunScript(dict):
14861486
def __init__(self, script, args):
1487-
super(InstallScript, self).__init__()
1487+
super().__init__()
14881488
assert(isinstance(script, list))
14891489
assert(isinstance(args, list))
14901490
self['exe'] = script

mesonbuild/interpreter.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ def __init__(self, build, interpreter):
987987
InterpreterObject.__init__(self)
988988
self.build = build
989989
self.interpreter = interpreter
990+
self._found_source_scripts = {}
990991
self.methods.update({'get_compiler': self.get_compiler_method,
991992
'is_cross_build' : self.is_cross_build_method,
992993
'has_exe_wrapper' : self.has_exe_wrapper_method,
@@ -1006,27 +1007,34 @@ def __init__(self, build, interpreter):
10061007
'backend' : self.backend_method,
10071008
})
10081009

1010+
def _find_source_script(self, name, args):
1011+
# Prefer scripts in the current source directory
1012+
search_dir = os.path.join(self.interpreter.environment.source_dir,
1013+
self.interpreter.subdir)
1014+
key = (name, search_dir)
1015+
if key in self._found_source_scripts:
1016+
found = self._found_source_scripts[key]
1017+
else:
1018+
found = dependencies.ExternalProgram(name, search_dir=search_dir)
1019+
if found:
1020+
self._found_source_scripts[key] = found
1021+
else:
1022+
raise InterpreterException('Script {!r} not found'.format(name))
1023+
return build.RunScript(found.get_command(), args)
1024+
10091025
def add_install_script_method(self, args, kwargs):
10101026
if len(args) < 1:
10111027
raise InterpreterException('add_install_script takes one or more arguments')
10121028
check_stringlist(args, 'add_install_script args must be strings')
1013-
scriptbase = args[0]
1014-
search_dir = os.path.join(self.interpreter.environment.source_dir,
1015-
self.interpreter.subdir)
1016-
script = dependencies.ExternalProgram(scriptbase, search_dir=search_dir)
1017-
extras = args[1:]
1018-
self.build.install_scripts.append({'exe': script.get_command(), 'args': extras})
1029+
script = self._find_source_script(args[0], args[1:])
1030+
self.build.install_scripts.append(script)
10191031

10201032
def add_postconf_script_method(self, args, kwargs):
10211033
if len(args) < 1:
10221034
raise InterpreterException('add_postconf_script takes one or more arguments')
10231035
check_stringlist(args, 'add_postconf_script arguments must be strings')
1024-
scriptbase = args[0]
1025-
search_dir = os.path.join(self.interpreter.environment.source_dir,
1026-
self.interpreter.subdir)
1027-
script = dependencies.ExternalProgram(scriptbase, search_dir=search_dir)
1028-
extras = args[1:]
1029-
self.build.postconf_scripts.append({'exe': script, 'args': extras})
1036+
script = self._find_source_script(args[0], args[1:])
1037+
self.build.postconf_scripts.append(script)
10301038

10311039
def current_source_dir_method(self, args, kwargs):
10321040
src = self.interpreter.environment.source_dir
@@ -1236,7 +1244,7 @@ def module_method_callback(self, invalues):
12361244
outvalues.append(GeneratedListHolder(v))
12371245
elif isinstance(v, build.RunTarget):
12381246
self.add_target(v.name, v)
1239-
elif isinstance(v, build.InstallScript):
1247+
elif isinstance(v, build.RunScript):
12401248
self.build.install_scripts.append(v)
12411249
elif isinstance(v, build.Data):
12421250
self.build.data.append(v)

mesonbuild/modules/gnome.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ def yelp(self, state, args, kwargs):
615615
args.append('--media=' + '@@'.join(media))
616616
if langs:
617617
args.append('--langs=' + '@@'.join(langs))
618-
inscript = build.InstallScript(script, args)
618+
inscript = build.RunScript(script, args)
619619

620620
potargs = [state.environment.get_build_command(), '--internal', 'yelphelper', 'pot',
621621
'--subdir=' + state.subdir,
@@ -699,7 +699,7 @@ def gtkdoc(self, state, args, kwargs):
699699
args += self._get_build_args(kwargs, state)
700700
res = [build.RunTarget(targetname, command[0], command[1:] + args, [], state.subdir)]
701701
if kwargs.get('install', True):
702-
res.append(build.InstallScript(command, args))
702+
res.append(build.RunScript(command, args))
703703
return res
704704

705705
def _get_build_args(self, kwargs, state):

mesonbuild/modules/i18n.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def gettext(self, state, args, kwargs):
109109
pkg_arg]
110110
if lang_arg:
111111
args.append(lang_arg)
112-
iscript = build.InstallScript(script, args)
112+
iscript = build.RunScript(script, args)
113113

114114
return [pottarget, gmotarget, iscript, updatepotarget]
115115

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
usr/bin/prog?exe
22
usr/diiba/daaba/file.dat
3+
usr/this/should/also-work.dat
4+
usr/this/does/something-different.dat.in

test cases/common/60 install script/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ project('custom install script', 'c')
22

33
executable('prog', 'prog.c', install : true)
44
meson.add_install_script('myinstall.py', 'diiba/daaba', 'file.dat')
5+
meson.add_install_script('myinstall.py', 'this/should', 'also-work.dat')
6+
7+
subdir('src')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
meson.add_install_script('myinstall.py', 'this/does', 'something-different.dat')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import sys
5+
6+
prefix = os.environ['MESON_INSTALL_DESTDIR_PREFIX']
7+
8+
dirname = os.path.join(prefix, sys.argv[1])
9+
10+
os.makedirs(dirname)
11+
with open(os.path.join(dirname, sys.argv[2] + '.in'), 'w') as f:
12+
f.write('')

0 commit comments

Comments
 (0)