Can use outputs of targets as inputs of custom targets.

pull/15/head
Jussi Pakkanen 11 years ago
parent 2ecd2ea65a
commit ee0607ddf9
  1. 12
      build.py
  2. 3
      ninjabackend.py
  3. 1
      test cases/common/57 custom target chain/data_source.txt
  4. 1
      test cases/common/57 custom target chain/installed_files.txt
  5. 21
      test cases/common/57 custom target chain/meson.build
  6. 14
      test cases/common/57 custom target chain/my_compiler.py
  7. 14
      test cases/common/57 custom target chain/my_compiler2.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

@ -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

@ -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'
)

@ -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')

@ -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')
Loading…
Cancel
Save