From 6b6ee0d5e64c8e1ef99991e92d86b0b31029bfda Mon Sep 17 00:00:00 2001 From: Pedro Date: Sat, 20 Jul 2024 11:07:28 +0200 Subject: [PATCH] Add PBXFileSystemSynchronizedRootGroup and property to PBXTarget --- .../PBXFileSystemSynchronizedRootGroup.swift | 8 ++++ .../XcodeProj/Objects/Targets/PBXTarget.swift | 39 +++++++++++++++---- 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedRootGroup.swift diff --git a/Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedRootGroup.swift b/Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedRootGroup.swift new file mode 100644 index 00000000..a07dd934 --- /dev/null +++ b/Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedRootGroup.swift @@ -0,0 +1,8 @@ +import Foundation +import PathKit + +public class PBXFileSystemSynchronizedRootGroup: PBXFileElement {} + +/** 6CEC6EEA2C4BAE2D005DD0F8 /* Test */ = {isa = + PBXFileSystemSynchronizedRootGroup; + explicitFileTypes = {}; explicitFolders = (); path = Test; sourceTree = ""; }; */ diff --git a/Sources/XcodeProj/Objects/Targets/PBXTarget.swift b/Sources/XcodeProj/Objects/Targets/PBXTarget.swift index 07d25549..16c9c9f9 100644 --- a/Sources/XcodeProj/Objects/Targets/PBXTarget.swift +++ b/Sources/XcodeProj/Objects/Targets/PBXTarget.swift @@ -88,6 +88,19 @@ public class PBXTarget: PBXContainerItem { } } + // File system synchronized groups references. + var fileSystemSynchronizedGroupsReferences: [PBXObjectReference]? + + // File system synchronized groups. + public var fileSystemSynchronizedGroups: [PBXFileSystemSynchronizedRootGroup]? { + set { + fileSystemSynchronizedGroupsReferences = newValue?.references() + } + get { + fileSystemSynchronizedGroupsReferences?.objects() + } + } + /// Target product type. public var productType: PBXProductType? @@ -110,12 +123,15 @@ public class PBXTarget: PBXContainerItem { packageProductDependencies: [XCSwiftPackageProductDependency] = [], productName: String? = nil, product: PBXFileReference? = nil, - productType: PBXProductType? = nil) { + productType: PBXProductType? = nil, + fileSystemSynchronizedGroups: [PBXFileSystemSynchronizedRootGroup]? = nil) + { buildConfigurationListReference = buildConfigurationList?.reference buildPhaseReferences = buildPhases.references() buildRuleReferences = buildRules.references() dependencyReferences = dependencies.references() packageProductDependencyReferences = packageProductDependencies.references() + fileSystemSynchronizedGroupsReferences = fileSystemSynchronizedGroups?.references() self.name = name self.productName = productName productReference = product?.reference @@ -135,6 +151,7 @@ public class PBXTarget: PBXContainerItem { case productReference case productType case packageProductDependencies + case fileSystemSynchronizedGroups } public required init(from decoder: Decoder) throws { @@ -160,11 +177,12 @@ public class PBXTarget: PBXContainerItem { } else { productReference = nil } - let packageProductDependencyReferenceStrings: [String] = try container.decodeIfPresent(.packageProductDependencies) ?? [] packageProductDependencyReferences = packageProductDependencyReferenceStrings.map { objectReferenceRepository.getOrCreate(reference: $0, objects: objects) } + let fileSystemSynchronizedGroupsReferences: [String] = try container.decodeIfPresent(.fileSystemSynchronizedGroups) ?? [] + self.fileSystemSynchronizedGroupsReferences = fileSystemSynchronizedGroupsReferences.map { objectReferenceRepository.getOrCreate(reference: $0, objects: objects) } productType = try container.decodeIfPresent(.productType) try super.init(from: decoder) @@ -174,7 +192,7 @@ public class PBXTarget: PBXContainerItem { var dictionary = try super.plistValues(proj: proj, reference: reference) dictionary["isa"] = .string(CommentedString(isa)) let buildConfigurationListComment = "Build configuration list for \(isa) \"\(name)\"" - if let buildConfigurationListReference = buildConfigurationListReference { + if let buildConfigurationListReference { dictionary["buildConfigurationList"] = .string(CommentedString(buildConfigurationListReference.value, comment: buildConfigurationListComment)) } @@ -190,14 +208,21 @@ public class PBXTarget: PBXContainerItem { } dictionary["dependencies"] = .array(dependencyReferences.map { .string(CommentedString($0.value, comment: PBXTargetDependency.isa)) }) + if let fileSystemSynchronizedGroupsReferences { + dictionary["fileSystemSynchronizedGroups"] = .array(fileSystemSynchronizedGroupsReferences.map { fileSystemSynchronizedGroupReference in + let fileSystemSynchronizedGroup: PBXFileSystemSynchronizedRootGroup? = fileSystemSynchronizedGroupReference.getObject() + return .string(CommentedString(fileSystemSynchronizedGroupReference.value, comment: fileSystemSynchronizedGroup?.name)) + }) + } + dictionary["name"] = .string(CommentedString(name)) - if let productName = productName { + if let productName { dictionary["productName"] = .string(CommentedString(productName)) } - if let productType = productType { + if let productType { dictionary["productType"] = .string(CommentedString(productType.rawValue)) } - if let productReference = productReference { + if let productReference { let fileElement: PBXFileElement? = productReference.getObject() dictionary["productReference"] = .string(CommentedString(productReference.value, comment: fileElement?.fileName())) } @@ -225,7 +250,7 @@ public extension PBXTarget { /// /// - Returns: product name with extension. func productNameWithExtension() -> String? { - guard let productName = self.productName else { return nil } + guard let productName else { return nil } guard let fileExtension = productType?.fileExtension else { return nil } return "\(productName).\(fileExtension)" }