Skip to content

Commit 6a12350

Browse files
committed
[pbxProject] add static libraries as plugins
1 parent f689c61 commit 6a12350

File tree

2 files changed

+76
-24
lines changed

2 files changed

+76
-24
lines changed

lib/pbxProject.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pbxProject.prototype.generateUuid = function () {
8484
pbxProject.prototype.addPluginFile = function (path, opt) {
8585
var file = new pbxFile(path, opt);
8686

87+
file.plugin = true; // durr
88+
8789
correctForPluginsPath(file, this);
8890
file.fileRef = this.generateUuid();
8991

@@ -198,13 +200,24 @@ pbxProject.prototype.removeFramework = function (path, opt) {
198200
}
199201

200202
pbxProject.prototype.addStaticLibrary = function (path, opt) {
201-
var file = new pbxFile(path, opt);
203+
opt = opt || {};
204+
205+
var file;
206+
207+
if (opt.plugin) {
208+
file = this.addPluginFile(path, opt);
209+
} else {
210+
file = new pbxFile(path, opt);
211+
}
202212

203213
file.uuid = this.generateUuid();
204-
file.fileRef = this.generateUuid();
205214

206-
this.addToPbxBuildFileSection(file); // PBXBuildFile
207-
this.addToPbxFileReferenceSection(file); // PBXFileReference
215+
if (!opt.plugin) {
216+
file.fileRef = this.generateUuid();
217+
this.addToPbxBuildFileSection(file); // PBXBuildFile
218+
this.addToPbxFileReferenceSection(file); // PBXFileReference
219+
}
220+
208221
this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase
209222
this.ensureCorrectSearchPaths(file); // make sure it gets built!
210223

@@ -540,8 +553,14 @@ function correctForResourcesPath(file, project) {
540553
return file;
541554
}
542555

543-
function searchPathForFile(file, project) {
544-
return '"\\"$(SRCROOT)/' + project.productName + '\\""';
556+
function searchPathForFile(file, proj) {
557+
var pluginsPath = proj.pbxGroupByName('Plugins').path;
558+
559+
if (file.plugin && pluginsPath) {
560+
return '"\\"$(SRCROOT)/' + unquote(pluginsPath) + '\\""';
561+
} else {
562+
return '"\\"$(SRCROOT)/' + proj.productName + '\\""';
563+
}
545564
}
546565

547566
function nonComments(obj) {

test/addStaticLibrary.js

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ function nonComments(obj) {
2121
return newObj;
2222
}
2323

24+
function librarySearchPaths(proj) {
25+
var configs = nonComments(proj.pbxXCBuildConfigurationSection()),
26+
allPaths = [],
27+
ids = Object.keys(configs), i, buildSettings;
28+
29+
for (i = 0; i< ids.length; i++) {
30+
buildSettings = configs[ids[i]].buildSettings;
31+
32+
if (buildSettings['LIBRARY_SEARCH_PATHS']) {
33+
allPaths.push(buildSettings['LIBRARY_SEARCH_PATHS']);
34+
}
35+
}
36+
37+
return allPaths;
38+
}
39+
2440
exports.setUp = function (callback) {
2541
proj.hash = cleanHash();
2642
callback();
@@ -134,35 +150,52 @@ exports.addStaticLibrary = {
134150
},
135151
'should ensure LIBRARY_SEARCH_PATHS inherits defaults correctly': function (test) {
136152
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'),
137-
configs = nonComments(proj.pbxXCBuildConfigurationSection()),
138-
ids = Object.keys(configs), i, current, buildSettings;
139-
140-
for (i = 0; i< ids.length; i++) {
141-
buildSettings = configs[ids[i]].buildSettings;
142-
143-
if (buildSettings['PRODUCT_NAME'] == '"KitchenSinktablet"') {
144-
current = buildSettings['LIBRARY_SEARCH_PATHS'];
153+
libraryPaths = librarySearchPaths(proj),
154+
expectedPath = '"\\"$(SRCROOT)/KitchenSinktablet\\""',
155+
i, current;
145156

146-
test.ok(current.indexOf('"$(inherited)"') >= 0)
147-
}
157+
for (i = 0; i < libraryPaths.length; i++) {
158+
current = libraryPaths[i];
159+
test.ok(current.indexOf('"$(inherited)"') >= 0);
148160
}
149161

150162
test.done();
151163
},
152164
'should ensure the new library is in LIBRARY_SEARCH_PATHS': function (test) {
153165
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'),
154-
configs = nonComments(proj.pbxXCBuildConfigurationSection()),
166+
libraryPaths = librarySearchPaths(proj),
155167
expectedPath = '"\\"$(SRCROOT)/KitchenSinktablet\\""',
156-
ids = Object.keys(configs), i, current, buildSettings;
168+
i, current;
157169

158-
for (i = 0; i< ids.length; i++) {
159-
buildSettings = configs[ids[i]].buildSettings;
170+
for (i = 0; i < libraryPaths.length; i++) {
171+
current = libraryPaths[i];
172+
test.ok(current.indexOf(expectedPath) >= 0);
173+
}
160174

161-
if (buildSettings['PRODUCT_NAME'] == '"KitchenSinktablet"') {
162-
current = buildSettings['LIBRARY_SEARCH_PATHS'];
175+
test.done();
176+
},
177+
'should add to the Plugins group, optionally': function (test) {
178+
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a',
179+
{ plugin: true }),
180+
plugins = proj.pbxGroupByName('Plugins');
163181

164-
test.ok(current.indexOf(expectedPath) >= 0)
165-
}
182+
test.equal(plugins.children.length, 1);
183+
test.done();
184+
},
185+
'should add the right LIBRARY_SEARCH_PATHS entry for plugins': function (test) {
186+
plugins = proj.pbxGroupByName('Plugins');
187+
plugins.path = '"Test200/Plugins"';
188+
189+
var newFile = proj.addStaticLibrary('libGoogleAnalytics.a',
190+
{ plugin: true }),
191+
libraryPaths = librarySearchPaths(proj),
192+
expectedPath = '"\\"$(SRCROOT)/Test200/Plugins\\""',
193+
i, current;
194+
195+
for (i = 0; i < libraryPaths.length; i++) {
196+
current = libraryPaths[i];
197+
test.ok(current.indexOf(expectedPath) >= 0,
198+
expectedPath + ' not found in ' + current);
166199
}
167200

168201
test.done();

0 commit comments

Comments
 (0)