Can override programs with scripts generated with configure_file.

pull/3218/head
Jussi Pakkanen 7 years ago committed by Nirbheek Chauhan
parent bdb57cf62a
commit 4256c0dae2
  1. 6
      mesonbuild/interpreter.py
  2. 5
      test cases/common/182 find override/otherdir/main2.c
  3. 15
      test cases/common/182 find override/otherdir/meson.build
  4. 1
      test cases/common/182 find override/otherdir/source2.desc
  5. 2
      test cases/common/182 find override/subdir/converter.py
  6. 15
      test cases/common/182 find override/subdir/gencodegen.py.in
  7. 11
      test cases/common/182 find override/subdir/meson.build

@ -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.')

@ -0,0 +1,5 @@
int number_returner();
int main(int argc, char **argv) {
return number_returner() == 100 ? 0 : 1;
}

@ -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)

@ -12,4 +12,4 @@ ftempl = '''int %s() {
d = pathlib.Path(ifilename).read_text().split('\n')[0].strip()
pathlib.Path(ofilename).write_text(ftempl % d)
pathlib.Path(ofilename).write_text(ftempl % d)

@ -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)

@ -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)

Loading…
Cancel
Save