Skip to content

Commit

Permalink
Add PBXFileSystemSynchronizedRootGroup and property to PBXTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
pepicrft committed Jul 20, 2024
1 parent 8a616e1 commit 6b6ee0d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation
import PathKit

public class PBXFileSystemSynchronizedRootGroup: PBXFileElement {}

/** 6CEC6EEA2C4BAE2D005DD0F8 /* Test */ = {isa =
PBXFileSystemSynchronizedRootGroup;
explicitFileTypes = {}; explicitFolders = (); path = Test; sourceTree = "<group>"; }; */
39 changes: 32 additions & 7 deletions Sources/XcodeProj/Objects/Targets/PBXTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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
Expand All @@ -135,6 +151,7 @@ public class PBXTarget: PBXContainerItem {
case productReference
case productType
case packageProductDependencies
case fileSystemSynchronizedGroups
}

public required init(from decoder: Decoder) throws {
Expand All @@ -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)
Expand All @@ -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))
}
Expand All @@ -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()))
}
Expand Down Expand Up @@ -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)"
}
Expand Down

0 comments on commit 6b6ee0d

Please sign in to comment.