Can specify extra arguments to generator commands. Closes #315.

pull/318/head
Jussi Pakkanen 9 years ago
parent 2024d9d237
commit 913963d608
  1. 6
      build.py
  2. 9
      interpreter.py
  3. 8
      ninjabackend.py
  4. 13
      test cases/common/98 gen extra/meson.build
  5. 1
      test cases/common/98 gen extra/name.dat
  6. 5
      test cases/common/98 gen extra/plain.c
  7. 26
      test cases/common/98 gen extra/srcgen.py
  8. 5
      test cases/common/98 gen extra/upper.c

@ -575,7 +575,7 @@ class Generator():
return self.arglist
class GeneratedList():
def __init__(self, generator):
def __init__(self, generator, extra_args=[]):
if hasattr(generator, 'held_object'):
generator = generator.held_object
self.generator = generator
@ -583,6 +583,7 @@ class GeneratedList():
self.outfilelist = []
self.outmap = {}
self.extra_depends = []
self.extra_args = extra_args
def add_file(self, newfile):
self.infilelist.append(newfile)
@ -602,6 +603,9 @@ class GeneratedList():
def get_generator(self):
return self.generator
def get_extra_args(self):
return self.extra_args
class Executable(BuildTarget):
def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs):
super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs)

@ -290,18 +290,17 @@ class GeneratorHolder(InterpreterObject):
self.methods.update({'process' : self.process_method})
def process_method(self, args, kwargs):
if len(kwargs) > 0:
raise InvalidArguments('Process does not take keyword arguments.')
check_stringlist(args)
gl = GeneratedListHolder(self)
extras = mesonlib.stringlistify(kwargs.get('extra_args', []))
gl = GeneratedListHolder(self, extras)
[gl.add_file(os.path.join(self.interpreter.subdir, a)) for a in args]
return gl
class GeneratedListHolder(InterpreterObject):
def __init__(self, arg1):
def __init__(self, arg1, extra_args=[]):
super().__init__()
if isinstance(arg1, GeneratorHolder):
self.held_object = build.GeneratedList(arg1.held_object)
self.held_object = build.GeneratedList(arg1.held_object, extra_args)
else:
self.held_object = arg1

@ -1141,7 +1141,13 @@ rule FORTRAN_DEP_HACK
relout = self.get_target_private_dir(target)
args = [x.replace("@SOURCE_DIR@", self.build_to_src).replace("@BUILD_DIR@", relout)
for x in args]
cmdlist = exe_arr + args
final_args = []
for a in args:
if a == '@EXTRA_ARGS@':
final_args += genlist.get_extra_args()
else:
final_args.append(a)
cmdlist = exe_arr + final_args
elem = NinjaBuildElement(outfiles, 'CUSTOM_COMMAND', infilename)
if len(extra_dependencies) > 0:
elem.add_dep(extra_dependencies)

@ -0,0 +1,13 @@
project('extra args in gen', 'c')
prog = find_program('srcgen.py')
gen = generator(prog,
output : '@BASENAME@.c',
arguments : ['--input=@INPUT@', '--output=@OUTPUT@', '@EXTRA_ARGS@'])
g1 = gen.process('name.dat')
g2 = gen.process('name.dat', extra_args: '--upper')
test('basic', executable('basic', 'plain.c', g1))
test('upper', executable('upper', 'upper.c', g2))

@ -0,0 +1,5 @@
int bob_mcbob();
int main(int argc, char **argv) {
return bob_mcbob();
}

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import sys
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--input', dest='input',
help='the input file')
parser.add_argument('--output', dest='output',
help='the output file')
parser.add_argument('--upper', dest='upper', action='store_true', default=False,
help='Convert to upper case.')
c_templ = '''int %s() {
return 0;
}
'''
options = parser.parse_args(sys.argv[1:])
funcname = open(options.input).readline().strip()
if options.upper:
funcname = funcname.upper()
open(options.output, 'w').write(c_templ % funcname)

@ -0,0 +1,5 @@
int BOB_MCBOB();
int main(int argc, char **argv) {
return BOB_MCBOB();
}
Loading…
Cancel
Save