From b4d326f412cd1b39f89765e53573e5ea2f648809 Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Sat, 15 Jun 2019 12:00:49 -0700 Subject: [PATCH 01/13] adds watch2 target/product types --- lib/pbxProject.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 0e0f8f9..513002f 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -1697,7 +1697,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] @@ -1715,7 +1717,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] From 4ba466db84ace69621ffbb327dc217037f16a97b Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Sat, 22 Jun 2019 19:36:41 -0500 Subject: [PATCH 02/13] support adding watch2 app/extension targets --- lib/pbxProject.js | 64 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 513002f..48b6acd 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -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 - 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 @@ -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, @@ -1743,8 +1774,7 @@ pbxProject.prototype.getFirstProject = function() { } pbxProject.prototype.getFirstTarget = function() { - - // Get first targets UUID + // Get first target's UUID var firstTargetUuid = this.getFirstProject()['firstProject']['targets'][0].value; // Get first pbxNativeTarget @@ -1756,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) { From b9da9d38489ae8186a9ee47a20a7a00338374d26 Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Wed, 25 Sep 2019 21:49:40 -0500 Subject: [PATCH 03/13] add watch app/extension test coverage --- test/addWatchApp.js | 139 ++++++++++++++++++++++++++++++++++++ test/addWatchExtension.js | 143 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 282 insertions(+) create mode 100644 test/addWatchApp.js create mode 100644 test/addWatchExtension.js diff --git a/test/addWatchApp.js b/test/addWatchApp.js new file mode 100644 index 0000000..b51a290 --- /dev/null +++ b/test/addWatchApp.js @@ -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(); + } +} diff --git a/test/addWatchExtension.js b/test/addWatchExtension.js new file mode 100644 index 0000000..aa55cc0 --- /dev/null +++ b/test/addWatchExtension.js @@ -0,0 +1,143 @@ +/** + 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 = 'TestWatchExtension', + TARGET_TYPE = 'watch2_extension', + TARGET_SUBFOLDER_NAME = 'TestWatchExtensionFiles'; + +exports.setUp = function (callback) { + proj.hash = cleanHash(); + callback(); +} + +exports.addWatchExtension = { + 'should create a new watch extension 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 extension 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 not create a new watch extension build phase if no watch app exists': 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); + + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid) + + test.ok(!buildPhase); + + test.done(); + }, + 'should create a new watch extension build phase if watch app exists': function (test) { + proj.addTarget('TestWatchApp', 'watch2_app'); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); + + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid) + + test.ok(buildPhase); + test.ok(buildPhase.files); + test.equal(buildPhase.files.length, 1); + test.ok(buildPhase.dstPath); + test.equal(buildPhase.dstSubfolderSpec, 13); + + test.done(); + }, + 'should create a new watch extension and add to existing watch app build phase and dependency': function (test) { + var watchApp = proj.addTarget('TestWatchApp', 'watch2_app'); + + var nativeTargets = proj.pbxNativeTargetSection(); + + test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 0); + test.equal(nativeTargets[watchApp.uuid].dependencies.length, 0); + + proj.addTarget(TARGET_NAME, TARGET_TYPE); + + test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 1); + test.equal(nativeTargets[watchApp.uuid].dependencies.length, 1); + + test.done(); + } +} From f13bd369bfbb6a2e64e59125e5f7475d0ddee50a Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Wed, 16 Oct 2019 22:17:53 -0500 Subject: [PATCH 04/13] project formatting consistency --- lib/pbxProject.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 48b6acd..3b81c41 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -1750,7 +1750,7 @@ function filetypeForProducttype (productType) { 'com.apple.product-type.application.watchapp': '"wrapper.application"', '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"', + 'com.apple.product-type.watchkit2-extension': '"wrapper.app-extension"' }; return FILETYPE_BY_PRODUCTTYPE[productType] From 1a2c8cb0a8684c54f86c1c838a46502fc79b9623 Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Wed, 16 Oct 2019 22:49:34 -0500 Subject: [PATCH 05/13] coverage for correct watch app extension path name --- test/addWatchExtension.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/addWatchExtension.js b/test/addWatchExtension.js index aa55cc0..f654f1a 100644 --- a/test/addWatchExtension.js +++ b/test/addWatchExtension.js @@ -138,6 +138,29 @@ exports.addWatchExtension = { test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 1); test.equal(nativeTargets[watchApp.uuid].dependencies.length, 1); + test.done(); + }, + 'should create a new watch extension with appropriate target extension': function (test) { + proj.addTarget('TestWatchApp', 'watch2_app'); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); + + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid) + + var buildPhaseFile = buildPhase.files[0]; + test.ok(buildPhaseFile.value); + var buildPhaseFileSection = proj.pbxBuildFileSection()[buildPhaseFile.value]; + test.ok(buildPhaseFileSection); + test.ok(buildPhaseFileSection.fileRef); + + var buildPhaseFileRef = proj.pbxFileReferenceSection()[buildPhaseFileSection.fileRef]; + test.ok(buildPhaseFileRef); + test.ok(buildPhaseFileRef.name); + test.ok(buildPhaseFileRef.path); + + var quotedTargetPath = "\"" + TARGET_NAME + ".appex\""; + test.equal(buildPhaseFileRef.name, quotedTargetPath); + test.equal(buildPhaseFileRef.path, quotedTargetPath); + test.done(); } } From 9f2d7451beca7fb2170a9607fc773bcc30426696 Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Wed, 16 Oct 2019 22:52:18 -0500 Subject: [PATCH 06/13] coverage for target type --- test/addBuildPhase.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/addBuildPhase.js b/test/addBuildPhase.js index 93a4040..eb105f8 100644 --- a/test/addBuildPhase.js +++ b/test/addBuildPhase.js @@ -172,11 +172,21 @@ exports.addBuildPhase = { test.equal(buildPhase.dstSubfolderSpec, 1); test.done(); }, + 'should set target to Products Directory given \'watch2_app\' as target': function (test) { + var buildPhase = proj.addBuildPhase(['file.m'], 'PBXCopyFilesBuildPhase', 'Copy Files', proj.getFirstTarget().uuid, 'watch2_app').buildPhase; + test.equal(buildPhase.dstSubfolderSpec, 16); + test.done(); + }, 'should set target to Plugins given \'watch_extension\' as target': function (test) { var buildPhase = proj.addBuildPhase(['file.m'], 'PBXCopyFilesBuildPhase', 'Copy Files', proj.getFirstTarget().uuid, 'watch_extension').buildPhase; test.equal(buildPhase.dstSubfolderSpec, 13); test.done(); }, + 'should set target to Plugins given \'watch2_extension\' as target': function (test) { + var buildPhase = proj.addBuildPhase(['file.m'], 'PBXCopyFilesBuildPhase', 'Copy Files', proj.getFirstTarget().uuid, 'watch2_extension').buildPhase; + test.equal(buildPhase.dstSubfolderSpec, 13); + test.done(); + }, 'should add a script build phase to echo "hello world!"': function(test) { var options = {shellPath: '/bin/sh', shellScript: 'echo "hello world!"'}; var buildPhase = proj.addBuildPhase([], 'PBXShellScriptBuildPhase', 'Run a script', proj.getFirstTarget().uuid, options).buildPhase; From 314c4c7202777e6b6aead4efc491b063d60803e5 Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Wed, 16 Oct 2019 23:00:54 -0500 Subject: [PATCH 07/13] ensure non-watch2 extensions additions don't modify watch2 app --- test/addWatchExtension.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/addWatchExtension.js b/test/addWatchExtension.js index f654f1a..c2cd6ef 100644 --- a/test/addWatchExtension.js +++ b/test/addWatchExtension.js @@ -140,6 +140,26 @@ exports.addWatchExtension = { test.done(); }, + 'should not modify watch2 target unless adding watch2 extension': function (test) { + var watchApp = proj.addTarget('TestWatchApp', 'watch2_app'); + + var nativeTargets = proj.pbxNativeTargetSection(); + + test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 0); + test.equal(nativeTargets[watchApp.uuid].dependencies.length, 0); + + proj.addTarget(TARGET_NAME, "app_extension"); + + test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 0); + test.equal(nativeTargets[watchApp.uuid].dependencies.length, 0); + + proj.addTarget(TARGET_NAME, "watch_extension"); + + test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 0); + test.equal(nativeTargets[watchApp.uuid].dependencies.length, 0); + + test.done(); + }, 'should create a new watch extension with appropriate target extension': function (test) { proj.addTarget('TestWatchApp', 'watch2_app'); var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); From a1b0da2c7017c3e8a3d0590c0ed22f26c26a6d88 Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Wed, 16 Oct 2019 23:05:20 -0500 Subject: [PATCH 08/13] revert comment - will fix in other pr --- lib/pbxProject.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 3b81c41..92182f0 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -1774,7 +1774,8 @@ pbxProject.prototype.getFirstProject = function() { } pbxProject.prototype.getFirstTarget = function() { - // Get first target's UUID + + // Get first targets UUID var firstTargetUuid = this.getFirstProject()['firstProject']['targets'][0].value; // Get first pbxNativeTarget From ab22bc2b548b534b39be610c0fe1ea673817a929 Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Sat, 19 Oct 2019 10:50:59 -0500 Subject: [PATCH 09/13] add test coverage for watch2 product types --- test/addWatch2App.js | 8 ++++++-- test/addWatch2Extension.js | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/test/addWatch2App.js b/test/addWatch2App.js index b51a290..398fc3b 100644 --- a/test/addWatch2App.js +++ b/test/addWatch2App.js @@ -35,7 +35,7 @@ exports.setUp = function (callback) { } exports.addWatchApp = { - 'should create a new watch app target': function (test) { + 'should create a new watch app target with the correct product type': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); test.ok(typeof target == 'object'); @@ -51,9 +51,11 @@ exports.addWatchApp = { test.ok(target.pbxNativeTarget.buildRules); test.ok(target.pbxNativeTarget.dependencies); + test.equal(target.pbxNativeTarget.productType, '"com.apple.product-type.application.watchapp2"'); + test.done(); }, - 'should create a new watch app target without needing a subfolder name': function (test) { + 'should create a new watch app target with the correct product type, without needing a subfolder name': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); test.ok(typeof target == 'object'); @@ -69,6 +71,8 @@ exports.addWatchApp = { test.ok(target.pbxNativeTarget.buildRules); test.ok(target.pbxNativeTarget.dependencies); + test.equal(target.pbxNativeTarget.productType, '"com.apple.product-type.application.watchapp2"'); + test.done(); }, 'should create a new watch app target and add source, framework, resource and header files and the corresponding build phases': function (test) { diff --git a/test/addWatch2Extension.js b/test/addWatch2Extension.js index c2cd6ef..d82f40b 100644 --- a/test/addWatch2Extension.js +++ b/test/addWatch2Extension.js @@ -35,7 +35,7 @@ exports.setUp = function (callback) { } exports.addWatchExtension = { - 'should create a new watch extension target': function (test) { + 'should create a new watch extension target with the correct product type': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); test.ok(typeof target == 'object'); @@ -50,6 +50,7 @@ exports.addWatchExtension = { test.ok(target.pbxNativeTarget.buildPhases); test.ok(target.pbxNativeTarget.buildRules); test.ok(target.pbxNativeTarget.dependencies); + test.equal(target.pbxNativeTarget.productType, '"com.apple.product-type.watchkit2-extension"'); test.done(); }, From b7bd745df0a85a34c68b4c72e663f3e21b9269be Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Sat, 19 Oct 2019 10:52:49 -0500 Subject: [PATCH 10/13] watch2 file/product type test coverage --- test/addTarget.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/addTarget.js b/test/addTarget.js index 452262c..c9c5fae 100644 --- a/test/addTarget.js +++ b/test/addTarget.js @@ -240,6 +240,19 @@ exports.addTarget = { test.done(); }, + 'should have "wrapper.application" filetype for watch2_app product': function (test) { + var target = proj.addTarget(TARGET_NAME, 'watch2_app'); + test.ok(target); + test.ok(target.pbxNativeTarget); + test.ok(target.pbxNativeTarget.productReference); + + var productFile = proj.pbxFileReferenceSection()[target.pbxNativeTarget.productReference]; + test.ok(productFile); + test.ok(productFile.explicitFileType); + test.equal(productFile.explicitFileType, '"wrapper.application"'); + + test.done(); + }, 'should have "wrapper.app-extension" filetype for watch_extension product': function (test) { var target = proj.addTarget(TARGET_NAME, 'watch_extension'); test.ok(target); @@ -251,6 +264,19 @@ exports.addTarget = { test.ok(productFile.explicitFileType); test.equal(productFile.explicitFileType, '"wrapper.app-extension"'); + test.done(); + }, + 'should have "wrapper.app-extension" filetype for watch2_extension product': function (test) { + var target = proj.addTarget(TARGET_NAME, 'watch2_extension'); + test.ok(target); + test.ok(target.pbxNativeTarget); + test.ok(target.pbxNativeTarget.productReference); + + var productFile = proj.pbxFileReferenceSection()[target.pbxNativeTarget.productReference]; + test.ok(productFile); + test.ok(productFile.explicitFileType); + test.equal(productFile.explicitFileType, '"wrapper.app-extension"'); + test.done(); } } From ceb33cfaa934d66a552773c4bb0f12c1617da2d1 Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Sat, 19 Oct 2019 11:01:29 -0500 Subject: [PATCH 11/13] watch2 coverage for target name/extension --- test/addWatch2App.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/addWatch2App.js b/test/addWatch2App.js index 398fc3b..b563fcf 100644 --- a/test/addWatch2App.js +++ b/test/addWatch2App.js @@ -138,6 +138,28 @@ exports.addWatchApp = { test.equal(buildPhase.dstPath, '"$(CONTENTS_FOLDER_PATH)/Watch"'); test.equal(buildPhase.dstSubfolderSpec, 16); + test.done(); + }, + 'should create a new watch app with appropriate target extension': function (test) { + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); + + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Watch Content', target.uuid) + + var buildPhaseFile = buildPhase.files[0]; + test.ok(buildPhaseFile.value); + var buildPhaseFileSection = proj.pbxBuildFileSection()[buildPhaseFile.value]; + test.ok(buildPhaseFileSection); + test.ok(buildPhaseFileSection.fileRef); + + var buildPhaseFileRef = proj.pbxFileReferenceSection()[buildPhaseFileSection.fileRef]; + test.ok(buildPhaseFileRef); + test.ok(buildPhaseFileRef.name); + test.ok(buildPhaseFileRef.path); + + var quotedTargetPath = "\"" + TARGET_NAME + ".app\""; + test.equal(buildPhaseFileRef.name, quotedTargetPath); + test.equal(buildPhaseFileRef.path, quotedTargetPath); + test.done(); } } From c378c24cef144271c511a918e9595f3789cff4cf Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Sat, 19 Oct 2019 11:03:42 -0500 Subject: [PATCH 12/13] clarify watch2 test descriptions --- test/addWatch2App.js | 10 +++++----- test/addWatch2Extension.js | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/addWatch2App.js b/test/addWatch2App.js index b563fcf..2dd72f5 100644 --- a/test/addWatch2App.js +++ b/test/addWatch2App.js @@ -35,7 +35,7 @@ exports.setUp = function (callback) { } exports.addWatchApp = { - 'should create a new watch app target with the correct product type': function (test) { + 'should create a new watch2 app target with the correct product type': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); test.ok(typeof target == 'object'); @@ -55,7 +55,7 @@ exports.addWatchApp = { test.done(); }, - 'should create a new watch app target with the correct product type, without needing a subfolder name': function (test) { + 'should create a new watch2 app target with the correct product type, without needing a subfolder name': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); test.ok(typeof target == 'object'); @@ -75,7 +75,7 @@ exports.addWatchApp = { test.done(); }, - 'should create a new watch app target and add source, framework, resource and header files and the corresponding build phases': function (test) { + 'should create a new watch2 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 }; @@ -111,7 +111,7 @@ exports.addWatchApp = { test.done(); }, - 'should create a new watch app target and add watch build phase': function (test) { + 'should create a new watch2 app target and add watch build phase': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); test.ok(typeof target == 'object'); @@ -140,7 +140,7 @@ exports.addWatchApp = { test.done(); }, - 'should create a new watch app with appropriate target extension': function (test) { + 'should create a new watch2 app with appropriate target extension': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Watch Content', target.uuid) diff --git a/test/addWatch2Extension.js b/test/addWatch2Extension.js index d82f40b..302b752 100644 --- a/test/addWatch2Extension.js +++ b/test/addWatch2Extension.js @@ -35,7 +35,7 @@ exports.setUp = function (callback) { } exports.addWatchExtension = { - 'should create a new watch extension target with the correct product type': function (test) { + 'should create a new watch2 extension target with the correct product type': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); test.ok(typeof target == 'object'); @@ -54,7 +54,7 @@ exports.addWatchExtension = { test.done(); }, - 'should create a new watch extension target and add source, framework, resource and header files and the corresponding build phases': function (test) { + 'should create a new watch2 extension 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 }; @@ -90,7 +90,7 @@ exports.addWatchExtension = { test.done(); }, - 'should not create a new watch extension build phase if no watch app exists': function (test) { + 'should not create a new watch2 extension build phase if no watch2 app exists': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); test.ok(typeof target == 'object'); @@ -112,7 +112,7 @@ exports.addWatchExtension = { test.done(); }, - 'should create a new watch extension build phase if watch app exists': function (test) { + 'should create a new watch2 extension build phase if watch2 app exists': function (test) { proj.addTarget('TestWatchApp', 'watch2_app'); var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); @@ -126,7 +126,7 @@ exports.addWatchExtension = { test.done(); }, - 'should create a new watch extension and add to existing watch app build phase and dependency': function (test) { + 'should create a new watch2 extension and add to existing watch2 app build phase and dependency': function (test) { var watchApp = proj.addTarget('TestWatchApp', 'watch2_app'); var nativeTargets = proj.pbxNativeTargetSection(); @@ -161,7 +161,7 @@ exports.addWatchExtension = { test.done(); }, - 'should create a new watch extension with appropriate target extension': function (test) { + 'should create a new watch2 extension with appropriate target extension': function (test) { proj.addTarget('TestWatchApp', 'watch2_app'); var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); From 96c30e0885ece5984f486f06775b6903791c1b1b Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Sun, 20 Oct 2019 21:33:25 -0500 Subject: [PATCH 13/13] update comment to keep consistent w/ project --- lib/pbxProject.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index e065d82..3097678 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -1503,14 +1503,13 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) { // Target: Add uuid to root project this.addToPbxProjectSection(target); + // Target: Add dependency for this target to other targets 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]); }