Skip to content

Commit

Permalink
Merge pull request #333 from tuist/encode_target_attributes
Browse files Browse the repository at this point in the history
Encode PBXObject reference in target attributes
  • Loading branch information
Pedro Piñera Buendía authored Oct 10, 2018
2 parents 7017b45 + b87f4e3 commit 268f936
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## next version

### Added
- Added ability to pass in a `PBXObject` into the `PBXProject.targetAttributes` dictionary, which will be encoded into its UUID. Can be used for `TestTargetID` https://github.com/tuist/xcodeproj/pull/333 by @yonaskolb.

### Changed
- Changed `XCScheme.BuildableReference` init to make `blueprint` a `PBXObject` and added a `setBlueprint(:)` function https://github.com/tuist/xcodeproj/pull/320 by @yonaskolb.
- Bump AEXML version to 4.3.3 https://github.com/tuist/xcodeproj/pull/310 by @pepibumur.
Expand Down
6 changes: 5 additions & 1 deletion Sources/xcodeproj/Objects/Project/PBXProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,11 @@ extension PBXProject: PlistSerializable {
if !targetAttributeReferences.isEmpty {
// merge target attributes
var plistTargetAttributes: [String: Any] = [:]
targetAttributeReferences.forEach({ plistTargetAttributes[$0.key.value] = $0.value })
for (reference, value) in targetAttributeReferences {
plistTargetAttributes[reference.value] = value.mapValues { value in
(value as? PBXObject)?.reference.value ?? value
}
}
plistAttributes[PBXProject.targetAttributesKey] = plistTargetAttributes
}
dictionary["attributes"] = plistAttributes.plist()
Expand Down
10 changes: 7 additions & 3 deletions Tests/xcodeprojTests/Objects/Project/PBXProjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import XCTest
final class PBXProjectTests: XCTestCase {
func test_attributes() throws {
let target = PBXTarget(name: "")
target.reference.fix("test")
target.reference.fix("app")

let testTarget = PBXTarget(name: "")
testTarget.reference.fix("test")

let project = PBXProject(name: "",
buildConfigurationList: XCConfigurationList(),
Expand All @@ -13,15 +16,16 @@ final class PBXProjectTests: XCTestCase {
attributes: ["LastUpgradeCheck": "0940"],
targetAttributes: [target: ["TestTargetID": "123"]])

project.setTargetAttributes(["custom": "abc"], target: target)
project.setTargetAttributes(["custom": "abc", "TestTargetID": testTarget], target: target)

let plist = try project.plistKeyAndValue(proj: PBXProj(), reference: "")
let attributes = plist.value.dictionary?["attributes"]?.dictionary ?? [:]

let expectedAttributes: [CommentedString: PlistValue] = [
"LastUpgradeCheck": "0940",
"TargetAttributes": ["test": [
"TargetAttributes": ["app": [
"custom": "abc",
"TestTargetID": "test"
]],
]
XCTAssertEqual(attributes, expectedAttributes)
Expand Down

0 comments on commit 268f936

Please sign in to comment.