From 4256c0dae2e4793a486ef38eec4361639dbb2957 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 17 Mar 2018 20:21:46 +0200 Subject: [PATCH] Can override programs with scripts generated with configure_file. --- mesonbuild/interpreter.py | 6 ++++++ .../common/182 find override/otherdir/main2.c | 5 +++++ .../common/182 find override/otherdir/meson.build | 15 +++++++++++++++ .../182 find override/otherdir/source2.desc | 1 + .../common/182 find override/subdir/converter.py | 2 +- .../182 find override/subdir/gencodegen.py.in | 15 +++++++++++++++ .../common/182 find override/subdir/meson.build | 11 +++++++++++ 7 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 test cases/common/182 find override/otherdir/main2.c create mode 100644 test cases/common/182 find override/otherdir/source2.desc create mode 100755 test cases/common/182 find override/subdir/gencodegen.py.in diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index c958b6fba..9d3a66968 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1426,6 +1426,12 @@ class MesonMain(InterpreterObject): raise InterpreterException('First argument must be a string') if hasattr(exe, 'held_object'): exe = exe.held_object + if isinstance(exe, mesonlib.File): + abspath = exe.absolute_path(self.interpreter.environment.source_dir, + self.interpreter.environment.build_dir) + if not os.path.exists(abspath): + raise InterpreterException('Tried to override %s with a file that does not exist.' % name) + exe = dependencies.ExternalProgram(abspath) if not isinstance(exe, dependencies.ExternalProgram): # FIXME, make this work if the exe is an Executable target. raise InterpreterException('Second argument must be an external program.') diff --git a/test cases/common/182 find override/otherdir/main2.c b/test cases/common/182 find override/otherdir/main2.c new file mode 100644 index 000000000..6d716882c --- /dev/null +++ b/test cases/common/182 find override/otherdir/main2.c @@ -0,0 +1,5 @@ +int number_returner(); + +int main(int argc, char **argv) { + return number_returner() == 100 ? 0 : 1; +} diff --git a/test cases/common/182 find override/otherdir/meson.build b/test cases/common/182 find override/otherdir/meson.build index 84e7e84e8..dc41f5bf7 100644 --- a/test cases/common/182 find override/otherdir/meson.build +++ b/test cases/common/182 find override/otherdir/meson.build @@ -9,3 +9,18 @@ src = custom_target('arrival', e = executable('six', 'main.c', src) test('six', e) + +# The same again, but this time with a program that was genererated +# with configure_file. + +gen = find_program('gencodegen') + +src = custom_target('hundred', + input : 'source2.desc', + output : 'file2.c', + command : [gen, '@INPUT@', '@OUTPUT@'] + ) + +e = executable('hundred', 'main2.c', src) + +test('hundred', e) diff --git a/test cases/common/182 find override/otherdir/source2.desc b/test cases/common/182 find override/otherdir/source2.desc new file mode 100644 index 000000000..965f868df --- /dev/null +++ b/test cases/common/182 find override/otherdir/source2.desc @@ -0,0 +1 @@ +number_returner diff --git a/test cases/common/182 find override/subdir/converter.py b/test cases/common/182 find override/subdir/converter.py index 55b2a7071..ee2ff85a3 100755 --- a/test cases/common/182 find override/subdir/converter.py +++ b/test cases/common/182 find override/subdir/converter.py @@ -12,4 +12,4 @@ ftempl = '''int %s() { d = pathlib.Path(ifilename).read_text().split('\n')[0].strip() -pathlib.Path(ofilename).write_text(ftempl % d) \ No newline at end of file +pathlib.Path(ofilename).write_text(ftempl % d) diff --git a/test cases/common/182 find override/subdir/gencodegen.py.in b/test cases/common/182 find override/subdir/gencodegen.py.in new file mode 100755 index 000000000..57d9c40b4 --- /dev/null +++ b/test cases/common/182 find override/subdir/gencodegen.py.in @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + +import sys +import pathlib + +[ifilename, ofilename] = sys.argv[1:3] + +ftempl = '''int %s() { + return @NUMBER@; +} +''' + +d = pathlib.Path(ifilename).read_text().split('\n')[0].strip() + +pathlib.Path(ofilename).write_text(ftempl % d) diff --git a/test cases/common/182 find override/subdir/meson.build b/test cases/common/182 find override/subdir/meson.build index 0d1f9d03b..e5de34dde 100644 --- a/test cases/common/182 find override/subdir/meson.build +++ b/test cases/common/182 find override/subdir/meson.build @@ -1,3 +1,14 @@ x = find_program('converter.py') meson.override_find_program('codegen', x) + +# Override a command with a generated script + +cdata = configuration_data() + +cdata.set('NUMBER', 100) +numprog = configure_file(input : 'gencodegen.py.in', + output : 'gencodegen.py', + configuration : cdata) + +meson.override_find_program('gencodegen', numprog)