c++ - 如何在具有依赖关系的 qbs 产品之间强制同步?
问题描述
我有一个包含多个产品的项目,其中一些取决于生成的代码(cpp 和 hpp 文件)。这个生成的代码是它自己取决于作为 CppApplication 的 code_generator 产品。
如果他的来源发生变化,我希望重新构建 code_generator,然后始终运行。只有在输出文件发生更改时才会修改输出文件(它在内部将它们生成在一个临时文件夹中,并在将它们移动到正确的位置之前使用校验和检查更改)。然后一旦生成文件,其他产品的编译就可以开始了。
我的问题是,在构建 code_generator.exe 之前,我将生成的文件放入其中的 StaticLibrary 开始构建。其他依赖于 StaticLibrary 的产品也可以在生成 .hpp 文件之前开始构建。
所以我的问题是:是否有一些机制可以让产品等到完全建立特定的依赖项?
我对任何类型的解决方案持开放态度,生成的代码可以在任何类型的模块中,我只是尝试使用 StaticLibrary,因为它看起来更方便。
PS:code_generator 产品生成了很多文件,并采用了一些我在 qbs 中不精确的输入,因为它始终可以运行,并且可以将其视为输入本身,因为它可以更改。这就是为什么我不确定使用 Rule 对我来说是否真的很有趣。
这是我的 qbs 文件的摘录:
CppApplication
{
name: "code_generator"
consoleApplication: true
files: [
"../sources/code_generator/code_generator.cpp",
"../sources/code_generator/code_generator.hpp",
...
]
Depends { name: "default-cpp-configuration" }
Depends { name: "tinyxml2" }
destinationDirectory: "../" // @Warning we move the binary to ease his usage by the "generated_code" module
}
StaticLibrary // @Warning as static library to build those sources only once
{
name: "generated_code"
Depends { name: "default-cpp-configuration" }
Depends { name: "code_generator" }
Rule {
multiplex: true
alwaysRun: true
// inputs: [project.buildDirectory + "/../code_generator.exe"]
Artifact { filePath: "generated/common/directx/driver_call_table.cpp"; fileTags: "cpp" }
Artifact { filePath: "generated/common/directx/driver_call_table.hpp"; fileTags: "hpp" }
Artifact { filePath: "generated/common/directx/d3d11.def"; fileTags: "def" }
Artifact { filePath: "generated/common/directx/uuid_helpers.cpp"; fileTags: "cpp" }
Artifact { filePath: "generated/common/directx/uuid_helpers.hpp"; fileTags: "hpp" }
prepare: {
var code_generator_path = project.buildDirectory + "/../code_generator.exe";
var cmd = new Command(code_generator_path, ["DirectX", "Outdir=${GENERATED_SOURCES_PATH}", "Indir=${CMAKE_SOURCE_DIR}/lib/specs", "CompilerPath=${CMAKE_CXX_COMPILER}", "--preprocess"]);
cmd.description = "generating sources";
return cmd;
}
}
}
CppApplication
{
name: "client"
consoleApplication: true
files: [
"../sources/client/main.cpp",
]
Depends { name: "default-cpp-configuration" }
Depends { name: "generated_code" }
Depends { name: "openssl" }
}
解决方案
产品依赖关系只是使产品的工件在依赖产品的规则中可用。它们本身不会引起同步。同步发生在工件级别;否则,并行化将受到阻碍。您的问题是您的规则没有说明它取决于代码生成器可执行文件。这是它的样子(未经测试):
Rule {
multiplex: true
inputsFromDependencies: "application" // These are tags, not paths!
Artifact {
filePath: "generated/common/directx/driver_call_table.cpp"
fileTags: "cpp"
}
Artifact {
filePath: "generated/common/directx/driver_call_table.hpp"
fileTags: "hpp"
}
Artifact {
filePath: "generated/common/directx/d3d11.def"
fileTags: "def"
}
Artifact {
filePath: "generated/common/directx/uuid_helpers.cpp"
fileTags: "cpp"
}
Artifact {
filePath: "generated/common/directx/uuid_helpers.hpp"
fileTags: "hpp"
}
prepare: {
var code_generator_path = inputs.application[0].filePath;
var args = [
"DirectX", "Outdir=${GENERATED_SOURCES_PATH}",
"Indir=${CMAKE_SOURCE_DIR}/lib/specs",
CompilerPath=${CMAKE_CXX_COMPILER}", "--preprocess"
];
var cmd = new Command(code_generator_path, args);
cmd.description = "generating sources";
return cmd;
}
}
推荐阅读
- http - HTTP 文本有效负载的内容长度的正确值
- c# - BouncyCastle 时间戳协议 | 如何从 TimeStampToken 获取原始哈希?
- reactjs - 如何将componentDidMount函数传递给React中的深层子级
- neo4j - 如何在 Neo4j 节点中显示特定属性
- r - 可以在 R 中读取 .wma 声音文件吗?
- c++ - g++ 内联调用 always_inline "int _rdrand16_step()" 失败
- java - HttpHeaders getFirst() 不区分大小写
- javascript - 当我尝试使用 window.print() 打印两个或更多文档时,只有第一个显示内容
- mongodb - mgo golang 不使用 $set 更新空数组
- python - 在 Python 中搜索加载的文件