Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
QBS module that produce binnary resource files.
import qbs
import qbs.FileInfo
import qbs.Xml
Module {
property bool compress: false
FileTagger {
patterns: "*.qrc"
fileTags: ["qrc"]
}
Rule {
inputs: ["qrc"] // needed to trigger this rule
Artifact {
filePath: {
return FileInfo.baseName(input.fileName)+".rcc";
}
fileTags: ["rcc"]
}
prepare: {
var rccToolPath = product.moduleProperty("Qt.core", "binPath");
if(!rccToolPath) throw "Unknown resource compiler path:\"" + rccTool + "\"!";
var args = ["-binary", input.filePath,
"-o",output.filePath ];
if(!product.moduleProperty("binaryrcc","compress"))
args.unshift("-no-compress");
var cmd = new Command(rccToolPath+"/rcc", args);
cmd.description = "generating binnary rcc from "+input.fileName;
return cmd;
}
}
Scanner {
inputs: ["qrc"]
scan: {
var xml = new XmlDomDocument();
xml.load(input.fileName);
var fileTag = xml.firstChild("RCC").firstChild("qresource");
fileTag= fileTag.firstChild("file");
var dependencies = [];
while(fileTag&&fileTag.isElement()) {
dependencies.push(fileTag.text());
fileTag= fileTag.nextSibling("file");
}
print(input.fileName+" depends on:\n "+dependencies.join("\n "));
return dependencies;
}
}
Depends { name: "Qt.core" }
}
Product {
name:"resources"
type:"rcc"
files: "*.qrc"
Group {
fileTagsFilter: product.type
qbs.install: true
}
qbsSearchPaths: "."
Depends { name: "binaryrcc" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment