aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2016-12-20 02:01:24 +0530
committerJussi Pakkanen <jpakkane@gmail.com>2016-12-20 00:09:02 +0200
commit589a56e78f37861ddf920ae0aa4710b409131fb7 (patch)
tree1ddd071328349f2c794b05d1ce64b61b91c72d41 /mesonbuild/interpreter.py
parent9bc07a09412b6ea1ff5e558e97478941b6cbfd18 (diff)
downloadmeson-589a56e78f37861ddf920ae0aa4710b409131fb7.zip
meson-589a56e78f37861ddf920ae0aa4710b409131fb7.tar.gz
meson-589a56e78f37861ddf920ae0aa4710b409131fb7.tar.bz2
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
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r--mesonbuild/interpreter.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 2bef595..7e55b88 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -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)