Skip to content

Commit

Permalink
Merge branch 'master' into showEnvVarsInLog
Browse files Browse the repository at this point in the history
  • Loading branch information
briantkelley authored Mar 7, 2018
2 parents 261a8d7 + 3c95e75 commit 5014c26
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

## next version

### Added
- `PBXNativeTarget.productInstallPath`, `PBXTargetDependency.name` https://github.com/xcodeswift/xcproj/pull/241 by @briantkelley

### Changed
- Support for `XCConfig` project-relative includes https://github.com/xcodeswift/xcproj/pull/238 by @briantkelley

### Fixed
- `PBXObject.isEqual(to:)` overrides correctly call super https://github.com/xcodeswift/xcproj/pull/239 by @briantkelley
- `PBXAggregateTarget` does not write `buildRules` https://github.com/xcodeswift/xcproj/pull/241 by @briantkelley
- Writes showEnvVarsInLog only when false https://github.com/xcodeswift/xcproj/pull/240 by @briantkelley

## 4.1.0
Expand Down
55 changes: 55 additions & 0 deletions Sources/xcproj/PBXNativeTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,61 @@ import Foundation
/// This is the element for a build target that produces a binary content (application or library).
final public class PBXNativeTarget: PBXTarget {

// Target product install path.
public var productInstallPath: String?

public init(name: String,
buildConfigurationList: String? = nil,
buildPhases: [String] = [],
buildRules: [String] = [],
dependencies: [String] = [],
productInstallPath: String? = nil,
productName: String? = nil,
productReference: String? = nil,
productType: PBXProductType? = nil) {
self.productInstallPath = productInstallPath
super.init(name: name,
buildConfigurationList: buildConfigurationList,
buildPhases: buildPhases,
buildRules: buildRules,
dependencies: dependencies,
productName: productName,
productReference: productReference,
productType: productType)
}

// MARK: - Decodable

fileprivate enum CodingKeys: String, CodingKey {
case productInstallPath
}

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.productInstallPath = try container.decodeIfPresent(.productInstallPath)
try super.init(from: decoder)
}

public override func isEqual(to object: PBXObject) -> Bool {
guard let rhs = object as? PBXNativeTarget,
super.isEqual(to: rhs) else {
return false
}
let lhs = self
return lhs.productInstallPath == rhs.productInstallPath
}

override func plistValues(proj: PBXProj, isa: String, reference: String) -> (key: CommentedString, value: PlistValue) {
let (key, value) = super.plistValues(proj: proj, isa: isa, reference: reference)
guard case PlistValue.dictionary(var dict) = value else {
fatalError("Expected super to give a dictionary")
}
if let productInstallPath = productInstallPath {
dict["productInstallPath"] = .string(CommentedString(productInstallPath))
}
return (key: key, value: .dictionary(dict))
}

}

// MARK: - PBXNativeTarget Extension (PlistSerializable)
Expand Down
4 changes: 2 additions & 2 deletions Sources/xcproj/PBXTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public class PBXTarget: PBXObject {
return .string(CommentedString(buildPhase, comment: comment))
})

// Xcode doesn't write empty PBXLegacyTarget buildRules
if !(self is PBXLegacyTarget) || !buildRules.isEmpty {
// Xcode doesn't write PBXAggregateTarget buildRules or empty PBXLegacyTarget buildRules
if !(self is PBXAggregateTarget), !(self is PBXLegacyTarget) || !buildRules.isEmpty {
dictionary["buildRules"] = .array(buildRules.map {.string(CommentedString($0))})
}

Expand Down
18 changes: 15 additions & 3 deletions Sources/xcproj/PBXTargetDependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ final public class PBXTargetDependency: PBXObject {

// MARK: - Attributes

/// Target name.
public var name: String?

/// Target reference.
public var target: String?

Expand All @@ -16,10 +19,13 @@ final public class PBXTargetDependency: PBXObject {
/// Initializes the target dependency.
///
/// - Parameters:
/// - name: element name.
/// - target: element target.
/// - targetProxy: element target proxy.
public init(target: String? = nil,
public init(name: String? = nil,
target: String? = nil,
targetProxy: String? = nil) {
self.name = name
self.target = target
self.targetProxy = targetProxy
super.init()
Expand All @@ -33,19 +39,22 @@ final public class PBXTargetDependency: PBXObject {
return false
}
let lhs = self
return lhs.target == rhs.target &&
lhs.targetProxy == rhs.targetProxy
return lhs.name == rhs.name &&
lhs.target == rhs.target &&
lhs.targetProxy == rhs.targetProxy
}

// MARK: - Decodable

fileprivate enum CodingKeys: String, CodingKey {
case name
case target
case targetProxy
}

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.name = try container.decodeIfPresent(.name)
self.target = try container.decodeIfPresent(.target)
self.targetProxy = try container.decodeIfPresent(.targetProxy)
try super.init(from: decoder)
Expand All @@ -60,6 +69,9 @@ extension PBXTargetDependency: PlistSerializable {
func plistKeyAndValue(proj: PBXProj, reference: String) -> (key: CommentedString, value: PlistValue) {
var dictionary: [CommentedString: PlistValue] = [:]
dictionary["isa"] = .string(CommentedString(PBXTargetDependency.isa))
if let name = name {
dictionary["name"] = .string(CommentedString(name))
}
if let target = target {
let targetName = proj.objects.getTarget(reference: target)?.name
dictionary["target"] = .string(CommentedString(target, comment: targetName))
Expand Down
6 changes: 5 additions & 1 deletion Tests/xcprojTests/PBXNativeTargetSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class PBXNativeTargetSpec: XCTestCase {
buildPhases: ["phase"],
buildRules: ["rule"],
dependencies: ["dependency"],
productInstallPath: "/usr/local/bin",
productName: "productname",
productReference: "productreference",
productType: .application)
Expand All @@ -28,6 +29,7 @@ final class PBXNativeTargetSpec: XCTestCase {
XCTAssertEqual(subject.buildRules, ["rule"])
XCTAssertEqual(subject.dependencies, ["dependency"])
XCTAssertEqual(subject.name, "name")
XCTAssertEqual(subject.productInstallPath, "/usr/local/bin")
XCTAssertEqual(subject.productName, "productname")
XCTAssertEqual(subject.productReference, "productreference")
XCTAssertEqual(subject.productType, .application)
Expand All @@ -50,6 +52,7 @@ final class PBXNativeTargetSpec: XCTestCase {
buildPhases: ["phase"],
buildRules: ["rule"],
dependencies: ["dependency"],
productInstallPath: "/usr/local/bin",
productName: "productname",
productReference: "productreference",
productType: .application)
Expand All @@ -62,7 +65,8 @@ final class PBXNativeTargetSpec: XCTestCase {
"buildPhases": ["phase"],
"buildRules": ["rule"],
"dependencies": ["dependency"],
"name": "name"
"name": "name",
"productInstallPath": "/usr/local/bin"
]
}

Expand Down
9 changes: 6 additions & 3 deletions Tests/xcprojTests/PBXTargetDependencySpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ final class PBXTargetDependencySpec: XCTestCase {
var subject: PBXTargetDependency!

override func setUp() {
subject = PBXTargetDependency(target: "target",
subject = PBXTargetDependency(name: "name",
target: "target",
targetProxy: "target_proxy")
}

func test_init_initializesTheTargetDependencyWithTheCorrectAttributes() {
XCTAssertEqual(subject.name, "name")
XCTAssertEqual(subject.target, "target")
XCTAssertEqual(subject.targetProxy, "target_proxy")
}
Expand All @@ -21,13 +23,14 @@ final class PBXTargetDependencySpec: XCTestCase {
}

func test_equals_shouldReturnTheRightValue() {
let one = PBXTargetDependency(target: "target", targetProxy: "target_proxy")
let another = PBXTargetDependency(target: "target", targetProxy: "target_proxy")
let one = PBXTargetDependency(name: "name", target: "target", targetProxy: "target_proxy")
let another = PBXTargetDependency(name: "name", target: "target", targetProxy: "target_proxy")
XCTAssertEqual(one, another)
}

private func testDictionary() -> [String: Any] {
return [
"name": "name",
"target": "target",
"targetProxy": "targetProxy",
"reference": "reference"
Expand Down

0 comments on commit 5014c26

Please sign in to comment.