Skip to content

Commit 8c6fa3a

Browse files
author
Roberto Andrade
committed
Enabling code signing of frameworks during build
1 parent c5990c1 commit 8c6fa3a

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
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;

test/addFramework.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ exports.addFramework = {
131131

132132
test.done();
133133
},
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+
144+
test.done();
145+
},
134146
'should add to the Frameworks PBXGroup': function (test) {
135147
var newLength = proj.pbxGroupByName('Frameworks').children.length + 1,
136148
newFile = proj.addFramework('libsqlite3.dylib'),

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)