Files
XcodeGen/Sources/ProjectSpec/TargetReference.swift
T
freddi(Yuki Aki) 245f17117a Support test target for local Swift Package (#1169)
* support local Swift Package test case into test scheme

* update test

* add test

* update CHABGELOG.md

* Update CHANGELOG.md

* revert resolved package test

* Update Sources/XcodeGenKit/SchemeGenerator.swift

Co-authored-by: Kohki Miki <giginet.net@gmail.com>

* make TargetReference convert from new JSON format

* add .package for location of target reference

* receive target reference format at target of scheme

* update test

* update XcodeProj

* add test and fix small bugs

* update docs

* support multiple style of coverageTargets

* add edge case of parsing test targets

* fix docs

* Update Docs/ProjectSpec.md

Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com>

* create TestableTargetReference for not making API complex

* fix code format

* fix parameter name to Testable Target Reference

* support directly writing key of Testable Target Reference

* fix compile error in build

Co-authored-by: Kohki Miki <giginet.net@gmail.com>
Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com>
2022-03-20 14:27:29 +11:00

58 lines
1.3 KiB
Swift

import Foundation
import JSONUtilities
public struct TargetReference: Hashable {
public var name: String
public var location: Location
public enum Location: Hashable {
case local
case project(String)
}
public init(name: String, location: Location) {
self.name = name
self.location = location
}
}
extension TargetReference {
public init(_ string: String) throws {
let paths = string.split(separator: "/")
switch paths.count {
case 2:
location = .project(String(paths[0]))
name = String(paths[1])
case 1:
location = .local
name = String(paths[0])
default:
throw SpecParsingError.invalidTargetReference(string)
}
}
public static func local(_ name: String) -> TargetReference {
TargetReference(name: name, location: .local)
}
}
extension TargetReference: ExpressibleByStringLiteral {
public init(stringLiteral value: String) {
try! self.init(value)
}
}
extension TargetReference: CustomStringConvertible {
public var reference: String {
switch location {
case .local: return name
case .project(let root):
return "\(root)/\(name)"
}
}
public var description: String {
reference
}
}