gpt4 book ai didi

build - 如何在构建的程序上声明测试脚本的 WAF 依赖关系?

转载 作者:行者123 更新时间:2023-12-04 10:07:53 25 4
gpt4 key购买 nike

我正在努力寻找正确的方法来定义测试脚本的依赖关系
在 waf 在同一构建过程中构建的二进制程序上。
这是 wscript 的最小示例:

from waflib.Tools import waf_unit_test

def options(opt):
opt.load("compiler_cxx python waf_unit_test")

def configure(cnf):
cnf.load("compiler_cxx python waf_unit_test")


def build(bld):
bld.add_post_fun(waf_unit_test.summary)
bld.options.clear_failed_tests= True

bld(features= "cxx cxxprogram",
target= "foo",
source= "foo.cpp")

tg= bld(features= "test_scripts",
test_scripts_source= "fooTest.py",
test_scripts_template= "${PYTHON} ${SRC}")
tg.post()
tg.tasks[0].inputs.append(bld.path.find_or_declare("foo"))

我想表达的是,waf 将构建程序 foo .
那么,如果程序 foo自上次构建运行以来已更改,脚本 fooTest.py应检查该程序的执行。 wscript以上作品:
Waf: Entering directory `/home/x/tmp/exe_depend/build'
[1/3] Compiling foo.cpp
[2/3] Linking build/foo
[3/3] Processing utest: fooTest.py build/foo
Waf: Leaving directory `/home/x/tmp/exe_depend/build'
execution summary
tests that pass 1/1
/home/x/tmp/exe_depend/fooTest.py
tests that fail 0/1
'build' finished successfully (0.054s)

原则上, wscript以上满足了我的需求,但它看起来很难看,而且摆弄任务生成器似乎是错误的 tg .你们中有人知道一个平稳的解决方案吗?

最佳答案

好吧,waf_unit_test.py 中没有很多钩子(Hook)。最好的方法是通过制作自己的工具并将两行代码放入其中来扩展它。像这样的东西:

# in file my_unit_test.py

def options(opt):
opt.load("waf_unit_test") # we extend it, no need to recode

def configure(conf):
conf.load("waf_unit_test") # we extend it, no need to recode

@feature('test_scripts')
@after_method('make_interpreted_test') # we execute after task creation
def process_test_scripts_dependencies(self):
try:
self.test_scripts_deps
except AttributeError:
return

for task in self.tasks: # there can be many scripts
task.set_inputs(self.to_nodes(self.test_scripts_deps))

使用它:

def options(opt):
opt.load("compiler_cxx python my_unit_test")

def configure(cnf):
cnf.load("compiler_cxx python my_unit_test")


def build(bld):
bld.add_post_fun(waf_unit_test.summary)
bld.options.clear_failed_tests= True

myprogram = "foo"

bld(
features = "cxx cxxprogram",
target = myprogram,
source = "foo.cpp",
)

bld(
features = "test_scripts",
test_scripts_deps = myprogram,
test_scripts_source = "fooTest.py",
test_scripts_template = "${PYTHON} ${SRC}",
)

当然,你可以走得更远,重写一些适合你需要的东西:)

关于build - 如何在构建的程序上声明测试脚本的 WAF 依赖关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61479068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com