[英]QBS build system, can't initialize environment with vcvars64.bat
I'm trying to implement my own module to build C++ on Windows with clang-cl toolchain as there's no built-in support in QBS right now. 我正在尝试实现自己的模块,以便使用clang-cl工具链在Windows上构建C ++,因为QBS目前没有内置支持。
I chose to use lld-link instead of microsoft linker, so I have to supply it with all the MS library include paths manually. 我选择使用lld-link而不是Microsoft链接程序,因此我必须手动为其提供所有MS库包含路径。 With these paths hardcoded, I manage to build my apps fine.
通过这些路径的硬编码,我可以很好地构建我的应用程序。 But I'd like to make my module more flexible and use
%LIB%
environment variable set by vcvars32.bat
| 但是,我想使我的模块更加灵活,并使用
vcvars32.bat
设置的%LIB%
环境变量。 vcvars64.bat
As far as I understand, this could (should?) be done inside module's setupBuildEnvironment
script. 据我了解,这可以(应该?)在模块的
setupBuildEnvironment
脚本中完成。 Here's what I try to read the %LIB%
and fail: 这是我尝试读取
%LIB%
并失败的内容:
import qbs.Environment
import qbs.Process
Module
{
setupBuildEnvironment:
{
var p = new Process();
p.exec("vcvars64.bat", [], true);
// makes no difference
// p.exec("cmd", ["/c", "vcvars64.bat"], true);
var lib = p.getEnv("LIB");
// this fails too
// var lib = Environment.getEnv("LIB");
console.info("LIB = " + lib);
p.close();
}
...
}
This gives me LIB =
so I'm getting nowhere. 这给了我
LIB =
所以我无处可去。 My guess is that the process is already terminated at the moment of querying the variable ( p.getEnv("LIB")
), hence the empty result. 我的猜测是,在查询变量(
p.getEnv("LIB")
)时,该过程已经终止,因此结果为空。 The QBS docs for Process.getEnv()
state nothing in this regard. 在这方面,针对
Process.getEnv()
的QBS文档没有任何规定。
What is the correct QBS way to initialize environment with vcvars64.bat
, and more broadly, what is the correct way to get environment of a process inside setupBuildEnvironment
? 用
vcvars64.bat
初始化环境的正确QBS方法是什么,更广泛地讲,在setupBuildEnvironment
获取进程环境的正确方法是什么?
[update] Well, embarassingly, this was easy to work around by creating a simple batch and getting rid of setupBuildEnvironment
script altogether: [更新]令人尴尬的是,通过创建一个简单的批处理并完全摆脱
setupBuildEnvironment
脚本,可以轻松解决此问题:
@echo off
call vcvars64 && qbs
But I'd like to avoid batch scripting as much as possible, so the question still stands. 但是我想尽可能避免批处理脚本,因此问题仍然存在。
The vars batch files just dump some information onto the console. vars批处理文件只是将一些信息转储到控制台上。 That does not set an environment on the calling process in any way.
这不会以任何方式在调用进程上设置环境。 You would need to parse the process output.
您将需要解析流程输出。 I suggest you take a look at the MsvcProbe item in the qbs sources to see how that is implemented for MSVC.
我建议您看一看qbs源中的MsvcProbe项,以了解如何为MSVC实施。 You might be able to adapt the code for clang-cl.
您可能可以将代码改编为clang-cl。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.