From ee0607ddf92b0d4e3cf9a075db6c2e2f4439400e Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 21 May 2014 23:47:23 +0300 Subject: Can use outputs of targets as inputs of custom targets. --- build.py | 12 +++++++++--- ninjabackend.py | 3 ++- .../common/57 custom target chain/data_source.txt | 1 + .../57 custom target chain/installed_files.txt | 1 + .../common/57 custom target chain/meson.build | 21 +++++++++++++++++++++ .../common/57 custom target chain/my_compiler.py | 14 ++++++++++++++ .../common/57 custom target chain/my_compiler2.py | 14 ++++++++++++++ 7 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 test cases/common/57 custom target chain/data_source.txt create mode 100644 test cases/common/57 custom target chain/installed_files.txt create mode 100644 test cases/common/57 custom target chain/meson.build create mode 100755 test cases/common/57 custom target chain/my_compiler.py create mode 100755 test cases/common/57 custom target chain/my_compiler2.py diff --git a/build.py b/build.py index 8640e8be0..fef3e5310 100644 --- a/build.py +++ b/build.py @@ -203,7 +203,7 @@ class BuildTarget(): for i in self.link_targets: result += i.get_rpaths() return result - + def get_custom_install_dir(self): return self.custom_install_dir @@ -567,6 +567,7 @@ class CustomTarget: def __init__(self, name, subdir, kwargs): self.name = name self.subdir = subdir + self.dependencies = [] self.process_kwargs(kwargs) def process_kwargs(self, kwargs): @@ -586,10 +587,15 @@ class CustomTarget: for i, c in enumerate(cmd): if hasattr(c, 'ep'): c = c.ep + if hasattr(c, 'held_object'): + c = c.held_object if isinstance(c, str): final_cmd.append(c) elif isinstance(c, dependencies.ExternalProgram): final_cmd.append(c.get_command()) + elif isinstance(c, BuildTarget) or isinstance(c, CustomTarget): + self.dependencies.append(c) + final_cmd.append(os.path.join(c.get_subdir(), c.get_filename())) else: raise InvalidArguments('Argument %s in "command" is invalid.' % i) self.command = final_cmd @@ -609,14 +615,14 @@ class CustomTarget: return self.name def get_dependencies(self): - return [] + return self.dependencies def should_install(self): return self.install def get_custom_install_dir(self): return self.install_dir - + def get_subdir(self): return self.subdir diff --git a/ninjabackend.py b/ninjabackend.py index ff491b7f9..45e19dd39 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -136,7 +136,8 @@ class NinjaBackend(backends.Backend): def generate_custom_target(self, target, outfile): ofilename = os.path.join(target.subdir, target.output) - elem = NinjaBuildElement(ofilename, 'CUSTOM_COMMAND', '') + deps = [os.path.join(i.get_subdir(), i.get_filename()) for i in target.get_dependencies()] + elem = NinjaBuildElement(ofilename, 'CUSTOM_COMMAND', deps) elem.add_item('COMMAND', target.command) elem.write(outfile) self.processed_targets[target.name] = True diff --git a/test cases/common/57 custom target chain/data_source.txt b/test cases/common/57 custom target chain/data_source.txt new file mode 100644 index 000000000..0c23cc0c3 --- /dev/null +++ b/test cases/common/57 custom target chain/data_source.txt @@ -0,0 +1 @@ +This is a text only input file. diff --git a/test cases/common/57 custom target chain/installed_files.txt b/test cases/common/57 custom target chain/installed_files.txt new file mode 100644 index 000000000..c5f8bd766 --- /dev/null +++ b/test cases/common/57 custom target chain/installed_files.txt @@ -0,0 +1 @@ +subdir/data2.dat diff --git a/test cases/common/57 custom target chain/meson.build b/test cases/common/57 custom target chain/meson.build new file mode 100644 index 000000000..7bfcddb94 --- /dev/null +++ b/test cases/common/57 custom target chain/meson.build @@ -0,0 +1,21 @@ +project('custom target', 'c') + +python = find_program('python3') + +comp = '@0@/@1@'.format(meson.current_source_dir(), 'my_compiler.py') +comp2 = '@0@/@1@'.format(meson.current_source_dir(), 'my_compiler2.py') +infile = '@0@/@1@'.format(meson.current_source_dir(), 'data_source.txt') +outfile = '@0@/@1@'.format(meson.current_build_dir(), 'data.dat') +outfile2 = '@0@/@1@'.format(meson.current_build_dir(), 'data2.dat') + +mytarget = custom_target('bindat', +output : 'data.dat', +command : [python, comp, infile, outfile], +) + +mytarget2 = custom_target('bindat2', +output : 'data2.dat', +command : [python, comp2, mytarget, outfile2], +install : true, +install_dir : 'subdir' +) diff --git a/test cases/common/57 custom target chain/my_compiler.py b/test cases/common/57 custom target chain/my_compiler.py new file mode 100755 index 000000000..3165cf8c0 --- /dev/null +++ b/test cases/common/57 custom target chain/my_compiler.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +import sys + +if __name__ == '__main__': + if len(sys.argv) != 3: + print(sys.argv[0], 'input_file output_file') + sys.exit(1) + ifile = open(sys.argv[1]).read() + if ifile != 'This is a text only input file.\n': + print('Malformed input') + sys.exit(1) + ofile = open(sys.argv[2], 'w') + ofile.write('This is a binary output file.\n') diff --git a/test cases/common/57 custom target chain/my_compiler2.py b/test cases/common/57 custom target chain/my_compiler2.py new file mode 100755 index 000000000..8c767b124 --- /dev/null +++ b/test cases/common/57 custom target chain/my_compiler2.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +import sys + +if __name__ == '__main__': + if len(sys.argv) != 3: + print(sys.argv[0], 'input_file output_file') + sys.exit(1) + ifile = open(sys.argv[1]).read() + if ifile != 'This is a binary output file.\n': + print('Malformed input') + sys.exit(1) + ofile = open(sys.argv[2], 'w') + ofile.write('This is a different binary output file.\n') -- cgit v1.2.3