mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
change target source from String to Source struct
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Source.swift
|
||||
// ProjectSpec
|
||||
//
|
||||
// Created by Yonas Kolb on 31/10/17.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import JSONUtilities
|
||||
|
||||
public struct Source {
|
||||
|
||||
public var path: String
|
||||
|
||||
public init(path: String) {
|
||||
self.path = path
|
||||
}
|
||||
}
|
||||
|
||||
extension Source: ExpressibleByStringLiteral {
|
||||
|
||||
public init(stringLiteral value: String) {
|
||||
self = Source(path: value)
|
||||
}
|
||||
|
||||
public init(extendedGraphemeClusterLiteral value: String) {
|
||||
self = Source(path: value)
|
||||
}
|
||||
|
||||
public init(unicodeScalarLiteral value: String) {
|
||||
self = Source(path: value)
|
||||
}
|
||||
}
|
||||
|
||||
extension Source: JSONObjectConvertible {
|
||||
|
||||
public init(jsonDictionary: JSONDictionary) throws {
|
||||
path = try jsonDictionary.json(atKeyPath: "path")
|
||||
}
|
||||
}
|
||||
|
||||
extension Source: Equatable {
|
||||
|
||||
public static func == (lhs: Source, rhs: Source) -> Bool {
|
||||
return lhs.path == rhs.path
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ extension ProjectSpec {
|
||||
}
|
||||
|
||||
for source in target.sources {
|
||||
let sourcePath = basePath + source
|
||||
let sourcePath = basePath + source.path
|
||||
if !sourcePath.exists {
|
||||
errors.append(.invalidTargetSource(target: target.name, source: sourcePath.string))
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public struct Target {
|
||||
public var type: PBXProductType
|
||||
public var platform: Platform
|
||||
public var settings: Settings
|
||||
public var sources: [String]
|
||||
public var sources: [Source]
|
||||
public var dependencies: [Dependency]
|
||||
public var prebuildScripts: [BuildScript]
|
||||
public var postbuildScripts: [BuildScript]
|
||||
@@ -30,7 +30,7 @@ public struct Target {
|
||||
return name
|
||||
}
|
||||
|
||||
public init(name: String, type: PBXProductType, platform: Platform, settings: Settings = .empty, configFiles: [String: String] = [:], sources: [String] = [], dependencies: [Dependency] = [], prebuildScripts: [BuildScript] = [], postbuildScripts: [BuildScript] = [], scheme: TargetScheme? = nil) {
|
||||
public init(name: String, type: PBXProductType, platform: Platform, settings: Settings = .empty, configFiles: [String: String] = [:], sources: [Source] = [], dependencies: [Dependency] = [], prebuildScripts: [BuildScript] = [], postbuildScripts: [BuildScript] = [], scheme: TargetScheme? = nil) {
|
||||
self.name = name
|
||||
self.type = type
|
||||
self.platform = platform
|
||||
@@ -179,9 +179,19 @@ extension Target: NamedJSONDictionaryConvertible {
|
||||
settings = jsonDictionary.json(atKeyPath: "settings") ?? .empty
|
||||
configFiles = jsonDictionary.json(atKeyPath: "configFiles") ?? [:]
|
||||
if let source: String = jsonDictionary.json(atKeyPath: "sources") {
|
||||
sources = [source]
|
||||
sources = [Source(path: source)]
|
||||
} else if let array = jsonDictionary["sources"] as? [Any] {
|
||||
sources = try array.flatMap { source in
|
||||
if let string = source as? String {
|
||||
return Source(path: string)
|
||||
} else if let dictionary = source as? [String: Any] {
|
||||
return try Source(jsonDictionary: dictionary)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sources = jsonDictionary.json(atKeyPath: "sources") ?? []
|
||||
sources = []
|
||||
}
|
||||
if jsonDictionary["dependencies"] == nil {
|
||||
dependencies = []
|
||||
|
||||
@@ -68,6 +68,22 @@ func specLoadingTests() {
|
||||
try expectTargetError(target, .invalidDependency([invalid: "name"]))
|
||||
}
|
||||
|
||||
$0.it("parses sources") {
|
||||
var targetDictionary1 = validTarget
|
||||
targetDictionary1["sources"] = [
|
||||
"source1",
|
||||
["path": "source2"],
|
||||
]
|
||||
var targetDictionary2 = validTarget
|
||||
targetDictionary2["sources"] = "source3"
|
||||
|
||||
let target1 = try Target(name: "test", jsonDictionary: targetDictionary1)
|
||||
let target2 = try Target(name: "test", jsonDictionary: targetDictionary2)
|
||||
|
||||
try expect(target1.sources) == [Source(path: "source1"), Source(path: "source2")]
|
||||
try expect(target2.sources) == [Source(path: "source3")]
|
||||
}
|
||||
|
||||
$0.it("parses target dependencies") {
|
||||
var targetDictionary = validTarget
|
||||
targetDictionary["dependencies"] = [
|
||||
|
||||
Reference in New Issue
Block a user