diff --git a/backends.py b/backends.py index 6d6f68b45..1c8844be1 100755 --- a/backends.py +++ b/backends.py @@ -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) diff --git a/meson_test.py b/meson_test.py index 2cea912d2..98927e4f1 100755 --- a/meson_test.py +++ b/meson_test.py @@ -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) diff --git a/test cases/31 generate header/input_src.dat b/test cases/31 generate header/input_src.dat new file mode 100644 index 000000000..354499acd --- /dev/null +++ b/test cases/31 generate header/input_src.dat @@ -0,0 +1 @@ +#include diff --git a/test cases/31 generate header/meson.build b/test cases/31 generate header/meson.build new file mode 100644 index 000000000..1948eeb6c --- /dev/null +++ b/test cases/31 generate header/meson.build @@ -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) \ No newline at end of file diff --git a/test cases/31 generate header/prog.c b/test cases/31 generate header/prog.c new file mode 100644 index 000000000..34294816b --- /dev/null +++ b/test cases/31 generate header/prog.c @@ -0,0 +1,9 @@ +#include"input_src.dat.h" + +int main(int argc, char **argv) { + void *foo = printf; + if(foo) { + return 0; + } + return 1; +} diff --git a/test cases/31 generate header/srcgen.c b/test cases/31 generate header/srcgen.c new file mode 100644 index 000000000..c4e412bef --- /dev/null +++ b/test cases/31 generate header/srcgen.c @@ -0,0 +1,33 @@ +#include +#include + +int main(int argc, char **argv) { + const int ARRSIZE = 80; + char arr[ARRSIZE]; + if(argc != 3) { + fprintf(stderr, "%s \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; +}