在 waf 构建变体中使用不同的源
Use different source in waf build variant
基于此,可以将 waf 中的项目的不同 variants
构建到不同的输出目录 7.2.2。更改变体的输出目录/配置集 (https://waf.io/book/#_custom_build_outputs)
但是我不明白如何根据variant
包含不同的文件或目录。
我像这样修改了 waf-book 中的示例,但我缺少如何构建不同的源文件或包含来自不同目录的文件。
def configure(ctx):
pass
def build(ctx):
if not ctx.variant:
ctx.fatal('call "waf a" or "waf b", and try "waf --help"')
# for variant "a" it should build "a.c" and fpr "b" it should build "b.c"
# for a: bld.program(source='a.c', target='app', includes='.')
# for b: bld.program(source='b.c', target='app', includes='.')
from waflib.Build import BuildContext
class a(BuildContext):
cmd = 'a'
variant = 'a'
from waflib.Build import BuildContext
class b(BuildContext):
cmd = 'b'
variant = 'b'
您运行python waf configure
配置项目。之后使用命令 build_a
和 build_b
构建变体
def configure(ctx):
load('compiler_c')
def build(bld):
if not bld.variant:
bld.fatal('call "waf build_a" or "waf build_b", and try "waf --help"')
if bld.variant == 'a':
bld.program(source='a.c', target='app', includes='.')
elif bld.variant == 'b':
bld.program(source='b.c', target='app', includes='.')
else:
bld.fatal('"')
# create build and clean commands for each build context
from waflib.Build import BuildContext, CleanContext
for x in 'a b'.split():
for y in (BuildContext, CleanContext):
name = y.__name__.replace('Context','').lower()
class tmp(y):
__doc__ = '''executes the {} of {}'''.format(name, x)
cmd = name + '_' + x
variant = x
基于此,可以将 waf 中的项目的不同 variants
构建到不同的输出目录 7.2.2。更改变体的输出目录/配置集 (https://waf.io/book/#_custom_build_outputs)
但是我不明白如何根据variant
包含不同的文件或目录。
我像这样修改了 waf-book 中的示例,但我缺少如何构建不同的源文件或包含来自不同目录的文件。
def configure(ctx):
pass
def build(ctx):
if not ctx.variant:
ctx.fatal('call "waf a" or "waf b", and try "waf --help"')
# for variant "a" it should build "a.c" and fpr "b" it should build "b.c"
# for a: bld.program(source='a.c', target='app', includes='.')
# for b: bld.program(source='b.c', target='app', includes='.')
from waflib.Build import BuildContext
class a(BuildContext):
cmd = 'a'
variant = 'a'
from waflib.Build import BuildContext
class b(BuildContext):
cmd = 'b'
variant = 'b'
您运行python waf configure
配置项目。之后使用命令 build_a
和 build_b
def configure(ctx):
load('compiler_c')
def build(bld):
if not bld.variant:
bld.fatal('call "waf build_a" or "waf build_b", and try "waf --help"')
if bld.variant == 'a':
bld.program(source='a.c', target='app', includes='.')
elif bld.variant == 'b':
bld.program(source='b.c', target='app', includes='.')
else:
bld.fatal('"')
# create build and clean commands for each build context
from waflib.Build import BuildContext, CleanContext
for x in 'a b'.split():
for y in (BuildContext, CleanContext):
name = y.__name__.replace('Context','').lower()
class tmp(y):
__doc__ = '''executes the {} of {}'''.format(name, x)
cmd = name + '_' + x
variant = x