From 226f063edb553ad6192edb7a62469f30c155c5a1 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 1 Mar 2013 20:49:46 +0200 Subject: [PATCH] Reworked how sources are passed to BuildTargets. --- backends.py | 6 +++-- interpreter.py | 39 +++++++++++++++--------------- test cases/30 pipeline/meson.build | 2 +- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/backends.py b/backends.py index 1262aaae7..f5b2f4c83 100755 --- a/backends.py +++ b/backends.py @@ -91,10 +91,12 @@ class Backend(): if target.has_pch(): self.generate_pch(target, outfile) for src in target.get_sources(): - obj_list.append(self.generate_single_compile(target, outfile, src)) + if not self.environment.is_header(src): + 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)) + if not self.environment.is_header(src): + 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 diff --git a/interpreter.py b/interpreter.py index 3cdf8c49a..37b951fe0 100755 --- a/interpreter.py +++ b/interpreter.py @@ -233,7 +233,7 @@ class BuildTarget(InterpreterObject): InterpreterObject.__init__(self) self.name = name self.subdir = subdir - self.sources = sources + self.sources = [] self.external_deps = [] self.include_dirs = [] self.link_targets = [] @@ -242,7 +242,21 @@ class BuildTarget(InterpreterObject): self.pch = [] self.extra_args = {} self.generated = [] + self.process_sourcelist(sources) self.process_kwargs(kwargs) + if len(self.sources) == 0: + raise InvalidArguments('Build target %s has no sources.' % name) + + def process_sourcelist(self, sources): + if not isinstance(sources, list): + sources = [sources] + for s in sources: + if isinstance(s, str): + self.sources.append(s) + elif isinstance(s, GeneratedList): + self.generated.append(s) + else: + raise InvalidArguments('Bad source in target %s.' % self.name) def process_kwargs(self, kwargs): self.need_install = kwargs.get('install', self.need_install) @@ -275,10 +289,6 @@ class BuildTarget(InterpreterObject): if not isinstance(deplist, list): deplist = [deplist] self.add_external_deps(deplist) - genlist = kwargs.get('gen_src', []) - if not isinstance(genlist, list): - genlist = [genlist] - self.set_generated(genlist) def get_subdir(self): return self.subdir @@ -695,25 +705,16 @@ class Interpreter(): def build_target(self, node, args, kwargs, targetclass): args = self.flatten(args) - for a in args: - if not isinstance(a, str): - raise InvalidArguments('Line %d: Argument %s is not a string.' % (node.lineno(), str(a))) + print(args) name = args[0] - sources = [] - for s in args[1:]: - if not self.environment.is_header(s): - sources.append(s) + sources = args[1:] try: kw_src = self.flatten(kwargs['sources']) + if not isinstance(kw_src, list): + kw_src = [kw_src] except KeyError: kw_src = [] - if not isinstance(kw_src, list): - kw_src = [kw_src] - for s in kw_src: - if not self.environment.is_header(s): - sources.append(s) - if len(sources) == 0: - raise InvalidArguments('Line %d: target has no source files.' % node.lineno()) + sources += kw_src if name in self.build.targets: raise InvalidCode('Line %d: tried to create target "%s", but a target of that name already exists.' % (node.lineno(), name)) l = targetclass(name, self.subdir, sources, self.environment, kwargs) diff --git a/test cases/30 pipeline/meson.build b/test cases/30 pipeline/meson.build index 4192c49a1..de613bc20 100644 --- a/test cases/30 pipeline/meson.build +++ b/test cases/30 pipeline/meson.build @@ -8,6 +8,6 @@ gen = generator(e1, \ generated = gen.process('input_src.dat') -e2 = executable('prog', 'prog.c', gen_src : generated) +e2 = executable('prog', 'prog.c', generated) add_test('pipelined', e2)