【发布时间】:2019-03-15 19:51:40
【问题描述】:
我有一个有点复杂的 SCons 构建脚本,它需要执行以下两个步骤:
# 1: builds unit tests (googletest, shell executable)
compile_tests = some_environment.Program(executable_path, test_sources)
# 2: runs unit tests (call earlier compiled program)
run_tests = other_environment.Command(
source = executable_path,
action = executable_path + ' --gtest_output=xml:' + test_results_path,
target = test_results_path
)
Depends(run_tests, compile_tests)
如果我使用这个构建脚本单独运行 scons,这会很好。
但是,如果我通过environment.SConscript() 从另一个目录级别的另一个SConstruct 文件调用它,那么步骤1 会调整项目位置的路径,而步骤2 不会。看到这个输出:
scons: Building targets ...
g++ -o Nuclex.Game.Native/obj/gcc-7-amd64-release/NuclexGameNativeTests -z defs -Bsymbolic Nuclex.Game.Native/obj/gcc-7-amd64-release/Tests/Timing/ClockTests.o -LNuclex.Game.Native/obj/gcc-7-amd64-release -LReferences/googletest/gcc-7-amd64-release -lNuclexGameNativeStatic -lgoogletest -lgoogletest_main -lpthread
obj/gcc-7-amd64-release/NuclexGameNativeTests --gtest_output=xml:bin/gcc-7-amd64-release/gtest-results.xml
sh: obj/gcc-7-amd64-release/NuclexGameNativeTests: No such file or directory
第 2 行将可执行文件构建到 Nuclex.Game.Native/obj/gcc-7-amd64-release/ 中,而第 3 行尝试在 obj/gcc-7-amd64-release/ 中调用它,忘记了项目目录。
我应该使用其他方式来调用我的单元测试可执行文件吗?或者我可以查询 SCons 环境的基本路径吗?
更新:复制案例,将https://pastebin.com/W08yZuF9作为SConstruct放在根目录中,创建子目录somelib并将https://pastebin.com/eiP63Yxh作为SConstruct放在其中,还可以使用“Hello World”或其他虚拟对象创建main.cpp程序。
【问题讨论】:
-
我不会将您目前拥有的称为最小、完整和可验证的示例。这些环境(some_environment、other_environment)是否以任何方式修改过? executable_path 和 test_results_path 的值是多少?
-
对 SConscript 的调用也有任何参数吗?
-
我相信这个例子足以理解和重现问题。假设环境是普通的,如果你愿意,用
a和b替换executable_path和test_results_path。我现在还添加了两个最小的SConstruct文件来重现问题底部的问题。 -
我试用了您的复制案例,一切似乎都正常工作。你确定你没有在任何地方使用变体目录吗?你的路径
obj/gcc-7-amd64-release/表明你是?并且环境没有差异,那为什么不使用相同的环境呢? -
我的实际构建设置确实使用了 VariantDir,但问题取决于
environment.SConscript()调用。在我的系统上,sh: ./example: No such file or directory的最小复制案例错误。
标签: path scons build-system