如何强制 qbs 产品与依赖关系之间的同步?



我有一个包含多个产品的项目,其中一些依赖于生成的代码(cpp 和 hpp 文件(。此生成的代码是自己的,具体取决于作为 CppApplication 的code_generator产品。

我希望如果他的来源发生变化,code_generator重建,然后始终运行。仅当输出文件发生更改时,它才会修改输出文件(它会在临时文件夹中内部生成它们,并在将它们移动到正确的位置之前使用校验和检查更改(。 然后,一旦生成文件,就可以开始编译其他产品。

我的问题是,在构建code_generator.exe之前,我在其中放置生成的文件的静态库就开始构建。其他依赖于静态库的产品也可以在生成 .hpp 文件之前开始构建。

所以我的问题是:是否有一些机制可以用来使产品等到完全构建特定的依赖项?

我对任何类型的解决方案都持开放态度,生成的代码可以在任何类型的模块中,我只是尝试使用静态库,因为它似乎更方便。

PS:code_generator产品生成了很多文件,并且很少输入我在qbs中没有精确定位,因为它始终可以运行,并且可以将其视为输入本身,因为它可以更改。这就是为什么我不确定使用规则对我来说是否真的有趣。

这是我的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;
}
}

最新更新