Merge branch 'tbd-support' of https://github.com/appden/node-xcode into appden-tbd-support
diff --git a/lib/pbxFile.js b/lib/pbxFile.js
index 62b6f76..0215bc3 100644
--- a/lib/pbxFile.js
+++ b/lib/pbxFile.js
@@ -36,6 +36,7 @@
'compiled.mach-o.dylib': 'Frameworks',
'sourcecode.text-based-dylib-definition': 'Frameworks',
'wrapper.framework': 'Frameworks',
+ 'embedded.framework': 'Embed Frameworks',
'sourcecode.c.h': 'Resources',
'sourcecode.c.objc': 'Sources',
'sourcecode.swift': 'Sources'
@@ -97,7 +98,7 @@
}
}
-function detectGroup(fileRef) {
+function detectGroup(fileRef, opt) {
var extension = path.extname(fileRef.basename).substring(1),
filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
groupName = GROUP_BY_FILETYPE[unquoted(filetype)];
@@ -106,6 +107,10 @@
return 'Sources';
}
+ if (opt.customFramework && opt.embed) {
+ return GROUP_BY_FILETYPE['embedded.framework'];
+ }
+
if (!groupName) {
return DEFAULT_GROUP;
}
@@ -165,7 +170,7 @@
this.basename = path.basename(filepath);
this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath);
- this.group = detectGroup(self);
+ this.group = detectGroup(self, opt);
// for custom frameworks
if (opt.customFramework == true) {
@@ -198,7 +203,7 @@
this.settings.COMPILER_FLAGS = util.format('"%s"', opt.compilerFlags);
}
- if (opt.sign) {
+ if (opt.embed && opt.sign) {
if (!this.settings)
this.settings = {};
if (!this.settings.ATTRIBUTES)
diff --git a/lib/pbxProject.js b/lib/pbxProject.js
index ab515e1..9a2f5ed 100644
--- a/lib/pbxProject.js
+++ b/lib/pbxProject.js
@@ -214,7 +214,14 @@
}
}
-pbxProject.prototype.addResourceFile = function(path, opt) {
+/**
+ *
+ * @param path {String}
+ * @param opt {Object} see pbxFile for avail options
+ * @param group {String} group key
+ * @returns {Object} file; see pbxFile
+ */
+pbxProject.prototype.addResourceFile = function(path, opt, group) {
opt = opt || {};
var file;
@@ -223,7 +230,7 @@
file = this.addPluginFile(path, opt);
if (!file) return false;
} else {
- file = new pbxFile(path, opt);
+ file = new pbxFile(path, opt);
if (this.hasFile(file.path)) return false;
}
@@ -234,19 +241,32 @@
correctForResourcesPath(file, this);
file.fileRef = this.generateUuid();
}
-
+
this.addToPbxBuildFileSection(file); // PBXBuildFile
this.addToPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
-
+
if (!opt.plugin) {
this.addToPbxFileReferenceSection(file); // PBXFileReference
- this.addToResourcesPbxGroup(file); // PBXGroup
+ if (group) {
+ this.addToPbxGroup(file, group); //Group other than Resources (i.e. 'splash')
+ }
+ else {
+ this.addToResourcesPbxGroup(file); // PBXGroup
+ }
+
}
-
+
return file;
}
-pbxProject.prototype.removeResourceFile = function(path, opt) {
+/**
+ *
+ * @param path {String}
+ * @param opt {Object} see pbxFile for avail options
+ * @param group {String} group key
+ * @returns {Object} file; see pbxFile
+ */
+pbxProject.prototype.removeResourceFile = function(path, opt, group) {
var file = new pbxFile(path, opt);
file.target = opt ? opt.target : undefined;
@@ -254,13 +274,25 @@
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
this.removeFromPbxFileReferenceSection(file); // PBXFileReference
- this.removeFromResourcesPbxGroup(file); // PBXGroup
+ if (group) {
+ this.removeFromPbxGroup(file, group); //Group other than Resources (i.e. 'splash')
+ }
+ else {
+ this.removeFromResourcesPbxGroup(file); // PBXGroup
+ }
this.removeFromPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
return file;
}
pbxProject.prototype.addFramework = function(fpath, opt) {
+ var customFramework = opt && opt.customFramework == true;
+ var link = !opt || (opt.link == undefined || opt.link); //defaults to true if not specified
+ var embed = opt && opt.embed; //defaults to false if not specified
+
+ if (opt) {
+ delete opt.embed;
+ }
var file = new pbxFile(fpath, opt);
@@ -270,10 +302,6 @@
if (this.hasFile(file.path)) return false;
- var customFramework = opt && opt.customFramework == true;
- var link = !opt || (opt.link == undefined || opt.link); //defaults to true if not specified
- var embed = opt && opt.embed; //defaults to false if not specified
-
this.addToPbxBuildFileSection(file); // PBXBuildFile
this.addToPbxFileReferenceSection(file); // PBXFileReference
this.addToFrameworksPbxGroup(file); // PBXGroup
@@ -286,7 +314,18 @@
this.addToFrameworkSearchPaths(file);
if (embed) {
- this.addToPbxEmbedFrameworksBuildPhase(file); // PBXCopyFilesBuildPhase
+ opt.embed = embed;
+ var embeddedFile = new pbxFile(fpath, opt);
+
+ embeddedFile.uuid = this.generateUuid();
+ embeddedFile.fileRef = file.fileRef;
+
+ //keeping a separate PBXBuildFile entry for Embed Frameworks
+ this.addToPbxBuildFileSection(embeddedFile); // PBXBuildFile
+
+ this.addToPbxEmbedFrameworksBuildPhase(embeddedFile); // PBXCopyFilesBuildPhase
+
+ return embeddedFile;
}
}
@@ -294,6 +333,12 @@
}
pbxProject.prototype.removeFramework = function(fpath, opt) {
+ var embed = opt && opt.embed;
+
+ if (opt) {
+ delete opt.embed;
+ }
+
var file = new pbxFile(fpath, opt);
file.target = opt ? opt.target : undefined;
@@ -301,12 +346,20 @@
this.removeFromPbxFileReferenceSection(file); // PBXFileReference
this.removeFromFrameworksPbxGroup(file); // PBXGroup
this.removeFromPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase
- this.removeFromPbxEmbedFrameworksBuildPhase(file); // PBXCopyFilesBuildPhase
if (opt && opt.customFramework) {
this.removeFromFrameworkSearchPaths(file);
}
+ opt = opt || {};
+ opt.embed = true;
+ var embeddedFile = new pbxFile(fpath, opt);
+
+ embeddedFile.fileRef = file.fileRef;
+
+ this.removeFromPbxBuildFileSection(embeddedFile); // PBXBuildFile
+ this.removeFromPbxEmbedFrameworksBuildPhase(embeddedFile); // PBXCopyFilesBuildPhase
+
return file;
}
@@ -600,12 +653,13 @@
pbxProject.prototype.removeFromPbxEmbedFrameworksBuildPhase = function (file) {
var sources = this.pbxEmbedFrameworksBuildPhaseObj(file.target);
if (sources) {
+ var files = [];
for (i in sources.files) {
- if (sources.files[i].comment == longComment(file)) {
- sources.files.splice(i, 1);
- break;
+ if (sources.files[i].comment != longComment(file)) {
+ files.push(sources.files[i]);
}
}
+ sources.files = files;
}
}
@@ -1446,6 +1500,7 @@
command_line_tool: 'wrapper',
dynamic_library: 'products_directory',
framework: 'shared_frameworks',
+ frameworks: 'frameworks',
static_library: 'products_directory',
unit_test_bundle: 'wrapper',
watch_app: 'wrapper',
diff --git a/package.json b/package.json
index 47927ad..b950062 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"author": "Andrew Lunny <alunny@gmail.com>",
"name": "xcode",
"description": "parser for xcodeproj/project.pbxproj files",
- "version": "0.8.5",
+ "version": "0.8.7",
"main": "index.js",
"repository": {
"url": "https://github.com/alunny/node-xcode.git"
@@ -12,11 +12,11 @@
},
"dependencies": {
"node-uuid":"1.4.7",
- "pegjs":"0.6.2",
- "simple-plist": "0.0.4"
+ "pegjs": "0.9.0",
+ "simple-plist": "0.1.4"
},
"devDependencies": {
- "nodeunit":"0.9.0"
+ "nodeunit": "0.9.1"
},
"scripts": {
"test": "node_modules/.bin/nodeunit test/parser test"
diff --git a/test/addBuildPhase.js b/test/addBuildPhase.js
index ee9005e..a9c5c39 100644
--- a/test/addBuildPhase.js
+++ b/test/addBuildPhase.js
@@ -104,5 +104,10 @@
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();
+ },
}
diff --git a/test/addFramework.js b/test/addFramework.js
index efae42e..d7e1c2b 100644
--- a/test/addFramework.js
+++ b/test/addFramework.js
@@ -45,7 +45,6 @@
exports.addFramework = {
'should return a pbxFile': function (test) {
var newFile = proj.addFramework('libsqlite3.dylib');
- console.log(newFile);
test.equal(newFile.constructor, pbxFile);
test.done()
@@ -131,18 +130,6 @@
test.done();
},
- 'should add the PBXBuildFile object correctly /w signable frameworks': function (test) {
- var newFile = proj.addFramework('libsqlite3.dylib', { sign: true }),
- buildFileSection = proj.pbxBuildFileSection(),
- buildFileEntry = buildFileSection[newFile.uuid];
-
- test.equal(buildFileEntry.isa, 'PBXBuildFile');
- test.equal(buildFileEntry.fileRef, newFile.fileRef);
- test.equal(buildFileEntry.fileRef_comment, 'libsqlite3.dylib');
- test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: [ 'CodeSignOnCopy' ] });
-
- test.done();
- },
'should add to the Frameworks PBXGroup': function (test) {
var newLength = proj.pbxGroupByName('Frameworks').children.length + 1,
newFile = proj.addFramework('libsqlite3.dylib'),
@@ -219,6 +206,9 @@
var newFile = proj.addFramework('/path/to/SomeEmbeddableCustom.framework', {customFramework: true, embed: true}),
frameworks = proj.pbxEmbedFrameworksBuildPhaseObj();
+ var buildPhaseInPbx = proj.pbxEmbedFrameworksBuildPhaseObj();
+ test.equal(buildPhaseInPbx.dstSubfolderSpec, 10);
+
test.equal(frameworks.files.length, 1);
test.done();
},
@@ -229,4 +219,17 @@
test.equal(frameworks.files.length, 0);
test.done();
},
+ 'should add the PBXBuildFile object correctly /w signable frameworks': function (test) {
+ var newFile = proj.addFramework('/path/to/SomeSignable.framework', { customFramework: true, embed: true, sign: true }),
+ buildFileSection = proj.pbxBuildFileSection(),
+ buildFileEntry = buildFileSection[newFile.uuid];
+
+ test.equal(newFile.group, 'Embed Frameworks');
+ test.equal(buildFileEntry.isa, 'PBXBuildFile');
+ test.equal(buildFileEntry.fileRef, newFile.fileRef);
+ test.equal(buildFileEntry.fileRef_comment, 'SomeSignable.framework');
+ test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: [ 'CodeSignOnCopy' ] });
+
+ test.done();
+ },
}
diff --git a/test/group.js b/test/group.js
index 8523b83..8eb5b00 100644
--- a/test/group.js
+++ b/test/group.js
@@ -185,7 +185,7 @@
}
exports.addHeaderFileToGroup = {
- 'should create group + add source file' : function(test) {
+ 'should create group + add header file' : function(test) {
var testKey = project.pbxCreateGroup('Test', 'Test');
var file = project.addHeaderFile('Notifications.h', {}, testKey);
@@ -197,7 +197,7 @@
}
exports.removeHeaderFileFromGroup = {
- 'should create group + add source file then remove source file' : function(test) {
+ 'should create group + add source file then remove header file' : function(test) {
var testKey = project.pbxCreateGroup('Test', 'Test');
var file = project.addHeaderFile('Notifications.h', {}, testKey);
@@ -213,6 +213,36 @@
}
}
+exports.addResourceFileToGroup = {
+ 'should add resource file (PNG) to the splash group' : function(test) {
+
+ var testKey = project.findPBXGroupKey({path:'splash'});
+ var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey);
+
+ var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
+ test.ok(foundInGroup);
+
+ test.done();
+ }
+}
+
+exports.removeResourceFileFromGroup = {
+ 'should add resource file (PNG) then remove resource file from splash group' : function(test) {
+ var testKey = project.findPBXGroupKey({path:'splash'});
+ var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey);
+
+ var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
+ test.ok(foundInGroup);
+
+ project.removeResourceFile('DefaultTest-667h.png', {}, testKey);
+
+ var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
+ test.ok(!foundInGroup);
+
+ test.done();
+ }
+}
+
exports.retrieveBuildPropertyForBuild = {
'should retrieve valid build property ':function(test) {
var releaseTargetedDeviceFamily = project.getBuildProperty('TARGETED_DEVICE_FAMILY', 'Release');
@@ -317,4 +347,4 @@
test.done();
}
-}
\ No newline at end of file
+}
diff --git a/test/pbxFile.js b/test/pbxFile.js
index 114c576..a24f564 100644
--- a/test/pbxFile.js
+++ b/test/pbxFile.js
@@ -241,7 +241,7 @@
'should be {ATTRIBUTES:["CodeSignOnCopy"]} if sign specified': function (test) {
var sourceFile = new pbxFile('signable.framework',
- { sign: true });
+ { embed: true, sign: true });
test.deepEqual({ATTRIBUTES:["CodeSignOnCopy"]}, sourceFile.settings);
test.done();
@@ -249,7 +249,7 @@
'should be {ATTRIBUTES:["Weak","CodeSignOnCopy"]} if both weak linking and sign specified': function (test) {
var sourceFile = new pbxFile('signableWeak.framework',
- { weak: true, sign: true });
+ { embed: true, weak: true, sign: true });
test.deepEqual({ATTRIBUTES:["Weak", "CodeSignOnCopy"]}, sourceFile.settings);
test.done();