forked from alunny/node-xcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddBuildPhase.js
More file actions
120 lines (103 loc) · 5.67 KB
/
addBuildPhase.js
File metadata and controls
120 lines (103 loc) · 5.67 KB
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
var fullProject = require('./fixtures/full-project')
fullProjectStr = JSON.stringify(fullProject),
pbx = require('../lib/pbxProject'),
proj = new pbx('.');
function cleanHash() {
return JSON.parse(fullProjectStr);
}
exports.setUp = function (callback) {
proj.hash = cleanHash();
callback();
}
exports.addBuildPhase = {
'should return a pbxBuildPhase': function (test) {
var buildPhase = proj.addBuildPhase(['file.m'], 'PBXSourcesBuildPhase', 'My build phase');
test.ok(typeof buildPhase === 'object');
test.done()
},
'should set a uuid on the pbxBuildPhase': function (test) {
var buildPhase = proj.addBuildPhase(['file.m'], 'PBXSourcesBuildPhase', 'My build phase');
test.ok(buildPhase.uuid);
test.done()
},
'should add all files to build phase': function (test) {
var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase;
for (var index = 0; index < buildPhase.files.length; index++) {
var file = buildPhase.files[index];
test.ok(file.value);
}
test.done()
},
'should add the PBXBuildPhase object correctly': function (test) {
var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase,
buildPhaseInPbx = proj.buildPhaseObject('PBXResourcesBuildPhase', 'My build phase');
test.equal(buildPhaseInPbx, buildPhase);
test.equal(buildPhaseInPbx.isa, 'PBXResourcesBuildPhase');
test.equal(buildPhaseInPbx.buildActionMask, 2147483647);
test.equal(buildPhaseInPbx.runOnlyForDeploymentPostprocessing, 0);
test.done();
},
'should add each of the files to PBXBuildFile section': function (test) {
var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase,
buildFileSection = proj.pbxBuildFileSection();
for (var index = 0; index < buildPhase.files.length; index++) {
var file = buildPhase.files[index];
test.ok(buildFileSection[file.value]);
}
test.done();
},
'should add each of the files to PBXFileReference section': function (test) {
var buildPhase = proj.addBuildPhase(['file.m', 'assets.bundle'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase,
fileRefSection = proj.pbxFileReferenceSection(),
buildFileSection = proj.pbxBuildFileSection(),
fileRefs = [];
for (var index = 0; index < buildPhase.files.length; index++) {
var file = buildPhase.files[index],
fileRef = buildFileSection[file.value].fileRef;
test.ok(fileRefSection[fileRef]);
}
test.done();
},
'should not add files to PBXFileReference section if already added': function (test) {
var fileRefSection = proj.pbxFileReferenceSection(),
initialFileReferenceSectionItemsCount = Object.keys(fileRefSection),
buildPhase = proj.addBuildPhase(['AppDelegate.m', 'main.m'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase,
afterAdditionBuildFileSectionItemsCount = Object.keys(fileRefSection);
test.deepEqual(initialFileReferenceSectionItemsCount, afterAdditionBuildFileSectionItemsCount);
test.done();
},
'should not add files to PBXBuildFile section if already added': function (test) {
var buildFileSection = proj.pbxBuildFileSection(),
initialBuildFileSectionItemsCount = Object.keys(buildFileSection),
buildPhase = proj.addBuildPhase(['AppDelegate.m', 'main.m'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase,
afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection);
test.deepEqual(initialBuildFileSectionItemsCount, afterAdditionBuildFileSectionItemsCount);
test.done();
},
'should add only missing files to PBXFileReference section': function (test) {
var fileRefSection = proj.pbxFileReferenceSection(),
buildFileSection = proj.pbxBuildFileSection(),
initialFileReferenceSectionItemsCount = Object.keys(fileRefSection),
buildPhase = proj.addBuildPhase(['file.m', 'AppDelegate.m'], 'PBXResourcesBuildPhase', 'My build phase').buildPhase,
afterAdditionBuildFileSectionItemsCount = Object.keys(fileRefSection);
for (var index = 0; index < buildPhase.files.length; index++) {
var file = buildPhase.files[index],
fileRef = buildFileSection[file.value].fileRef;
test.ok(fileRefSection[fileRef]);
}
test.deepEqual(initialFileReferenceSectionItemsCount.length, afterAdditionBuildFileSectionItemsCount.length - 2);
test.done();
},
'should set target to Frameworks given \'frameworks\' as target': function (test) {
var buildPhase = proj.addBuildPhase(['file.m'], 'PBXCopyFilesBuildPhase', 'Copy Files', proj.getFirstTarget().uuid, 'frameworks').buildPhase;
test.equal(buildPhase.dstSubfolderSpec, 10);
test.done();
},
'should add a script build phase to echo "hello world!"': function(test) {
var options = {shellPath: '/bin/sh', shellScript: 'echo "hello world!"'};
var buildPhase = proj.addBuildPhase([], 'PBXShellScriptBuildPhase', 'Run a script', proj.getFirstTarget().uuid, options).buildPhase;
test.equal(buildPhase.shellPath, '/bin/sh');
test.equal(buildPhase.shellScript, '"echo \\"hello world!\\""');
test.done();
},
}