2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-21 17:35:55 +01:00

Accept nested lists as bld(source=...)

This commit is contained in:
Thomas Nagy 2017-01-21 12:50:52 +01:00
parent 0d63f15cde
commit 1a0396ea88
No known key found for this signature in database
GPG Key ID: 49B4C67C05277AAA
7 changed files with 20 additions and 31 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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