1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
import qbs 1.0
import qbs.fileinfo as FileInfo
import '../utils.js' as ModUtils
import "bundle-tools.js" as BundleTools
import "darwin-tools.js" as DarwinTools
UnixGCC {
condition: false
compilerDefines: ["__GNUC__", "__APPLE__"]
dynamicLibrarySuffix: ".dylib"
property path infoPlistFile
property var infoPlist
property bool processInfoPlist: true
property string infoPlistFormat: {
if (qbs.targetOS.contains("osx"))
return infoPlistFile ? "same-as-input" : "xml1"
else if (qbs.targetOS.contains("ios"))
return "binary1"
}
property bool buildDsym: qbs.buildVariant === "release"
property var buildEnv: {
var env = {
"LANG": "en_US.US-ASCII"
}
if (minimumIosVersion)
env["IPHONEOS_DEPLOYMENT_TARGET"] = minimumIosVersion;
if (minimumOsxVersion)
env["MACOSX_DEPLOYMENT_TARGET"] = minimumOsxVersion;
return env;
}
setupBuildEnvironment: {
var v = new ModUtils.EnvironmentVariable("PATH", ":", false);
v.prepend(platformPath + "/Developer/usr/bin");
var platformPathL = platformPath.split("/");
platformPathL.pop();
platformPathL.pop();
var devPath = platformPathL.join("/")
v.prepend(devPath + "/usr/bin");
v.set();
for (var key in buildEnv) {
v = new ModUtils.EnvironmentVariable(key);
v.value = buildEnv[key];
v.set();
}
}
readonly property var defaultInfoPlist: {
var dict = {
CFBundleDevelopmentRegion: "en", // default localization
CFBundleDisplayName: product.targetName, // localizable
CFBundleExecutable: product.targetName,
CFBundleIdentifier: "org.example." + DarwinTools.rfc1034(product.targetName),
CFBundleInfoDictionaryVersion: "6.0",
CFBundleName: product.targetName, // short display name of the bundle, localizable
CFBundlePackageType: BundleTools.packageType(product),
CFBundleShortVersionString: product.version || "1.0", // "release" version number, localizable
CFBundleSignature: "????", // legacy creator code in Mac OS Classic, can be ignored
CFBundleVersion: product.version || "1.0.0" // build version number, must be 3 octets
};
if (product.type.contains("applicationbundle"))
dict["CFBundleIconFile"] = product.targetName;
if (qbs.targetOS.contains("osx") && minimumOsxVersion)
dict["LSMinimumSystemVersion"] = minimumOsxVersion;
if (qbs.targetOS.contains("ios")) {
dict["LSRequiresIPhoneOS"] = true;
// architectures supported, to support iPhone 3G for example one has to add
// armv6 to the list and also compile for it (with Xcode 4.4.1 or earlier)
dict["UIRequiredDeviceCapabilities"] = [ "armv7" ];
var orientations = [
"UIInterfaceOrientationPortrait",
"UIInterfaceOrientationLandscapeLeft",
"UIInterfaceOrientationLandscapeRight"
];
dict["UISupportedInterfaceOrientations"] = orientations;
orientations.splice(1, 0, "UIInterfaceOrientationPortraitUpsideDown");
dict["UISupportedInterfaceOrientations~ipad"] = orientations;
}
return dict;
}
Rule {
multiplex: true
inputs: ["infoplist"]
explicitlyDependsOn: ["infoplist"]
Artifact {
fileName: product.destinationDirectory + "/" + BundleTools.pkgInfoPath(product)
fileTags: ["pkginfo"]
}
prepare: {
var cmd = new JavaScriptCommand();
cmd.description = "generating PkgInfo";
cmd.highlight = "codegen";
cmd.sourceCode = function() {
var infoPlist = BundleTools.infoPlistContents(inputs.infoplist[0].fileName);
var pkgType = infoPlist['CFBundlePackageType'];
if (!pkgType)
throw("CFBundlePackageType not found in Info.plist; this should not happen");
var pkgSign = infoPlist['CFBundleSignature'];
if (!pkgSign)
throw("CFBundleSignature not found in Info.plist; this should not happen");
var pkginfo = new TextFile(outputs.pkginfo[0].fileName, TextFile.WriteOnly);
pkginfo.write(pkgType + pkgSign);
pkginfo.close();
}
return cmd;
}
}
Rule {
multiplex: true
inputs: ["qbs"]
Artifact {
fileName: product.destinationDirectory + "/" + BundleTools.infoPlistPath(product)
fileTags: ["infoplist"]
}
prepare: {
var cmd = new JavaScriptCommand();
cmd.description = "generating Info.plist";
cmd.highlight = "codegen";
cmd.infoPlistFile = ModUtils.moduleProperty(product, "infoPlistFile");
cmd.infoPlist = ModUtils.moduleProperty(product, "infoPlist") || {};
cmd.processInfoPlist = ModUtils.moduleProperty(product, "processInfoPlist");
cmd.infoPlistFormat = ModUtils.moduleProperty(product, "infoPlistFormat");
cmd.platformPath = product.moduleProperty("cpp", "platformPath");
cmd.toolchainInstallPath = product.moduleProperty("cpp", "toolchainInstallPath");
cmd.sysroot = product.moduleProperty("qbs", "sysroot");
cmd.buildEnv = product.moduleProperty("cpp", "buildEnv");
cmd.sourceCode = function() {
var process, key;
// Contains the combination of default, file, and in-source keys and values
// Start out with the contents of this file as the "base", if given
var aggregatePlist = BundleTools.infoPlistContents(infoPlistFile) || {};
// Add local key-value pairs (overrides equivalent keys specified in the file if
// one was given)
for (key in infoPlist) {
if (infoPlist.hasOwnProperty(key))
aggregatePlist[key] = infoPlist[key];
}
// Do some postprocessing if desired
if (processInfoPlist) {
// Add default values to the aggregate plist if the corresponding keys
// for those values are not already present
var defaultValues = ModUtils.moduleProperty(product, "defaultInfoPlist");
for (key in defaultValues) {
if (defaultValues.hasOwnProperty(key) && !(key in aggregatePlist))
aggregatePlist[key] = defaultValues[key];
}
// Add keys from platform's Info.plist if not already present
if (platformPath) {
process = new Process();
process.start("plutil", ["-convert", "json", "-o", "-",
[platformPath, "Info.plist"].join('/')]);
process.waitForFinished();
platformInfo = JSON.parse(process.readAll());
var additionalProps = platformInfo["AdditionalInfo"];
for (key in additionalProps) {
if (additionalProps.hasOwnProperty(key) && !(key in aggregatePlist)) // override infoPlist?
aggregatePlist[key] = defaultValues[key];
}
props = platformInfo['OverrideProperties'];
for (key in props) {
aggregatePlist[key] = props[key];
}
if (product.moduleProperty("qbs", "targetOS").contains("ios")) {
key = "UIDeviceFamily";
if (key in platformInfo && !(key in aggregatePlist))
aggregatePlist[key] = platformInfo[key];
}
} else {
print("Missing platformPath property");
}
if (sysroot) {
process = new Process();
process.start("plutil", ["-convert", "json", "-o", "-",
sysroot + "/SDKSettings.plist"]);
process.waitForFinished();
sdkSettings = JSON.parse(process.readAll());
} else {
print("Missing sysroot (SDK path)");
}
if (toolchainInstallPath) {
process = new Process();
process.start("plutil", ["-convert", "json", "-o", "-",
toolchainInstallPath + "/../../ToolchainInfo.plist"]);
process.waitForFinished();
toolchainInfo = JSON.parse(process.readAll());
} else {
print("Cannot get the ToolchainInfo.plist from the toolchainInstallPath");
}
process = new Process();
process.start("sw_vers", ["-buildVersion"]);
process.waitForFinished();
aggregatePlist["BuildMachineOSBuild"] = process.readAll().trim();
// setup env
env = {
"SDK_NAME": sdkSettings["CanonicalName"],
"XCODE_VERSION_ACTUAL": toolchainInfo["DTXcode"],
"SDK_PRODUCT_BUILD_VERSION": toolchainInfo["DTPlatformBuild"],
"GCC_VERSION": platformInfo["DTCompiler"],
"XCODE_PRODUCT_BUILD_VERSION": platformInfo["DTPlatformBuild"],
"PLATFORM_PRODUCT_BUILD_VERSION": platformInfo["ProductBuildVersion"],
}
process = new Process();
process.start("sw_vers", ["-buildVersion"]);
process.waitForFinished();
env["MAC_OS_X_PRODUCT_BUILD_VERSION"] = process.readAll().trim();
for (key in buildEnv)
env[key] = buildEnv[key];
DarwinTools.doRepl(infoPlist, env, true);
}
// Write the plist contents as JSON
var infoplist = new TextFile(outputs.infoplist[0].fileName, TextFile.WriteOnly);
infoplist.write(JSON.stringify(aggregatePlist));
infoplist.close();
if (infoPlistFormat === "same-as-input" && infoPlistFile)
infoPlistFormat = BundleTools.infoPlistFormat(infoPlistFile);
var validFormats = [ "xml1", "binary1", "json" ];
if (!validFormats.contains(infoPlistFormat))
throw("Invalid Info.plist format " + infoPlistFormat + ". " +
"Must be in [xml1, binary1, json].");
// Convert the written file to the format appropriate for the current platform
process = new Process();
process.start("plutil", ["-convert", infoPlistFormat, outputs.infoplist[0].fileName]);
process.waitForFinished();
}
return cmd;
}
}
Rule {
condition: product.moduleProperty("cpp", "buildDsym")
inputs: ["application"]
Artifact {
fileName: product.destinationDirectory + "/" + PathTools.dwarfDsymFileName()
fileTags: ["dsym"]
}
prepare: {
var cmd = new Command("dsymutil", ["--out=" + outputs.dsym[0].fileName, input.fileName]);
cmd.description = "generating dsym";
cmd.highlight = "codegen";
return cmd;
}
}
Rule {
multiplex: true
inputs: ["application", "infoplist", "pkginfo", "dsym", "nib", "resourcerules", "ipa"]
Artifact {
fileName: product.destinationDirectory + "/" + BundleTools.wrapperName(product)
fileTags: ["applicationbundle"]
}
prepare: {
// This command is intentionally empty; it just lets the user know a bundle has been made
var cmd = new JavaScriptCommand();
cmd.description = "creating app bundle";
cmd.highlight = "codegen";
return cmd;
}
}
Rule {
multiplex: true
inputs: ["dynamiclibrary", "infoplist", "pkginfo", "dsym", "nib"]
Artifact {
fileName: product.destinationDirectory + "/" + BundleTools.wrapperName(product)
fileTags: ["frameworkbundle"]
}
prepare: {
var commands = [];
var cmd = new Command("ln", ["-s", BundleTools.frameworkVersion(product), "Current"]);
cmd.workingDirectory = output.fileName + "/Versions";
cmd.description = "creating framework " + product.targetName;
cmd.highlight = "codegen";
commands.push(cmd);
cmd = new Command("ln", ["-s", "Versions/Current/Headers", "Headers"]);
cmd.workingDirectory = output.fileName;
commands.push(cmd);
cmd = new Command("ln", ["-s", "Versions/Current/Resources", "Resources"]);
cmd.workingDirectory = output.fileName;
commands.push(cmd);
cmd = new Command("ln", ["-s", "Versions/Current/" + product.targetName, product.targetName]);
cmd.workingDirectory = output.fileName;
commands.push(cmd);
return commands;
}
}
FileTagger {
pattern: "*.xib"
fileTags: ["xib"]
}
Rule {
inputs: ["xib"]
explicitlyDependsOn: ["infoplist"]
Artifact {
fileName: {
var path = product.destinationDirectory;
var xibFilePath = input.baseDir + '/' + input.fileName;
var key = DarwinTools.localizationKey(xibFilePath);
if (key) {
path += '/' + BundleTools.localizedResourcesFolderPath(product, key);
var subPath = DarwinTools.relativeResourcePath(xibFilePath);
if (subPath && subPath !== '.')
path += '/' + subPath;
} else {
path += '/' + BundleTools.unlocalizedResourcesFolderPath(product);
path += '/' + input.baseDir;
}
return path + '/' + input.completeBaseName + ".nib";
}
fileTags: ["nib"]
}
prepare: {
var cmd = new Command("ibtool", [
'--output-format', 'human-readable-text',
'--warnings', '--errors', '--notices',
'--compile', output.fileName, input.fileName,
'--sdk', product.moduleProperty("qbs", "sysroot")]);
cmd.description = 'ibtool ' + FileInfo.fileName(input.fileName);
// Also display the language name of the XIB being compiled if it has one
var localizationKey = DarwinTools.localizationKey(input.fileName);
if (localizationKey)
cmd.description += ' (' + localizationKey + ')';
cmd.highlight = 'compiler';
return cmd;
}
}
}
|