Add support for Files passed to generators.

I need this for windows.compile_resources to be able to use
configure_file results, but it may have other benefits.
pull/1257/head
Elliott Sales de Andrade 8 years ago
parent eea0670872
commit 78b030cf19
  1. 2
      mesonbuild/backend/ninjabackend.py
  2. 2
      mesonbuild/backend/vs2010backend.py
  3. 10
      mesonbuild/build.py
  4. 1
      test cases/common/133 configure file in generator/inc/confdata.in
  5. 6
      test cases/common/133 configure file in generator/inc/meson.build
  6. 4
      test cases/common/133 configure file in generator/meson.build
  7. 13
      test cases/common/133 configure file in generator/src/gen.py
  8. 17
      test cases/common/133 configure file in generator/src/main.c
  9. 7
      test cases/common/133 configure file in generator/src/meson.build
  10. 1
      test cases/common/133 configure file in generator/src/source

@ -1557,7 +1557,7 @@ rule FORTRAN_DEP_HACK
else:
sole_output = ''
curfile = infilelist[i]
infilename = os.path.join(self.build_to_src, curfile)
infilename = curfile.rel_to_builddir(self.build_to_src)
outfiles = genlist.get_outputs_for(curfile)
outfiles = [os.path.join(self.get_target_private_dir(target), of) for of in outfiles]
if generator.depfile is None:

@ -121,7 +121,7 @@ class Vs2010Backend(backends.Backend):
else:
sole_output = ''
curfile = infilelist[i]
infilename = os.path.join(self.environment.get_source_dir(), curfile)
infilename = os.path.join(down, curfile.rel_to_builddir(self.build_to_src))
outfiles_rel = genlist.get_outputs_for(curfile)
outfiles = [os.path.join(target_private_dir, of) for of in outfiles_rel]
generator_output_files += outfiles

@ -918,9 +918,11 @@ class Generator():
def process_files(self, name, files, state, extra_args=[]):
output = GeneratedList(self, extra_args=extra_args)
for f in files:
if not isinstance(f, str):
raise InvalidArguments('{} arguments must be strings.'.format(name))
output.add_file(os.path.join(state.subdir, f))
if isinstance(f, str):
f = File.from_source_file(state.environment.source_dir, state.subdir, f)
elif not isinstance(f, File):
raise InvalidArguments('{} arguments must be strings or files not {!r}.'.format(name, f))
output.add_file(f)
return output
@ -938,7 +940,7 @@ class GeneratedList():
def add_file(self, newfile):
self.infilelist.append(newfile)
outfiles = self.generator.get_base_outnames(newfile)
outfiles = self.generator.get_base_outnames(newfile.fname)
self.outfilelist += outfiles
self.outmap[newfile] = outfiles

@ -0,0 +1,6 @@
cdata = configuration_data()
cdata.set('VALUE', '42')
cfile = configure_file(input : 'confdata.in',
output : 'confdata',
configuration : cdata)

@ -0,0 +1,4 @@
project('conf file in generator', 'c')
subdir('inc')
subdir('src')

@ -0,0 +1,13 @@
#!/usr/bin/env python3
import sys
ifile = sys.argv[1]
ofile = sys.argv[2]
with open(ifile, 'r') as f:
resval = f.readline().strip()
templ = '#define RESULT (%s)\n'
with open(ofile, 'w') as f:
f.write(templ % (resval, ))

@ -0,0 +1,17 @@
#include<stdio.h>
#include"confdata.h"
#if RESULT != 42
#error Configuration RESULT is not defined correctly
#endif
#undef RESULT
#include"source.h"
#if RESULT != 23
#error Source RESULT is not defined correctly
#endif
int main(int argc, char **argv) {
return 0;
}

@ -0,0 +1,7 @@
compiler = find_program('gen.py')
gen = generator(compiler,
output: '@BASENAME@.h',
arguments : ['@INPUT@', '@OUTPUT@'])
hs = gen.process(cfile, files('source'))
executable('proggie', 'main.c', hs)
Loading…
Cancel
Save