Skip to content

Commit be6005e

Browse files
author
Anis Kadri
committed
Merge branch 'robertoandrade-forkChanges'
2 parents 6d88702 + 8c6fa3a commit be6005e

File tree

5 files changed

+1367
-25
lines changed

5 files changed

+1367
-25
lines changed

lib/pbxFile.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ function detectGroup(fileRef) {
110110
}
111111

112112
function detectSourcetree(fileRef) {
113-
113+
114114
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
115115
sourcetree = SOURCETREE_BY_FILETYPE[unquoted(filetype)];
116116

117117
if (fileRef.explicitFileType) {
118118
return DEFAULT_PRODUCT_SOURCETREE;
119119
}
120-
120+
121121
if (fileRef.customFramework) {
122122
return DEFAULT_SOURCETREE;
123123
}
124-
124+
125125
if (!sourcetree) {
126126
return DEFAULT_SOURCETREE;
127127
}
@@ -136,7 +136,7 @@ function defaultPath(fileRef, filePath) {
136136
if (fileRef.customFramework) {
137137
return filePath;
138138
}
139-
139+
140140
if (defaultPath) {
141141
return path.join(defaultPath, path.basename(filePath));
142142
}
@@ -156,7 +156,7 @@ function defaultGroup(fileRef) {
156156

157157
function pbxFile(filepath, opt) {
158158
var opt = opt || {};
159-
159+
160160
self = this;
161161

162162
this.basename = path.basename(filepath);
@@ -194,6 +194,14 @@ function pbxFile(filepath, opt) {
194194
this.settings = {};
195195
this.settings.COMPILER_FLAGS = util.format('"%s"', opt.compilerFlags);
196196
}
197+
198+
if (opt.sign) {
199+
if (!this.settings)
200+
this.settings = {};
201+
if (!this.settings.ATTRIBUTES)
202+
this.settings.ATTRIBUTES = [];
203+
this.settings.ATTRIBUTES.push('CodeSignOnCopy');
204+
}
197205
}
198206

199207
module.exports = pbxFile;

lib/pbxProject.js

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,24 @@ pbxProject.prototype.addFramework = function(fpath, opt) {
270270

271271
if (this.hasFile(file.path)) return false;
272272

273+
var customFramework = opt && opt.customFramework == true;
274+
var link = !opt || (opt.link == undefined || opt.link); //defaults to true if not specified
275+
var embed = opt && opt.embed; //defaults to false if not specified
276+
273277
this.addToPbxBuildFileSection(file); // PBXBuildFile
274278
this.addToPbxFileReferenceSection(file); // PBXFileReference
275279
this.addToFrameworksPbxGroup(file); // PBXGroup
276-
this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase
277280

278-
if (opt && opt.customFramework == true) {
281+
if (link) {
282+
this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase
283+
}
284+
285+
if (customFramework) {
279286
this.addToFrameworkSearchPaths(file);
287+
288+
if (embed) {
289+
this.addToPbxEmbedFrameworksBuildPhase(file); // PBXCopyFilesBuildPhase
290+
}
280291
}
281292

282293
return file;
@@ -286,10 +297,11 @@ pbxProject.prototype.removeFramework = function(fpath, opt) {
286297
var file = new pbxFile(fpath, opt);
287298
file.target = opt ? opt.target : undefined;
288299

289-
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
290-
this.removeFromPbxFileReferenceSection(file); // PBXFileReference
291-
this.removeFromFrameworksPbxGroup(file); // PBXGroup
292-
this.removeFromPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase
300+
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
301+
this.removeFromPbxFileReferenceSection(file); // PBXFileReference
302+
this.removeFromFrameworksPbxGroup(file); // PBXGroup
303+
this.removeFromPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase
304+
this.removeFromPbxEmbedFrameworksBuildPhase(file); // PBXCopyFilesBuildPhase
293305

294306
if (opt && opt.customFramework) {
295307
this.removeFromFrameworkSearchPaths(path.dirname(fpath));
@@ -578,6 +590,24 @@ pbxProject.prototype.removeFromFrameworksPbxGroup = function(file) {
578590
}
579591
}
580592

593+
pbxProject.prototype.addToPbxEmbedFrameworksBuildPhase = function (file) {
594+
var sources = this.pbxEmbedFrameworksBuildPhaseObj(file.target);
595+
if (sources) {
596+
sources.files.push(pbxBuildPhaseObj(file));
597+
}
598+
}
599+
600+
pbxProject.prototype.removeFromPbxEmbedFrameworksBuildPhase = function (file) {
601+
var sources = this.pbxEmbedFrameworksBuildPhaseObj(file.target);
602+
if (sources) {
603+
for (i in sources.files) {
604+
if (sources.files[i].comment == longComment(file)) {
605+
sources.files.splice(i, 1);
606+
break;
607+
}
608+
}
609+
}
610+
}
581611

582612
pbxProject.prototype.addToProductsPbxGroup = function(file) {
583613
var productsGroup = this.pbxGroupByName('Products');
@@ -905,6 +935,10 @@ pbxProject.prototype.pbxFrameworksBuildPhaseObj = function(target) {
905935
return this.buildPhaseObject('PBXFrameworksBuildPhase', 'Frameworks', target);
906936
}
907937

938+
pbxProject.prototype.pbxEmbedFrameworksBuildPhaseObj = function (target) {
939+
return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Frameworks', target);
940+
};
941+
908942
// Find Build Phase from group/target
909943
pbxProject.prototype.buildPhase = function(group, target) {
910944

@@ -1166,14 +1200,14 @@ pbxProject.prototype.removeFromOtherLinkerFlags = function (flag) {
11661200
var configurations = nonComments(this.pbxXCBuildConfigurationSection()),
11671201
OTHER_LDFLAGS = 'OTHER_LDFLAGS',
11681202
config, buildSettings;
1169-
1203+
11701204
for (config in configurations) {
11711205
buildSettings = configurations[config].buildSettings;
1172-
1206+
11731207
if (unquote(buildSettings['PRODUCT_NAME']) != this.productName) {
11741208
continue;
11751209
}
1176-
1210+
11771211
if (buildSettings[OTHER_LDFLAGS]) {
11781212
var matches = buildSettings[OTHER_LDFLAGS].filter(function (p) {
11791213
return p.indexOf(flag) > -1;
@@ -1192,7 +1226,7 @@ pbxProject.prototype.addToBuildSettings = function (buildSetting, value) {
11921226

11931227
for (config in configurations) {
11941228
buildSettings = configurations[config].buildSettings;
1195-
1229+
11961230
buildSettings[buildSetting] = value;
11971231
}
11981232
}
@@ -1203,7 +1237,7 @@ pbxProject.prototype.removeFromBuildSettings = function (buildSetting) {
12031237

12041238
for (config in configurations) {
12051239
buildSettings = configurations[config].buildSettings;
1206-
1240+
12071241
if (buildSettings[buildSetting]) {
12081242
delete buildSettings[buildSetting];
12091243
}
@@ -1245,22 +1279,22 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) {
12451279
targetType = type,
12461280
targetSubfolder = subfolder || name,
12471281
targetName = name.trim();
1248-
1282+
12491283
// Check type against list of allowed target types
12501284
if (!targetName) {
12511285
throw new Error("Target name missing.");
1252-
}
1286+
}
12531287

12541288
// Check type against list of allowed target types
12551289
if (!targetType) {
12561290
throw new Error("Target type missing.");
1257-
}
1291+
}
12581292

12591293
// Check type against list of allowed target types
12601294
if (!producttypeForTargettype(targetType)) {
12611295
throw new Error("Target type invalid: " + targetType);
12621296
}
1263-
1297+
12641298
// Build Configuration: Create
12651299
var buildConfigurationsList = [
12661300
{

test/addFramework.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,19 @@ exports.addFramework = {
128128
test.equal(buildFileEntry.fileRef, newFile.fileRef);
129129
test.equal(buildFileEntry.fileRef_comment, 'libsqlite3.dylib');
130130
test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: [ 'Weak' ] });
131-
131+
132+
test.done();
133+
},
134+
'should add the PBXBuildFile object correctly /w signable frameworks': function (test) {
135+
var newFile = proj.addFramework('libsqlite3.dylib', { sign: true }),
136+
buildFileSection = proj.pbxBuildFileSection(),
137+
buildFileEntry = buildFileSection[newFile.uuid];
138+
139+
test.equal(buildFileEntry.isa, 'PBXBuildFile');
140+
test.equal(buildFileEntry.fileRef, newFile.fileRef);
141+
test.equal(buildFileEntry.fileRef_comment, 'libsqlite3.dylib');
142+
test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: [ 'CodeSignOnCopy' ] });
143+
132144
test.done();
133145
},
134146
'should add to the Frameworks PBXGroup': function (test) {
@@ -155,6 +167,13 @@ exports.addFramework = {
155167
test.equal(frameworks.files.length, 16);
156168
test.done();
157169
},
170+
'should not add to the PBXFrameworksBuildPhase': function (test) {
171+
var newFile = proj.addFramework('Private.framework', {link: false}),
172+
frameworks = proj.pbxFrameworksBuildPhaseObj();
173+
174+
test.equal(frameworks.files.length, 15);
175+
test.done();
176+
},
158177
'should have the right values for the Sources entry': function (test) {
159178
var newFile = proj.addFramework('libsqlite3.dylib'),
160179
frameworks = proj.pbxFrameworksBuildPhaseObj(),
@@ -188,12 +207,26 @@ exports.addFramework = {
188207
// should add path to framework search path
189208
var frameworkPaths = frameworkSearchPaths(proj);
190209
expectedPath = '"\\"/path/to\\""';
191-
210+
192211
for (i = 0; i < frameworkPaths.length; i++) {
193212
var current = frameworkPaths[i];
194213
test.ok(current.indexOf('"$(inherited)"') >= 0);
195214
test.ok(current.indexOf(expectedPath) >= 0);
196215
}
197216
test.done();
198-
}
217+
},
218+
'should add to the Embed Frameworks PBXCopyFilesBuildPhase': function (test) {
219+
var newFile = proj.addFramework('/path/to/SomeEmbeddableCustom.framework', {customFramework: true, embed: true}),
220+
frameworks = proj.pbxEmbedFrameworksBuildPhaseObj();
221+
222+
test.equal(frameworks.files.length, 1);
223+
test.done();
224+
},
225+
'should not add to the Embed Frameworks PBXCopyFilesBuildPhase by default': function (test) {
226+
var newFile = proj.addFramework('/path/to/Custom.framework', {customFramework: true}),
227+
frameworks = proj.pbxEmbedFrameworksBuildPhaseObj();
228+
229+
test.equal(frameworks.files.length, 0);
230+
test.done();
231+
},
199232
}

test/fixtures/full-project.json

Lines changed: 1252 additions & 1 deletion
Large diffs are not rendered by default.

test/pbxFile.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ exports['settings'] = {
186186
test.equal(undefined, sourceFile.settings);
187187
test.done();
188188
},
189-
189+
190190
'should be undefined if weak is false or non-boolean': function (test) {
191191
var sourceFile1 = new pbxFile('social.framework',
192192
{ weak: false });
@@ -206,6 +206,22 @@ exports['settings'] = {
206206
test.done();
207207
},
208208

209+
'should be {ATTRIBUTES:["CodeSignOnCopy"]} if sign specified': function (test) {
210+
var sourceFile = new pbxFile('signable.framework',
211+
{ sign: true });
212+
213+
test.deepEqual({ATTRIBUTES:["CodeSignOnCopy"]}, sourceFile.settings);
214+
test.done();
215+
},
216+
217+
'should be {ATTRIBUTES:["Weak","CodeSignOnCopy"]} if both weak linking and sign specified': function (test) {
218+
var sourceFile = new pbxFile('signableWeak.framework',
219+
{ weak: true, sign: true });
220+
221+
test.deepEqual({ATTRIBUTES:["Weak", "CodeSignOnCopy"]}, sourceFile.settings);
222+
test.done();
223+
},
224+
209225
'should be {COMPILER_FLAGS:"blah"} if compiler flags specified': function (test) {
210226
var sourceFile = new pbxFile('Plugins/BarcodeScanner.m',
211227
{ compilerFlags: "-std=c++11 -fno-objc-arc" });

0 commit comments

Comments
 (0)