Can generate header files.

pull/15/head
Jussi Pakkanen 12 years ago
parent 775d86c0fa
commit 60cf41adab
  1. 18
      backends.py
  2. 4
      meson_test.py
  3. 1
      test cases/31 generate header/input_src.dat
  4. 13
      test cases/31 generate header/meson.build
  5. 9
      test cases/31 generate header/prog.c
  6. 33
      test cases/31 generate header/srcgen.c

@ -90,13 +90,16 @@ class Backend():
obj_list = []
if target.has_pch():
self.generate_pch(target, outfile)
for src in target.get_sources():
if not self.environment.is_header(src):
obj_list.append(self.generate_single_compile(target, outfile, src))
header_deps = []
for genlist in target.get_generated_sources():
for src in genlist.get_outfilelist():
if not self.environment.is_header(src):
obj_list.append(self.generate_single_compile(target, outfile, src, True))
else:
header_deps.append(src)
for src in target.get_sources():
if not self.environment.is_header(src):
obj_list.append(self.generate_single_compile(target, outfile, src, False, header_deps))
elem = self.generate_link(target, outfile, outname, obj_list)
self.generate_shlib_aliases(target, self.get_target_dir(target), outfile, elem)
self.processed_targets[name] = True
@ -429,7 +432,7 @@ class NinjaBackend(Backend):
base_args = generator.get_arglist()
for i in range(len(infilelist)):
infilename = os.path.join(self.build_to_src, infilelist[i])
outfilename = os.path.join(self.get_target_dir(target), outfilelist[i])
outfilename = os.path.join(self.get_target_private_dir(target), outfilelist[i])
args = [x.replace("@INPUT@", infilename).replace('@OUTPUT@', outfilename)\
for x in base_args]
cmdlist = [exe_file] + args
@ -438,11 +441,12 @@ class NinjaBackend(Backend):
elem.add_item('COMMAND', cmdlist)
elem.write(outfile)
def generate_single_compile(self, target, outfile, src, is_generated=False):
def generate_single_compile(self, target, outfile, src, is_generated=False, header_deps=[]):
compiler = self.get_compiler_for_source(src)
commands = self.generate_basic_compiler_flags(target, compiler)
commands.append(compiler.get_include_arg(self.get_target_private_dir(target)))
if is_generated:
abs_src = src
abs_src = os.path.join(self.get_target_private_dir(target), src)
else:
abs_src = os.path.join(self.build_to_src, target.get_source_subdir(), src)
abs_obj = os.path.join(self.get_target_private_dir(target), src)
@ -471,6 +475,8 @@ class NinjaBackend(Backend):
compiler_name = '%s_COMPILER' % compiler.get_language()
element = NinjaBuildElement(abs_obj, compiler_name, abs_src)
if len(header_deps) > 0:
element.add_dep([os.path.join(self.get_target_private_dir(target), d) for d in header_deps])
element.add_orderdep(pch_dep)
element.add_item('DEPFILE', dep_file)
element.add_item('FLAGS', commands)

@ -25,8 +25,8 @@ def run_tests(datafilename):
(stdo, stde) = p.communicate()
if p.returncode != 0:
print('Error running test.')
print('Stdout:\n' + stdo)
print('Stderr:\n' + stde)
print('Stdout:\n' + stdo.decode())
print('Stderr:\n' + stde.decode())
sys.exit(1)
print('Test "%s": OK' % line)

@ -0,0 +1,13 @@
project('pipeline test', 'c')
e1 = executable('srcgen', 'srcgen.c')
gen = generator(e1, \
output_name : '@BASENAME@.h', \
arguments : ['@INPUT@', '@OUTPUT@'])
generated = gen.process('input_src.dat')
e2 = executable('prog', 'prog.c', generated)
add_test('pipelined', e2)

@ -0,0 +1,9 @@
#include"input_src.dat.h"
int main(int argc, char **argv) {
void *foo = printf;
if(foo) {
return 0;
}
return 1;
}

@ -0,0 +1,33 @@
#include<stdio.h>
#include<assert.h>
int main(int argc, char **argv) {
const int ARRSIZE = 80;
char arr[ARRSIZE];
if(argc != 3) {
fprintf(stderr, "%s <input file> <output file>\n", argv[0]);
return 1;
}
char *ifilename = argv[1];
char *ofilename = argv[2];
printf("%s\n", ifilename);
FILE *ifile = fopen(ifilename, "r");
if(!ifile) {
fprintf(stderr, "Could not open source file %s.\n", ifilename);
return 1;
}
FILE *ofile = fopen(ofilename, "w");
if(!ofile) {
fprintf(stderr, "Could not open target file %s\n", ofilename);
return 1;
}
size_t bytes;
bytes = fread(arr, 1, ARRSIZE, ifile);
assert(bytes < 80);
assert(bytes > 0);
fwrite(arr, 1, bytes, ofile);
fclose(ifile);
fclose(ofile);
return 0;
}
Loading…
Cancel
Save