mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
6b17b76435
Added support for compilerFlags in source list. If any source file metadata (like compilerFlags) is attached to a directory the metadata propagates downwards to all children recursively until the files are reached. Files are now processed in the same way as directories in `getSources` this depends on #108 to not over-eagerly cache groups. The `source` is propagated as metadata down all the way (thanks @yonaskolb) Fixtures and unit tests are updated as well.
61 lines
1.5 KiB
Swift
61 lines
1.5 KiB
Swift
//
|
|
// Source.swift
|
|
// ProjectSpec
|
|
//
|
|
// Created by Yonas Kolb on 31/10/17.
|
|
//
|
|
|
|
import Foundation
|
|
import JSONUtilities
|
|
import PathKit
|
|
|
|
public struct Source {
|
|
|
|
public var path: String
|
|
public var compilerFlags: [String]
|
|
|
|
public init(path: String, compilerFlags: [String] = []) {
|
|
self.path = path
|
|
self.compilerFlags = compilerFlags
|
|
}
|
|
}
|
|
|
|
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")
|
|
let maybeCompilerFlagsString: String? = jsonDictionary.json(atKeyPath: "compilerFlags")
|
|
let maybeCompilerFlagsArray: [String]? = jsonDictionary.json(atKeyPath: "compilerFlags")
|
|
compilerFlags = maybeCompilerFlagsArray ??
|
|
maybeCompilerFlagsString.map{ $0.split(separator: " ").map{ String($0) } } ?? []
|
|
}
|
|
}
|
|
|
|
extension Source: Equatable {
|
|
|
|
public static func == (lhs: Source, rhs: Source) -> Bool {
|
|
return lhs.path == rhs.path && lhs.compilerFlags == rhs.compilerFlags
|
|
}
|
|
}
|
|
|
|
extension Source: Hashable {
|
|
public var hashValue: Int {
|
|
return path.hashValue ^ compilerFlags.joined(separator: ":").hashValue
|
|
}
|
|
}
|