Generate compile commands for generated sources.

pull/15/head
Jussi Pakkanen 12 years ago
parent 1e66faac5f
commit 15aa29bf15
  1. 23
      backends.py
  2. 16
      interpreter.py

@ -91,6 +91,9 @@ class Backend():
self.generate_pch(target, outfile)
for src in target.get_sources():
obj_list.append(self.generate_single_compile(target, outfile, src))
for genlist in target.get_generated_sources():
for src in genlist.get_outfilelist():
obj_list.append(self.generate_single_compile(target, outfile, src, True))
self.generate_link(target, outfile, outname, obj_list)
self.generate_shlib_aliases(target, self.get_target_dir(target), outfile)
self.processed_targets[name] = True
@ -344,10 +347,13 @@ class NinjaBackend(Backend):
outfile.write('\n')
outfile.write('\n')
def generate_single_compile(self, target, outfile, src):
def generate_single_compile(self, target, outfile, src, is_generated=False):
compiler = self.get_compiler_for_source(src)
commands = self.generate_basic_compiler_flags(target, compiler)
abs_src = os.path.join(self.build_to_src, target.get_source_subdir(), src)
if is_generated:
abs_src = 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)
abs_obj += '.' + self.environment.get_object_suffix()
dep_file = abs_obj + '.' + compiler.get_depfile_suffix()
@ -705,16 +711,3 @@ echo Run compile.sh before this or bad things will happen.
aliasfile = os.path.join(outdir, alias)
cmd = ['ln', '-s', '-f', basename, aliasfile]
outfile.write(' '.join(shell_quote(cmd)) + '|| exit\n')
if __name__ == '__main__':
code = """
project('simple generator')
language('c')
executable('prog', 'prog.c', 'dep.c')
"""
import environment
os.chdir(os.path.split(__file__)[0])
envir = environment.Environment('.', 'work area')
intpr = interpreter.Interpreter(code, envir)
g = ShellBackend(intpr, envir)
g.generate()

@ -73,7 +73,7 @@ class Generator(InterpreterObject):
self.name_rule = rule
def get_base_outname(self, inname):
base = os.path.split()[1]
base = os.path.split(inname)[1]
return self.name_rule.replace('@BASENAME@', base)
def process_method(self, args, kwargs):
@ -94,13 +94,18 @@ class GeneratedList(InterpreterObject):
def __init__(self, generator):
InterpreterObject.__init__(self)
self.generator = generator
self.filelist = []
self.infilelist = []
self.outfilelist = []
def add_file(self, newfile):
self.filelist.append(newfile)
self.infilelist.append(newfile)
self.outfilelist.append(self.generator.get_base_outname(newfile))
def get_filelist(self):
return self.filelist
def get_infilelist(self):
return self.infilelist
def get_outfilelist(self):
return self.outfilelist
def get_generator(self):
return self.generator
@ -326,6 +331,7 @@ class BuildTarget(InterpreterObject):
for g in genlist:
if not(isinstance(g, GeneratedList)):
raise InvalidArguments('Generated source argument is not the output of a generator.')
self.generated.append(g)
def add_pch(self, pchlist):
for a in pchlist:

Loading…
Cancel
Save