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:
parent
0d63f15cde
commit
1a0396ea88
@ -35,9 +35,8 @@ def build(bld):
|
|||||||
elif tp == 'objects':
|
elif tp == 'objects':
|
||||||
features = 'c'
|
features = 'c'
|
||||||
|
|
||||||
source = Options.options.source
|
|
||||||
app = Options.options.app
|
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):
|
def recurse_rep(x, y):
|
||||||
f = getattr(Context.g_module, x.cmd or x.fun, Utils.nada)
|
f = getattr(Context.g_module, x.cmd or x.fun, Utils.nada)
|
||||||
|
@ -36,7 +36,7 @@ def build(bld):
|
|||||||
# example for generated python files
|
# example for generated python files
|
||||||
target = bld.path.find_or_declare('abc.py')
|
target = bld.path.find_or_declare('abc.py')
|
||||||
bld(rule='touch ${TGT}', source='wscript', target=target)
|
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
|
# then a c extension module
|
||||||
bld(
|
bld(
|
||||||
|
@ -14,14 +14,14 @@ def build(bld):
|
|||||||
for x in bld.path.ant_glob('*.svg'):
|
for x in bld.path.ant_glob('*.svg'):
|
||||||
bld(
|
bld(
|
||||||
rule='${CONVERT} -density 600 ${SRC} ${TGT}',
|
rule='${CONVERT} -density 600 ${SRC} ${TGT}',
|
||||||
source=x,
|
source=[x],
|
||||||
target=x.change_ext('.png'),
|
target=x.change_ext('.png'),
|
||||||
)
|
)
|
||||||
|
|
||||||
for x in bld.path.ant_glob('*.dia'):
|
for x in bld.path.ant_glob('*.dia'):
|
||||||
bld(
|
bld(
|
||||||
rule='${DIA} -t png ${SRC} -e ${TGT}',
|
rule='${DIA} -t png ${SRC} -e ${TGT}',
|
||||||
source=x,
|
source=[x],
|
||||||
target=x.change_ext('.png'),
|
target=x.change_ext('.png'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ def build(bld):
|
|||||||
bld(rule=try_compress, target=ini, always=True, kind=kind, frompath=node, files=rels)
|
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
|
# 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=write_template, target=plot, triplet=[png, kind, dist], always=True)
|
||||||
bld(rule='${GNUPLOT} < ${SRC[1].abspath()}', target=png, source=[dist, plot])
|
bld(rule='${GNUPLOT} < ${SRC[1].abspath()}', target=png, source=[dist, plot])
|
||||||
|
|
||||||
|
@ -47,26 +47,13 @@ def build(bld):
|
|||||||
import random
|
import random
|
||||||
rnd = random.randint(0, 25)
|
rnd = random.randint(0, 25)
|
||||||
bld(
|
bld(
|
||||||
rule = "sleep 2 && (echo 'int num%d = %d;' > ${TGT})" % (rnd, rnd),
|
rule = "sleep 2 && (echo 'int num%d = %d;' > ${TGT})" % (rnd, rnd),
|
||||||
target = 'foo_%d.c' % rnd,
|
target = 'foo_%d.c' % rnd,
|
||||||
)
|
)
|
||||||
|
|
||||||
bld.add_group()
|
bld.add_group()
|
||||||
|
|
||||||
bld.program(source='main.c', target='app', dynamic_source='*.c')
|
it = bld.path.get_bld().ant_glob('*.c', remove=False, quiet=True, generator=True)
|
||||||
|
src = ['main.c', it]
|
||||||
# support for the "dynamic_source" attribute follows:
|
bld(features='c cprogram', source=src, target='app')
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
@ -8,5 +8,5 @@ def build(bld):
|
|||||||
node = bld.path.get_bld().make_node('test/bar/stuff')
|
node = bld.path.get_bld().make_node('test/bar/stuff')
|
||||||
|
|
||||||
bld(features='mkdir', target=node)
|
bld(features='mkdir', target=node)
|
||||||
bld(rule='du ${SRC}', source=node)
|
bld(rule='du ${SRC}', source=[node])
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class task_gen(object):
|
|||||||
|
|
||||||
The extra key/value elements passed in ``kw`` are set as attributes
|
The extra key/value elements passed in ``kw`` are set as attributes
|
||||||
"""
|
"""
|
||||||
self.source = ''
|
self.source = []
|
||||||
self.target = ''
|
self.target = ''
|
||||||
|
|
||||||
self.meths = []
|
self.meths = []
|
||||||
@ -490,7 +490,8 @@ def extension(*k):
|
|||||||
@taskgen_method
|
@taskgen_method
|
||||||
def to_nodes(self, lst, path=None):
|
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 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`:
|
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):
|
if isinstance(lst, Node.Node):
|
||||||
lst = [lst]
|
lst = [lst]
|
||||||
|
|
||||||
# either a list or a string, convert to a list of nodes
|
|
||||||
for x in Utils.to_list(lst):
|
for x in Utils.to_list(lst):
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
node = find(x)
|
node = find(x)
|
||||||
else:
|
elif hasattr(x, 'name'):
|
||||||
node = x
|
node = x
|
||||||
|
else:
|
||||||
|
tmp.extend(self.to_nodes(x))
|
||||||
|
continue
|
||||||
if not node:
|
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)
|
tmp.append(node)
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user