Use different source in waf build variant

感情迁移 提交于 2019-12-11 13:23:43

问题


Based on this it is possible to build different variants of a project in waf to different output directories 7.2.2. Changing the output directory / Configuration sets for variants (https://waf.io/book/#_custom_build_outputs)

But I do not understand how to include different files or directories based on the variant. I modified the example from the waf-book like this, but I am missing how to build a different sourcefile or include files from different directories.

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'

回答1:


You run python waf configure to configure the project. After that a variant is build with the commands build_a and 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


来源:https://stackoverflow.com/questions/47396160/use-different-source-in-waf-build-variant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!