特殊属性值
根据上下文,Qbs 提供以下特殊值,供在属性绑定和 JavaScript 代码中使用
base
这个值在利用继承时很有用。它表示继承链中上一级条目相应属性的值。例如
Product { // defined in MyProduct.qbs
Depends { name: "mymodule" }
mymodule.someProperty: ["value1"]
}
------ some other file ------
MyProduct {
mymodule.someProperty: base.concat(["value2"]) // => ["value1", "value2"]
}exportingProduct
在 Export 项内部,你可以使用 exportingProduct 变量来引用定义 Export 项的产品
Product {
Export {
Depends { name: "cpp" }
cpp.includePaths: exportingProduct.sourceDirectory
}
}filePath
此值包含所述 .qbs 文件的全路径。这个属性很少使用,但在调试时可能有用
Product {
property bool dummy: {
console.info("I'm located at " + filePath);
}
}importingProduct
在 Export 项内部,你可以使用 importingProduct 变量来引用拉入结果的模块的产品
Product {
Export {
Depends { name: "cpp" }
cpp.includePaths: importingProduct.buildDirectory
}
}通常,你应该使用 product 变量以保持与 Module 项的一致性。
original
当在模块属性绑定的右边时,这表示模块自身(可能被配置文件覆盖)中属性的值。使用它有条件地设置模块属性
Module { // This is mymodule
property string aProperty: "z"
}
----------
Product {
Depends { name: "mymodule" }
Depends { name: "myothermodule" }
// "y" if myothermodule.anotherProperty is "x", "z" otherwise:
mymodule.aProperty: myothermodule.anotherProperty === "x" ? "y" : original
}outer
这个值用于嵌套项,其中它表示围绕项的相应属性的值。它只在 Group 和 Properties 项中有效
Product {
Depends { name: "mymodule" }
mymodule.someProperty: ["value1"]
Group {
name: "special files"
files: ["somefile1", "somefile2"]
mymodule.someProperty: outer.concat(["value"]) // => ["value1", "value2"]
}
}path
此值包含 .qbs 文件所在的文件夹路径。用例如将产品的目录添加到文件路径中
Product {
Depends { name: "cpp" }
cpp.includePaths: path
}product
此值包含包含当前项或拉入当前模块的产品属性
Module {
Rule {
Artifact {
fileTags: product.type
filePath: {
var result = input.fileName;
// module properties are available as well
if (product.qbs.buildVariant === "debug")
result = result + "_debug";
result = result + ".out";
return result;
}
}
}
}在 Export 项内部,等同于 importingProduct。
project
这个值包含引用当前项或拉入当前模块的项目属性
Project {
property bool enableProduct: true
Product {
name: "theProduct"
condition: project.enableProduct
}
}如果项目树中最接近的项目没有所需的属性,Qbs 将在父项目中查找它,可能一直查到顶级项目。
©2023 本文档中包含的 Qt 公司 Ltd. 文档贡献各自所有者的版权。提供的文档使用自由软件基金会发布的《GNU 自由文档许可证》第 1.3 版为您授权。Qt 及其相关标志为芬兰及其它国家/地区的 Qt 公司的商标。所有其他商标均为各自所有者的财产。