summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@petroules.com>2014-10-08 02:53:48 -0400
committerJoerg Bornemann <joerg.bornemann@digia.com>2014-10-10 16:32:37 +0200
commit203640bb34445c4f4d65823ca6640450f356bfef (patch)
treeec7d02205120223a14aebee3e1956c034b8e2b95
parent2b0184cf3e57942585ca4abd4311776d3998d4dc (diff)
downloadqbs-203640bb34445c4f4d65823ca6640450f356bfef.tar.gz
Refactor IB module a bit. This fixes the asset catalog autotest.
Task-number: QBS-669 Change-Id: I026bc51cd73db64bf8f96163362af4e9b77c70e3 Reviewed-by: Christian Kandeler <christian.kandeler@digia.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r--share/qbs/modules/ib/IBModule.qbs90
-rw-r--r--share/qbs/modules/ib/ib.js53
-rw-r--r--tests/auto/blackbox/testdata/ib/assetcatalog/assetcatalogempty.qbs4
-rw-r--r--tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/Contents.json22
-rw-r--r--tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/icon_16x16.pngbin0 -> 3303 bytes
-rw-r--r--tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/icon_16x16@2x.pngbin0 -> 3336 bytes
-rw-r--r--tests/auto/blackbox/tst_blackbox.cpp2
7 files changed, 115 insertions, 56 deletions
diff --git a/share/qbs/modules/ib/IBModule.qbs b/share/qbs/modules/ib/IBModule.qbs
index 385275fe3..e84cf3b46 100644
--- a/share/qbs/modules/ib/IBModule.qbs
+++ b/share/qbs/modules/ib/IBModule.qbs
@@ -3,6 +3,7 @@ import qbs.BundleTools
import qbs.DarwinTools
import qbs.FileInfo
import qbs.ModUtils
+import qbs.Process
import 'ib.js' as Ib
Module {
@@ -85,9 +86,11 @@ Module {
Artifact {
filePath: {
- var outputDirectory = BundleTools.isBundleProduct(product)
- ? BundleTools.unlocalizedResourcesFolderPath(product)
- : product.destinationDirectory;
+ var outputDirectory = product.destinationDirectory;
+ if (BundleTools.isBundleProduct(product)) {
+ outputDirectory = FileInfo.joinPaths(outputDirectory,
+ BundleTools.unlocalizedResourcesFolderPath(product));
+ }
return FileInfo.joinPaths(outputDirectory, input.completeBaseName + ModUtils.moduleProperty(product, "appleIconSuffix"))
}
fileTags: ["icns"]
@@ -152,16 +155,8 @@ Module {
}
prepare: {
- var args = Ib.prepareIbtoold(product, input, outputs);
-
- var flags = ModUtils.moduleProperty(input, "flags");
- if (flags)
- args = args.concat(flags);
-
- args.push("--compile", outputs.compiled_ibdoc[0].filePath);
- args.push(input.filePath);
-
- var cmd = new Command(ModUtils.moduleProperty(input, "ibtoolPath"), args);
+ var cmd = new Command(ModUtils.moduleProperty(input, "ibtoolPath"),
+ Ib.ibtooldArguments(product, input, outputs));
cmd.description = ModUtils.moduleProperty(input, "ibtoolName") + ' ' + input.fileName;
// Also display the language name of the nib/storyboard being compiled if it has one
@@ -187,26 +182,42 @@ Module {
Rule {
inputs: ["assetcatalog"]
- // We only return one artifact, as this is a little complicated...
// actool takes an output *directory*, and in this directory it will
// potentially output "Assets.car" and/or one or more additional files.
// We can discover which files were written in an easily parseable manner
- // through use of --output-format xml1, but we have a chicken and egg problem
- // in that we only gain that information *after* running the compilation, so
- // if we want to know in advance which artifacts are generated we have to run
- // the compilation twice which probably isn't worth it.
+ // through use of --output-format xml1
outputArtifacts: {
- var outputDirectory = BundleTools.isBundleProduct(product)
- ? BundleTools.unlocalizedResourcesFolderPath(product)
- : product.destinationDirectory;
- return [{
- filePath: FileInfo.joinPaths(outputDirectory, "Assets" + ModUtils.moduleProperty(product, "compiledAssetCatalogSuffix")),
- fileTags: ["compiled_assetcatalog"]
- },
- {
- filePath: FileInfo.joinPaths(product.destinationDirectory, "assetcatalog_generated_info.plist"),
- fileTags: ["partial_infoplist"]
- }];
+ var outputDirectory = product.destinationDirectory;
+ if (BundleTools.isBundleProduct(product)) {
+ outputDirectory = FileInfo.joinPaths(outputDirectory,
+ BundleTools.unlocalizedResourcesFolderPath(product));
+ }
+
+ // Chicken and egg... create a fake outputs dictionary for building actool args list
+ var outputs = {
+ partial_infoplist: [{filePath: FileInfo.joinPaths(product.destinationDirectory, "assetcatalog_generated_info.plist")}],
+ compiled_assetcatalog: [{filePath: FileInfo.joinPaths(outputDirectory, "Assets" + ModUtils.moduleProperty(product, "compiledAssetCatalogSuffix"))}]
+ };
+
+ var process = new Process();
+ try {
+ process.exec("mkdir", ["-p", outputDirectory], true);
+ } finally {
+ process.close();
+ }
+
+ var filePaths = Ib.runActool(ModUtils.moduleProperty(input, "actoolPath"),
+ Ib.ibtooldArguments(product, input, outputs));
+
+ var artifacts = [];
+ for (var i in filePaths) {
+ artifacts.push({
+ filePath: filePaths[i],
+ fileTags: filePaths[i] === outputs.partial_infoplist[0].filePath ? ["partial_infoplist"] : ["compiled_assetcatalog"]
+ });
+ }
+
+ return artifacts;
}
outputFileTags: ["compiled_assetcatalog", "partial_infoplist"]
@@ -217,28 +228,9 @@ Module {
// There's also the undocumented --export-dependency-info <output.txt> which is used by Xcode and generated a \0x00\0x02-delimited
// file (yes, really) that contains the output file names, identical to the output of actool itself (what's the point?).
prepare: {
- var args = Ib.prepareIbtoold(product, input, outputs);
-
- var flags = ModUtils.moduleProperty(input, "flags");
- if (flags)
- args = args.concat(flags);
-
- var outputPath = FileInfo.path(outputs.compiled_assetcatalog[0].filePath);
-
- args.push("--compile");
- args.push(outputPath);
- args.push(input.filePath);
-
- var cmd = new Command(ModUtils.moduleProperty(input, "actoolPath"), args);
+ var cmd = new JavaScriptCommand();
cmd.description = ModUtils.moduleProperty(input, "actoolName") + ' ' + input.fileName;
cmd.highlight = "compiler";
- cmd.stdoutFilterFunction = function(stdout) {
- stdout = stdout.replace("/* com.apple.actool.compilation-results */\n", "");
- return stdout.split("\n").filter(function(line) {
- return line.length > 0 /*&& line.indexOf(outputPath) !== 0*/;
- }).join("\n");
- }
-
return cmd;
}
}
diff --git a/share/qbs/modules/ib/ib.js b/share/qbs/modules/ib/ib.js
index 7e6764c70..6d1d68dee 100644
--- a/share/qbs/modules/ib/ib.js
+++ b/share/qbs/modules/ib/ib.js
@@ -1,17 +1,20 @@
var DarwinTools = loadExtension("qbs.DarwinTools");
+var FileInfo = loadExtension("qbs.FileInfo");
var ModUtils = loadExtension("qbs.ModUtils");
var Process = loadExtension("qbs.Process");
var PropertyList = loadExtension("qbs.PropertyList");
-function prepareIbtoold(product, input, outputs) {
+function ibtooldArguments(product, input, outputs) {
var args = [];
var outputFormat = ModUtils.moduleProperty(input, "outputFormat");
- if (!["binary1", "xml1", "human-readable-text"].contains(outputFormat))
- throw("Invalid ibtoold output format: " + outputFormat + ". " +
- "Must be in [binary1, xml1, human-readable-text].");
+ if (outputFormat) {
+ if (!["binary1", "xml1", "human-readable-text"].contains(outputFormat))
+ throw("Invalid ibtoold output format: " + outputFormat + ". " +
+ "Must be in [binary1, xml1, human-readable-text].");
- args.push("--output-format", outputFormat);
+ args.push("--output-format", outputFormat);
+ }
if (ModUtils.moduleProperty(input, "warnings"))
args.push("--warnings");
@@ -82,9 +85,49 @@ function prepareIbtoold(product, input, outputs) {
}
}
+ var flags = ModUtils.moduleProperty(input, "flags");
+ if (flags)
+ args = args.concat(flags);
+
+ if (outputs.compiled_ibdoc)
+ args.push("--compile", outputs.compiled_ibdoc[0].filePath);
+
+ if (outputs.compiled_assetcatalog)
+ args.push("--compile", FileInfo.path(outputs.compiled_assetcatalog[0].filePath));
+
+ args.push(input.filePath);
+
return args;
}
+function runActool(actool, args) {
+ var process;
+ var outputFilePaths;
+ try {
+ process = new Process();
+
+ // Last --output-format argument overrides any previous ones
+ if (process.exec(actool, args.concat(["--output-format", "xml1"]), true) !== 0)
+ print(process.readStdErr());
+
+ var propertyList = new PropertyList();
+ try {
+ propertyList.readFromString(process.readStdOut());
+
+ var plist = JSON.parse(propertyList.toJSONString());
+ if (plist)
+ plist = plist["com.apple.actool.compilation-results"];
+ if (plist)
+ outputFilePaths = plist["output-files"];
+ } finally {
+ propertyList.clear();
+ }
+ } finally {
+ process.close();
+ }
+ return outputFilePaths;
+}
+
function ibtoolVersion(ibtool) {
var process;
var version;
diff --git a/tests/auto/blackbox/testdata/ib/assetcatalog/assetcatalogempty.qbs b/tests/auto/blackbox/testdata/ib/assetcatalog/assetcatalogempty.qbs
index d29a39bce..2e31c03fc 100644
--- a/tests/auto/blackbox/testdata/ib/assetcatalog/assetcatalogempty.qbs
+++ b/tests/auto/blackbox/testdata/ib/assetcatalog/assetcatalogempty.qbs
@@ -6,9 +6,11 @@ Project {
CppApplication {
Depends { name: "ib" }
files: {
- var filez = ["main.c", "empty.xcassets", "MainMenu.xib"];
+ var filez = ["main.c", "MainMenu.xib"];
if (project.includeIconset)
filez.push("empty.xcassets/empty.iconset");
+ else
+ filez.push("empty.xcassets");
if (qbs.hostOSVersionMinor >= 10) // need OS X 10.10 to build SBs
filez.push("Storyboard.storyboard");
return filez;
diff --git a/tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/Contents.json b/tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/Contents.json
new file mode 100644
index 000000000..4b1cfb1f0
--- /dev/null
+++ b/tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/Contents.json
@@ -0,0 +1,22 @@
+{
+ "images" : [
+ {
+ "idiom" : "universal",
+ "scale" : "1x",
+ "filename" : "icon_16x16.png"
+ },
+ {
+ "idiom" : "universal",
+ "scale" : "2x",
+ "filename" : "icon_16x16@2x.png"
+ },
+ {
+ "idiom" : "universal",
+ "scale" : "3x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+} \ No newline at end of file
diff --git a/tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/icon_16x16.png b/tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/icon_16x16.png
new file mode 100644
index 000000000..65ff1ff57
--- /dev/null
+++ b/tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/icon_16x16.png
Binary files differ
diff --git a/tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/icon_16x16@2x.png b/tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/icon_16x16@2x.png
new file mode 100644
index 000000000..a5c69bccd
--- /dev/null
+++ b/tests/auto/blackbox/testdata/ib/assetcatalog/empty.xcassets/other.imageset/icon_16x16@2x.png
Binary files differ
diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp
index cde04882e..5c4ce9168 100644
--- a/tests/auto/blackbox/tst_blackbox.cpp
+++ b/tests/auto/blackbox/tst_blackbox.cpp
@@ -2418,7 +2418,7 @@ void TestBlackbox::testAssetCatalog()
rmDirR(buildDir);
params.arguments.append("project.includeIconset:true");
QCOMPARE(runQbs(params), 0);
- QVERIFY((bool)m_qbsStdout.contains("actool"));
+ QVERIFY(!(bool)m_qbsStdout.contains("actool"));
QVERIFY((bool)m_qbsStdout.contains("iconutil"));
// make sure the nibs/storyboards are in there