如何解决SCONS:始终运行目标,不仅在更新时
基于 SCONS run target,我创建了一个基本的 SCONS 脚本来构建并运行我的单元测试:
test = env.Program(
target='artifacts/unittest',source= sources + tests
)
Alias(
'test',test,test[0].abspath
)
> scons test
scons: Reading sconscript files ...
scons: done reading sconscript files.
scons: Building targets ...
g++ [...]
[Lots of compiler output]
unittest.exe
===============================================================================
All tests passed (22 assertions in 4 test cases)
如果我现在再次运行 scons test 而不更改代码,它认为不需要再次构建,这是正确的,但也不会再次运行测试:
> scons test
scons: Reading sconscript files ...
scons: done reading sconscript files.
scons: Building targets ...
scons: `test' is up to date.
scons: done building targets.
但是,很明显,我希望即使没有重建测试也能运行:
> scons test
scons: Reading sconscript files ...
scons: done reading sconscript files.
scons: Building targets ...
scons: `test' is up to date.
scons: done building targets.
unittest.exe
===============================================================================
All tests passed (22 assertions in 4 test cases)
得到这个结果的最简单方法是什么?
解决方法
试试
env.Pseudo('test')
这应该将目标标记为不生成任何文件,并且可能对您有用。
,还见过 AlwaysBuild
用于触发单元测试执行。 “见过”并不意味着它一定是最佳实践(@bdbaddog 是这里的专家!)。
现在通过使用 AddMethod 创建 PseudoBuilder 来连接构建器和命令来修复它:
env.AddMethod(
lambda env,target,source:
[
env.Program(
target=target,source=source
)[0],env.Command(
target,source,'.\\$TARGET'
)[0]
],'BuildAndRun'
)
env.Alias(
'test',env.BuildAndRun(
target='artifacts/unittest',source= sources + tests
)
)
目前按预期工作:
> scons test
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ [...]
[Lots of compiler output]
.\artifacts\unittest
===============================================================================
All tests passed (22 assertions in 4 test cases)
> scons test
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
.\artifacts\unittest
===============================================================================
All tests passed (22 assertions in 4 test cases)
唯一的缺点:命令中的反斜杠使我依赖于 Windows。
有什么意见吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。