From 1a0396ea8878ea05e3630e4abf026c72c8caeaf7 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Sat, 21 Jan 2017 12:50:52 +0100 Subject: [PATCH] Accept nested lists as bld(source=...) --- build_system_kit/noscript/dbdlib.py | 3 +-- demos/python/wscript | 2 +- docs/slides/presentation/gfx/wscript | 4 ++-- playground/compress/wscript | 2 +- playground/dynamic_build/wscript | 25 ++++++------------------- playground/folder_hashing/wscript | 2 +- waflib/TaskGen.py | 13 ++++++++----- 7 files changed, 20 insertions(+), 31 deletions(-) diff --git a/build_system_kit/noscript/dbdlib.py b/build_system_kit/noscript/dbdlib.py index f2f356a5..6a392878 100644 --- a/build_system_kit/noscript/dbdlib.py +++ b/build_system_kit/noscript/dbdlib.py @@ -35,9 +35,8 @@ def build(bld): elif tp == 'objects': features = 'c' - source = Options.options.source app = Options.options.app - bld(features=features, source=source, target=app) + bld(features=features, source=Options.options.source, target=app) def recurse_rep(x, y): f = getattr(Context.g_module, x.cmd or x.fun, Utils.nada) diff --git a/demos/python/wscript b/demos/python/wscript index 61d3100a..07b5b666 100644 --- a/demos/python/wscript +++ b/demos/python/wscript @@ -36,7 +36,7 @@ def build(bld): # example for generated python files target = bld.path.find_or_declare('abc.py') bld(rule='touch ${TGT}', source='wscript', target=target) - bld(features='py', source=target, install_from=target.parent) + bld(features='py', source=[target], install_from=target.parent) # then a c extension module bld( diff --git a/docs/slides/presentation/gfx/wscript b/docs/slides/presentation/gfx/wscript index 958ba0c9..94c85497 100644 --- a/docs/slides/presentation/gfx/wscript +++ b/docs/slides/presentation/gfx/wscript @@ -14,14 +14,14 @@ def build(bld): for x in bld.path.ant_glob('*.svg'): bld( rule='${CONVERT} -density 600 ${SRC} ${TGT}', - source=x, + source=[x], target=x.change_ext('.png'), ) for x in bld.path.ant_glob('*.dia'): bld( rule='${DIA} -t png ${SRC} -e ${TGT}', - source=x, + source=[x], target=x.change_ext('.png'), ) diff --git a/playground/compress/wscript b/playground/compress/wscript index 4614855a..40f7a126 100644 --- a/playground/compress/wscript +++ b/playground/compress/wscript @@ -138,7 +138,7 @@ def build(bld): bld(rule=try_compress, target=ini, always=True, kind=kind, frompath=node, files=rels) # for the same reason, count_result will be executed each time - bld(rule=count_result, target=dist, source=ini, always=True) + bld(rule=count_result, target=dist, source=[ini], always=True) bld(rule=write_template, target=plot, triplet=[png, kind, dist], always=True) bld(rule='${GNUPLOT} < ${SRC[1].abspath()}', target=png, source=[dist, plot]) diff --git a/playground/dynamic_build/wscript b/playground/dynamic_build/wscript index 9309724b..296a1af4 100644 --- a/playground/dynamic_build/wscript +++ b/playground/dynamic_build/wscript @@ -47,26 +47,13 @@ def build(bld): import random rnd = random.randint(0, 25) bld( - rule = "sleep 2 && (echo 'int num%d = %d;' > ${TGT})" % (rnd, rnd), - target = 'foo_%d.c' % rnd, - ) + rule = "sleep 2 && (echo 'int num%d = %d;' > ${TGT})" % (rnd, rnd), + target = 'foo_%d.c' % rnd, + ) bld.add_group() - bld.program(source='main.c', target='app', dynamic_source='*.c') - -# support for the "dynamic_source" attribute follows: - -from waflib import Build, Utils, TaskGen -@TaskGen.feature('c') -@TaskGen.before('process_source', 'process_rule') -def dynamic_post(self): - """ - bld(dynamic_source='*.c', ..) will search for source files to add to the attribute 'source' - we could also call "eval" or whatever expression - """ - if not getattr(self, 'dynamic_source', None): - return - self.source = Utils.to_list(self.source) - self.source.extend(self.path.get_bld().ant_glob(self.dynamic_source, remove=False)) + it = bld.path.get_bld().ant_glob('*.c', remove=False, quiet=True, generator=True) + src = ['main.c', it] + bld(features='c cprogram', source=src, target='app') diff --git a/playground/folder_hashing/wscript b/playground/folder_hashing/wscript index f66101fb..cf1d73f4 100644 --- a/playground/folder_hashing/wscript +++ b/playground/folder_hashing/wscript @@ -8,5 +8,5 @@ def build(bld): node = bld.path.get_bld().make_node('test/bar/stuff') bld(features='mkdir', target=node) - bld(rule='du ${SRC}', source=node) + bld(rule='du ${SRC}', source=[node]) diff --git a/waflib/TaskGen.py b/waflib/TaskGen.py index b6074eb9..35a8f562 100644 --- a/waflib/TaskGen.py +++ b/waflib/TaskGen.py @@ -48,7 +48,7 @@ class task_gen(object): The extra key/value elements passed in ``kw`` are set as attributes """ - self.source = '' + self.source = [] self.target = '' self.meths = [] @@ -490,7 +490,8 @@ def extension(*k): @taskgen_method def to_nodes(self, lst, path=None): """ - Converts the input list into a list of nodes. + Flatten the input list of string/nodes/lists into a list of nodes. + It is used by :py:func:`waflib.TaskGen.process_source` and :py:func:`waflib.TaskGen.process_rule`. It is designed for source files, for folders, see :py:func:`waflib.Tools.ccroot.to_incnodes`: @@ -507,14 +508,16 @@ def to_nodes(self, lst, path=None): if isinstance(lst, Node.Node): lst = [lst] - # either a list or a string, convert to a list of nodes for x in Utils.to_list(lst): if isinstance(x, str): node = find(x) - else: + elif hasattr(x, 'name'): node = x + else: + tmp.extend(self.to_nodes(x)) + continue if not node: - raise Errors.WafError("source not found: %r in %r" % (x, self)) + raise Errors.WafError('source not found: %r in %r' % (x, self)) tmp.append(node) return tmp