aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2018-03-17 20:21:46 +0200
committerNirbheek Chauhan <nirbheek@centricular.com>2018-04-15 13:32:38 +0530
commit4256c0dae2e4793a486ef38eec4361639dbb2957 (patch)
tree31d627c164f943fc966b0f17c9fa95efe786e18e
parentbdb57cf62a56e292d3ebf9f4ba39be07674707f8 (diff)
downloadmeson-4256c0dae2e4793a486ef38eec4361639dbb2957.zip
meson-4256c0dae2e4793a486ef38eec4361639dbb2957.tar.gz
meson-4256c0dae2e4793a486ef38eec4361639dbb2957.tar.bz2
Can override programs with scripts generated with configure_file.
-rw-r--r--mesonbuild/interpreter.py6
-rw-r--r--test cases/common/182 find override/otherdir/main2.c5
-rw-r--r--test cases/common/182 find override/otherdir/meson.build15
-rw-r--r--test cases/common/182 find override/otherdir/source2.desc1
-rwxr-xr-xtest cases/common/182 find override/subdir/converter.py2
-rwxr-xr-xtest cases/common/182 find override/subdir/gencodegen.py.in15
-rw-r--r--test cases/common/182 find override/subdir/meson.build11
7 files changed, 54 insertions, 1 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index c958b6f..9d3a669 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 0000000..6d71688
--- /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 84e7e84..dc41f5b 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 0000000..965f868
--- /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 55b2a70..ee2ff85 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 0000000..57d9c40
--- /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 0d1f9d0..e5de34d 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)