SCONS:运行 目标始终,不仅在更新时
SCONS: Run target always, not only if updated
基于 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 而不更改代码,它认为不需要再次构建,这是正确的,但也不会 运行 再次测试:
> 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 依赖。
有什么意见吗?
基于 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 而不更改代码,它认为不需要再次构建,这是正确的,但也不会 运行 再次测试:
> 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 依赖。
有什么意见吗?