Octopus merged cross fixes and genetor custom because why not.

pull/602/head
Jussi Pakkanen 9 years ago
commit 68dbbeb78f
  1. 12
      mesonbuild/backend/backends.py
  2. 79
      mesonbuild/backend/ninjabackend.py
  3. 2
      mesonbuild/build.py
  4. 13
      test cases/common/113 generatorcustom/catter.py
  5. 11
      test cases/common/113 generatorcustom/gen.py
  6. 7
      test cases/common/113 generatorcustom/main.c
  7. 17
      test cases/common/113 generatorcustom/meson.build
  8. 1
      test cases/common/113 generatorcustom/res1.txt
  9. 1
      test cases/common/113 generatorcustom/res2.txt

@ -476,14 +476,16 @@ class Backend():
if hasattr(i, 'held_object'):
i = i.held_object
if isinstance(i, str):
fname = os.path.join(self.build_to_src, target.subdir, i)
fname = [os.path.join(self.build_to_src, target.subdir, i)]
elif isinstance(i, build.BuildTarget):
fname = self.get_target_filename(i)
fname = [self.get_target_filename(i)]
elif isinstance(i, build.GeneratedList):
fname = [os.path.join(self.get_target_private_dir(target), p) for p in i.get_outfilelist()]
else:
fname = i.rel_to_builddir(self.build_to_src)
fname = [i.rel_to_builddir(self.build_to_src)]
if absolute_paths:
fname = os.path.join(self.environment.get_build_dir(), fname)
srcs.append(fname)
fname =[os.path.join(self.environment.get_build_dir(), f) for f in fname]
srcs += fname
cmd = []
for i in target.command:
if isinstance(i, build.Executable):

@ -340,7 +340,15 @@ int dummy;
if not tname in self.processed_targets:
self.generate_target(t, outfile)
def custom_target_generator_inputs(self, target, outfile):
for s in target.sources:
if hasattr(s, 'held_object'):
s = s.held_object
if isinstance(s, build.GeneratedList):
self.generate_genlist_for_target(s, target, outfile)
def generate_custom_target(self, target, outfile):
self.custom_target_generator_inputs(target, outfile)
(srcs, ofilenames, cmd) = self.eval_custom_target_command(target)
deps = []
desc = 'Generating {0} with a {1} command.'
@ -1303,40 +1311,43 @@ rule FORTRAN_DEP_HACK
for genlist in target.get_generated_sources():
if isinstance(genlist, build.CustomTarget):
continue # Customtarget has already written its output rules
generator = genlist.get_generator()
exe = generator.get_exe()
exe_arr = self.exe_object_to_cmd_array(exe)
infilelist = genlist.get_infilelist()
outfilelist = genlist.get_outfilelist()
base_args = generator.get_arglist()
extra_dependencies = [os.path.join(self.build_to_src, i) for i in genlist.extra_depends]
for i in range(len(infilelist)):
if len(generator.outputs) == 1:
sole_output = os.path.join(self.get_target_private_dir(target), outfilelist[i])
else:
sole_output = ''
curfile = infilelist[i]
infilename = os.path.join(self.build_to_src, curfile)
outfiles = genlist.get_outputs_for(curfile)
outfiles = [os.path.join(self.get_target_private_dir(target), of) for of in outfiles]
args = [x.replace("@INPUT@", infilename).replace('@OUTPUT@', sole_output)\
for x in base_args]
args = self.replace_outputs(args, self.get_target_private_dir(target), outfilelist)
# We have consumed output files, so drop them from the list of remaining outputs.
if sole_output == '':
outfilelist = outfilelist[len(generator.outputs):]
relout = self.get_target_private_dir(target)
args = [x.replace("@SOURCE_DIR@", self.build_to_src).replace("@BUILD_DIR@", relout)
for x in args]
cmdlist = exe_arr + self.replace_extra_args(args, genlist)
elem = NinjaBuildElement(self.all_outputs, outfiles, 'CUSTOM_COMMAND', infilename)
if len(extra_dependencies) > 0:
elem.add_dep(extra_dependencies)
elem.add_item('DESC', 'Generating $out')
if isinstance(exe, build.BuildTarget):
elem.add_dep(self.get_target_filename(exe))
elem.add_item('COMMAND', cmdlist)
elem.write(outfile)
self.generate_genlist_for_target(genlist, target, outfile)
def generate_genlist_for_target(self, genlist, target, outfile):
generator = genlist.get_generator()
exe = generator.get_exe()
exe_arr = self.exe_object_to_cmd_array(exe)
infilelist = genlist.get_infilelist()
outfilelist = genlist.get_outfilelist()
base_args = generator.get_arglist()
extra_dependencies = [os.path.join(self.build_to_src, i) for i in genlist.extra_depends]
for i in range(len(infilelist)):
if len(generator.outputs) == 1:
sole_output = os.path.join(self.get_target_private_dir(target), outfilelist[i])
else:
sole_output = ''
curfile = infilelist[i]
infilename = os.path.join(self.build_to_src, curfile)
outfiles = genlist.get_outputs_for(curfile)
outfiles = [os.path.join(self.get_target_private_dir(target), of) for of in outfiles]
args = [x.replace("@INPUT@", infilename).replace('@OUTPUT@', sole_output)\
for x in base_args]
args = self.replace_outputs(args, self.get_target_private_dir(target), outfilelist)
# We have consumed output files, so drop them from the list of remaining outputs.
if sole_output == '':
outfilelist = outfilelist[len(generator.outputs):]
relout = self.get_target_private_dir(target)
args = [x.replace("@SOURCE_DIR@", self.build_to_src).replace("@BUILD_DIR@", relout)
for x in args]
cmdlist = exe_arr + self.replace_extra_args(args, genlist)
elem = NinjaBuildElement(self.all_outputs, outfiles, 'CUSTOM_COMMAND', infilename)
if len(extra_dependencies) > 0:
elem.add_dep(extra_dependencies)
elem.add_item('DESC', 'Generating $out')
if isinstance(exe, build.BuildTarget):
elem.add_dep(self.get_target_filename(exe))
elem.add_item('COMMAND', cmdlist)
elem.write(outfile)
def scan_fortran_module_outputs(self, target):
compiler = None

@ -824,7 +824,7 @@ class CustomTarget:
for c in self.sources:
if hasattr(c, 'held_object'):
c = c.held_object
if isinstance(c, BuildTarget) or isinstance(c, CustomTarget):
if isinstance(c, BuildTarget) or isinstance(c, CustomTarget) or isinstance(c, GeneratedList):
deps.append(c)
return deps

@ -0,0 +1,13 @@
#!/usr/bin/env python3
import sys, os
output = sys.argv[-1]
inputs = sys.argv[1:-1]
with open(output, 'w') as ofile:
ofile.write('#pragma once\n')
for i in inputs:
content = open(i, 'r').read()
ofile.write(content)
ofile.write('\n')

@ -0,0 +1,11 @@
#!/usr/bin/env python3
import sys, os
ifile = sys.argv[1]
ofile = sys.argv[2]
resname = open(ifile, 'r').readline().strip()
templ = 'const char %s[] = "%s";\n'
open(ofile, 'w').write(templ % (resname, resname))

@ -0,0 +1,7 @@
#include<stdio.h>
#include"alltogether.h"
int main(int argc, char **argv) {
return 0;
}

@ -0,0 +1,17 @@
project('generatorcustom', 'c')
creator = find_program('gen.py')
catter = find_program('catter.py')
gen = generator(creator,
output: '@BASENAME@.h',
arguments : ['@INPUT@', '@OUTPUT@'])
hs = gen.process('res1.txt', 'res2.txt')
allinone = custom_target('alltogether',
input : hs,
output : 'alltogether.h',
command : [catter, '@INPUT@', '@OUTPUT@'])
executable('proggie', 'main.c', allinone)
Loading…
Cancel
Save