Skip to content

Commit 5db21ba

Browse files
committed
Add fixes for app_extension Info.plist files. Add build phase creation and registering with custom targets. Cleanup.
1 parent 8297ac6 commit 5db21ba

File tree

1 file changed

+59
-34
lines changed

1 file changed

+59
-34
lines changed

lib/pbxProject.js

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ pbxProject.prototype.addProductFile = function(targetPath, opt) {
115115
file.fileRef = this.generateUuid();
116116
file.target = opt ? opt.target : undefined;
117117
file.group = opt ? opt.group : undefined;
118+
file.uuid = this.generateUuid();
119+
file.path = file.basename;
118120

121+
this.addToPbxFileReferenceSection(file);
119122
this.addToProductsPbxGroup(file); // PBXGroup
120123

121124
return file;
@@ -208,9 +211,8 @@ pbxProject.prototype.removeResourceFile = function(path, opt) {
208211
}
209212

210213
pbxProject.prototype.addFramework = function(fpath, opt) {
214+
211215
var file = new pbxFile(fpath, opt);
212-
// catch duplicates
213-
if (this.hasFile(file.path)) return false;
214216

215217
file.uuid = this.generateUuid();
216218
file.fileRef = this.generateUuid();
@@ -252,14 +254,10 @@ pbxProject.prototype.addCopyfile = function(fpath, opt) {
252254
// catch duplicates
253255
if (this.hasFile(file.path)) {
254256
file = this.hasFile(file.path);
255-
} else {
256-
file.uuid = this.generateUuid();
257-
file.fileRef = this.generateUuid();
258257
}
259258

259+
file.fileRef = file.uuid = this.generateUuid();
260260
file.target = opt ? opt.target : undefined;
261-
file.group = 'CopyFiles';
262-
263261

264262
this.addToPbxBuildFileSection(file); // PBXBuildFile
265263
this.addToPbxFileReferenceSection(file); // PBXFileReference
@@ -269,11 +267,11 @@ pbxProject.prototype.addCopyfile = function(fpath, opt) {
269267
}
270268

271269
pbxProject.prototype.pbxCopyfilesBuildPhaseObj = function(target) {
272-
return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'CopyFiles', target);
270+
return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Copy Files', target);
273271
}
274272

275273
pbxProject.prototype.addToPbxCopyfilesBuildPhase = function(file) {
276-
var sources = this.buildPhaseObject('PBXCopyFilesBuildPhase', 'CopyFiles', file.target);
274+
var sources = this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Copy Files', file.target);
277275
sources.files.push(pbxBuildPhaseObj(file));
278276
}
279277

@@ -642,24 +640,40 @@ pbxProject.prototype.addTargetDependency = function(target, dependencyTargets) {
642640
return { uuid: target, target: nativeTargets[target] };
643641
}
644642

645-
pbxProject.prototype.addBuildPhase = function(filePathsArray, addToType, comment, folderType, subfolderPath) {
646-
var buildPhaseSection = this.hash.project.objects[addToType],
643+
pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, comment, target, folderType, subfolderPath) {
644+
var buildPhaseSection,
647645
fileReferenceSection = this.pbxFileReferenceSection(),
648646
buildFileSection = this.pbxBuildFileSection(),
649-
phaseUuid = this.generateUuid(),
650-
commentKey = f("%s_comment", phaseUuid),
651-
buildPhaseRef = {
652-
isa: addToType,
647+
buildPhaseUuid = this.generateUuid(),
648+
buildPhaseTargetUuid = target || this.getFirstTarget().uuid,
649+
commentKey = f("%s_comment", buildPhaseUuid),
650+
buildPhase = {
651+
isa: buildPhaseType,
653652
buildActionMask: 2147483647,
654653
files: [],
655654
runOnlyForDeploymentPostprocessing: 0
656655
},
657656
filePathToBuildFile = {};
658657

658+
if (buildPhaseType === 'PBXCopyFilesBuildPhase') {
659+
buildPhase = pbxCopyFilesBuildPhaseObj(buildPhase, folderType, subfolderPath, comment);
660+
}
661+
662+
if (!this.hash.project.objects[buildPhaseType]) {
663+
this.hash.project.objects[buildPhaseType] = new Object();
664+
}
665+
666+
if (!this.hash.project.objects[buildPhaseType][buildPhaseUuid]) {
667+
this.hash.project.objects[buildPhaseType][buildPhaseUuid] = buildPhase;
668+
this.hash.project.objects[buildPhaseType][commentKey] = comment;
669+
}
670+
671+
if (this.hash.project.objects['PBXNativeTarget'][buildPhaseTargetUuid]['buildPhases']) {
672+
this.hash.project.objects['PBXNativeTarget'][buildPhaseTargetUuid]['buildPhases'].push({
673+
value: buildPhaseUuid,
674+
comment: comment
675+
})
659676

660-
// Add CopyFiles BuildPhase template
661-
if (addToType === 'PBXCopyFilesBuildPhase') {
662-
buildPhaseRef = pbxCopyFilesBuildPhaseObj(buildPhaseRef, folderType, subfolderPath, comment);
663677
}
664678

665679

@@ -695,15 +709,15 @@ pbxProject.prototype.addBuildPhase = function(filePathsArray, addToType, comment
695709
file.fileRef = this.generateUuid();
696710
this.addToPbxFileReferenceSection(file); // PBXFileReference
697711
this.addToPbxBuildFileSection(file); // PBXBuildFile
698-
buildPhaseRef.files.push(pbxBuildPhaseObj(file));
712+
buildPhase.files.push(pbxBuildPhaseObj(file));
699713
}
700714

701715
if (buildPhaseSection) {
702-
buildPhaseSection[phaseUuid] = buildPhaseRef;
716+
buildPhaseSection[buildPhaseUuid] = buildPhase;
703717
buildPhaseSection[commentKey] = comment;
704-
}
718+
}
705719

706-
return { uuid: phaseUuid, buildPhase: buildPhaseRef };
720+
return { uuid: buildPhaseUuid, buildPhase: buildPhase };
707721
}
708722

709723
// helper access functions
@@ -993,11 +1007,12 @@ pbxProject.prototype.hasFile = function(filePath) {
9931007
return false;
9941008
}
9951009

996-
pbxProject.prototype.addTarget = function(name, type) {
1010+
pbxProject.prototype.addTarget = function(name, type, subfolder) {
9971011

9981012
// Setup uuid and name of new target
9991013
var targetUuid = this.generateUuid(),
10001014
targetType = type,
1015+
targetSubfolder = subfolder,
10011016
targetName = name.trim();
10021017

10031018
// Check type against list of allowed target types
@@ -1013,19 +1028,19 @@ pbxProject.prototype.addTarget = function(name, type) {
10131028
isa: 'XCBuildConfiguration',
10141029
buildSettings: {
10151030
GCC_PREPROCESSOR_DEFINITIONS: ['"DEBUG=1"', '"$(inherited)"'],
1016-
INFOPLIST_FILE: '"' + path.join(targetName, targetName + '-Info.plist' + '"'),
1031+
INFOPLIST_FILE: '"' + path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'),
10171032
LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"',
1018-
PRODUCT_NAME: targetName,
1033+
PRODUCT_NAME: '"' + targetName + '"',
10191034
SKIP_INSTALL: 'YES'
10201035
}
10211036
},
10221037
{
10231038
name: 'Release',
10241039
isa: 'XCBuildConfiguration',
10251040
buildSettings: {
1026-
INFOPLIST_FILE: '"' + path.join(targetName, targetName + '-Info.plist' + '"'),
1041+
INFOPLIST_FILE: '"' + path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'),
10271042
LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"',
1028-
PRODUCT_NAME: targetName,
1043+
PRODUCT_NAME: '"' + targetName + '"',
10291044
SKIP_INSTALL: 'YES'
10301045
}
10311046
}
@@ -1038,16 +1053,20 @@ pbxProject.prototype.addTarget = function(name, type) {
10381053
var productName = targetName,
10391054
productType = producttypeForTargettype(targetType),
10401055
productFileType = filetypeForProducttype(productType),
1041-
productFile = this.addProductFile(productName, { 'target': targetUuid, 'explicitFileType': productFileType}),
1056+
productFile = this.addProductFile(productName, { group: 'Copy Files', 'target': targetUuid, 'explicitFileType': productFileType}),
10421057
productFileName = productFile.basename;
10431058

1059+
1060+
// Product: Add to build file list
1061+
this.addToPbxBuildFileSection(productFile);
1062+
10441063
// Target: Create
10451064
var target = {
10461065
uuid: targetUuid,
10471066
pbxNativeTarget: {
10481067
isa: 'PBXNativeTarget',
1049-
name: targetName,
1050-
productName: targetName,
1068+
name: '"' + targetName + '"',
1069+
productName: '"' + targetName + '"',
10511070
productReference: productFile.fileRef,
10521071
productType: '"' + producttypeForTargettype(targetType) + '"',
10531072
buildConfigurationList: buildConfigurations.uuid,
@@ -1062,9 +1081,15 @@ pbxProject.prototype.addTarget = function(name, type) {
10621081

10631082
// Product: Embed (only for "extension"-type targets)
10641083
if (targetType === 'app_extension') {
1065-
// Create "Copy Files" build phase for target which contains the extension
1066-
this.addToPbxBuildFileSection(productFile);
1067-
this.addBuildPhase([productFileName], 'PBXCopyFilesBuildPhase', 'Copy Files', targetType)
1084+
1085+
// Create CopyFiles phase in first target
1086+
this.addBuildPhase([], 'PBXCopyFilesBuildPhase', 'Copy Files', this.getFirstTarget().uuid, targetType)
1087+
1088+
// Add product to CopyFiles phase
1089+
this.addToPbxCopyfilesBuildPhase(productFile)
1090+
1091+
// this.addBuildPhaseToTarget(newPhase.buildPhase, this.getFirstTarget().uuid)
1092+
10681093
};
10691094

10701095
// Target: Add uuid to root project
@@ -1180,7 +1205,7 @@ function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName){
11801205
xpc_services: 0
11811206
}
11821207

1183-
obj.name = '"' + phaseName + '"' || '""';
1208+
obj.name = '"' + phaseName + '"';
11841209
obj.dstPath = subfolderPath || '""';
11851210
obj.dstSubfolderSpec = SUBFOLDERSPEC_BY_DESTINATION[DESTINATION_BY_TARGETTYPE[folderType]];
11861211

0 commit comments

Comments
 (0)