Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 63 additions & 9 deletions lib/pbxProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,14 +1476,43 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) {
this.addToPbxCopyfilesBuildPhase(productFile)

// this.addBuildPhaseToTarget(newPhase.buildPhase, this.getFirstTarget().uuid)

};
} else if (targetType === 'watch2_app') {
// Create CopyFiles phase in first target
this.addBuildPhase(
[targetName + '.app'],
'PBXCopyFilesBuildPhase',
'Embed Watch Content',
this.getFirstTarget().uuid,
targetType,
'"$(CONTENTS_FOLDER_PATH)/Watch"'
);
} else if (targetType === 'watch2_extension') {
// Create CopyFiles phase in watch target (if exists)
var watch2Target = this.getTarget(producttypeForTargettype('watch2_app'));
if (watch2Target) {
this.addBuildPhase(
[targetName + '.appex'],
'PBXCopyFilesBuildPhase',
'Embed App Extensions',
watch2Target.uuid,
targetType
);
}
}

// Target: Add uuid to root project
this.addToPbxProjectSection(target);

// Target: Add dependency for this target to first (main) target
Comment thread
brody2consult marked this conversation as resolved.
this.addTargetDependency(this.getFirstTarget().uuid, [target.uuid]);
if (targetType === 'watch2_extension') {
// Target: Add dependency for this target to watch target (if exists)
var watch2Target = this.getTarget(producttypeForTargettype('watch2_app'));
if (watch2Target) {
this.addTargetDependency(watch2Target.uuid, [target.uuid]);
}
} else {
// Target: Add dependency for this target to first (main) target
this.addTargetDependency(this.getFirstTarget().uuid, [target.uuid]);
}


// Return target on success
Expand Down Expand Up @@ -1564,7 +1593,9 @@ function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName) {
static_library: 'products_directory',
unit_test_bundle: 'wrapper',
watch_app: 'wrapper',
watch_extension: 'plugins'
watch2_app: 'products_directory',
watch_extension: 'plugins',
watch2_extension: 'plugins'
}
var SUBFOLDERSPEC_BY_DESTINATION = {
absolute_path: 0,
Expand Down Expand Up @@ -1697,7 +1728,9 @@ function producttypeForTargettype (targetType) {
static_library: 'com.apple.product-type.library.static',
unit_test_bundle: 'com.apple.product-type.bundle.unit-test',
watch_app: 'com.apple.product-type.application.watchapp',
watch_extension: 'com.apple.product-type.watchkit-extension'
watch2_app: 'com.apple.product-type.application.watchapp2',
watch_extension: 'com.apple.product-type.watchkit-extension',
watch2_extension: 'com.apple.product-type.watchkit2-extension'
};

return PRODUCTTYPE_BY_TARGETTYPE[targetType]
Expand All @@ -1715,7 +1748,9 @@ function filetypeForProducttype (productType) {
'com.apple.product-type.library.static': '"archive.ar"',
'com.apple.product-type.bundle.unit-test': '"wrapper.cfbundle"',
'com.apple.product-type.application.watchapp': '"wrapper.application"',
'com.apple.product-type.watchkit-extension': '"wrapper.app-extension"'
'com.apple.product-type.application.watchapp2': '"wrapper.application"',
'com.apple.product-type.watchkit-extension': '"wrapper.app-extension"',
'com.apple.product-type.watchkit2-extension': '"wrapper.app-extension"',
};

return FILETYPE_BY_PRODUCTTYPE[productType]
Expand All @@ -1739,8 +1774,7 @@ pbxProject.prototype.getFirstProject = function() {
}

pbxProject.prototype.getFirstTarget = function() {

// Get first targets UUID
// Get first target's UUID
Comment thread
l3ender marked this conversation as resolved.
var firstTargetUuid = this.getFirstProject()['firstProject']['targets'][0].value;

// Get first pbxNativeTarget
Expand All @@ -1752,6 +1786,26 @@ pbxProject.prototype.getFirstTarget = function() {
}
}

pbxProject.prototype.getTarget = function(productType) {
// Find target by product type
var targets = this.getFirstProject()['firstProject']['targets'];
var nativeTargets = this.pbxNativeTargetSection();
for (var i = 0; i < targets.length; i++) {
var target = targets[i];
var targetUuid = target.value;
if (nativeTargets[targetUuid]['productType'] === '"' + productType + '"') {
// Get pbxNativeTarget
var nativeTarget = this.pbxNativeTargetSection()[targetUuid];
return {
uuid: targetUuid,
target: nativeTarget
};
}
}

return null;
}

/*** NEW ***/

pbxProject.prototype.addToPbxGroupType = function (file, groupKey, groupType) {
Expand Down
139 changes: 139 additions & 0 deletions test/addWatchApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
'License'); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

var fullProject = require('./fixtures/full-project')
fullProjectStr = JSON.stringify(fullProject),
pbx = require('../lib/pbxProject'),
pbxFile = require('../lib/pbxFile'),
proj = new pbx('.');

function cleanHash() {
return JSON.parse(fullProjectStr);
}

var TARGET_NAME = 'TestWatchApp',
TARGET_TYPE = 'watch2_app',
TARGET_SUBFOLDER_NAME = 'TestWatchAppFiles';

exports.setUp = function (callback) {
proj.hash = cleanHash();
callback();
}

exports.addWatchApp = {
'should create a new watch app target': function (test) {
var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME);

test.ok(typeof target == 'object');
test.ok(target.uuid);
test.ok(target.pbxNativeTarget);
test.ok(target.pbxNativeTarget.isa);
test.ok(target.pbxNativeTarget.name);
test.ok(target.pbxNativeTarget.productName);
test.ok(target.pbxNativeTarget.productReference);
test.ok(target.pbxNativeTarget.productType);
test.ok(target.pbxNativeTarget.buildConfigurationList);
test.ok(target.pbxNativeTarget.buildPhases);
test.ok(target.pbxNativeTarget.buildRules);
test.ok(target.pbxNativeTarget.dependencies);

test.done();
},
'should create a new watch app target without needing a subfolder name': function (test) {
var target = proj.addTarget(TARGET_NAME, TARGET_TYPE);

test.ok(typeof target == 'object');
test.ok(target.uuid);
test.ok(target.pbxNativeTarget);
test.ok(target.pbxNativeTarget.isa);
test.ok(target.pbxNativeTarget.name);
test.ok(target.pbxNativeTarget.productName);
test.ok(target.pbxNativeTarget.productReference);
test.ok(target.pbxNativeTarget.productType);
test.ok(target.pbxNativeTarget.buildConfigurationList);
test.ok(target.pbxNativeTarget.buildPhases);
test.ok(target.pbxNativeTarget.buildRules);
test.ok(target.pbxNativeTarget.dependencies);

test.done();
},
'should create a new watch app target and add source, framework, resource and header files and the corresponding build phases': function (test) {
var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME),
options = { 'target' : target.uuid };

var sourceFile = proj.addSourceFile('Plugins/file.m', options),
sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid),
resourceFile = proj.addResourceFile('assets.bundle', options),
resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid),
frameworkFile = proj.addFramework('libsqlite3.dylib', options);
frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid),
headerFile = proj.addHeaderFile('file.h', options);

test.ok(sourcePhase);
test.ok(resourcePhase);
test.ok(frameworkPhase);

test.equal(sourceFile.constructor, pbxFile);
test.equal(resourceFile.constructor, pbxFile);
test.equal(frameworkFile.constructor, pbxFile);
test.equal(headerFile.constructor, pbxFile);

test.ok(typeof target == 'object');
test.ok(target.uuid);
test.ok(target.pbxNativeTarget);
test.ok(target.pbxNativeTarget.isa);
test.ok(target.pbxNativeTarget.name);
test.ok(target.pbxNativeTarget.productName);
test.ok(target.pbxNativeTarget.productReference);
test.ok(target.pbxNativeTarget.productType);
test.ok(target.pbxNativeTarget.buildConfigurationList);
test.ok(target.pbxNativeTarget.buildPhases);
test.ok(target.pbxNativeTarget.buildRules);
test.ok(target.pbxNativeTarget.dependencies);

test.done();
},
'should create a new watch app target and add watch build phase': function (test) {
var target = proj.addTarget(TARGET_NAME, TARGET_TYPE);

test.ok(typeof target == 'object');
test.ok(target.uuid);
test.ok(target.pbxNativeTarget);
test.ok(target.pbxNativeTarget.isa);
test.ok(target.pbxNativeTarget.name);
test.ok(target.pbxNativeTarget.productName);
test.ok(target.pbxNativeTarget.productReference);
test.ok(target.pbxNativeTarget.productType);
test.ok(target.pbxNativeTarget.buildConfigurationList);
test.ok(target.pbxNativeTarget.buildPhases);
test.ok(target.pbxNativeTarget.buildRules);
test.ok(target.pbxNativeTarget.dependencies);

test.equal(target.pbxNativeTarget.productType, '"com.apple.product-type.application.watchapp2"');

var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Watch Content', target.uuid);

test.ok(buildPhase);
test.ok(buildPhase.files);
test.equal(buildPhase.files.length, 1);
test.ok(buildPhase.dstPath);
test.equal(buildPhase.dstPath, '"$(CONTENTS_FOLDER_PATH)/Watch"');
test.equal(buildPhase.dstSubfolderSpec, 16);

test.done();
}
}
Loading