Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PackageDescription

let package = Package(
name: "XcodeGen",
platforms: [.macOS(.v10_13)],
platforms: [.macOS(.v11)],
products: [
.executable(name: "xcodegen", targets: ["XcodeGen"]),
.library(name: "XcodeGenKit", targets: ["XcodeGenKit"]),
Expand All @@ -16,7 +16,7 @@ let package = Package(
.package(url: "https://github.com/yonaskolb/JSONUtilities.git", from: "4.2.0"),
.package(url: "https://github.com/kylef/Spectre.git", from: "0.9.2"),
.package(url: "https://github.com/onevcat/Rainbow.git", from: "4.0.0"),
.package(url: "https://github.com/tuist/XcodeProj.git", exact: "8.27.7"),
.package(url: "https://github.com/tuist/XcodeProj.git", exact: "9.10.1"),
.package(url: "https://github.com/jakeheis/SwiftCLI.git", from: "6.0.3"),
.package(url: "https://github.com/mxcl/Version", from: "2.0.0"),
.package(url: "https://github.com/freddi-kit/ArtifactBundleGen", exact: "0.0.8")
Expand Down
2 changes: 1 addition & 1 deletion Sources/ProjectSpec/Linkage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ extension Target {
private extension BuildSettings {

var machOType: String? {
self["MACH_O_TYPE"] as? String
self["MACH_O_TYPE"]?.stringValue
}
}
66 changes: 45 additions & 21 deletions Sources/ProjectSpec/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,17 @@ public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertibl
self.groups = groups
}

public init(dictionary: [String: Any]) {
buildSettings = dictionary
configSettings = [:]
groups = []
}

public static let empty: Settings = Settings(dictionary: [:])
public static let empty: Settings = Settings(buildSettings: [:])

public init(jsonDictionary: JSONDictionary) throws {
if jsonDictionary["configs"] != nil || jsonDictionary["groups"] != nil || jsonDictionary["base"] != nil {
groups = jsonDictionary.json(atKeyPath: "groups") ?? jsonDictionary.json(atKeyPath: "presets") ?? []
let buildSettingsDictionary: JSONDictionary = jsonDictionary.json(atKeyPath: "base") ?? [:]
buildSettings = buildSettingsDictionary
buildSettings = buildSettingsDictionary.mapValues { BuildSetting(any: $0) }

self.configSettings = try Self.extractValidConfigs(from: jsonDictionary)
} else {
buildSettings = jsonDictionary
buildSettings = jsonDictionary.mapValues { BuildSetting(any: $0) }
configSettings = [:]
groups = []
}
Expand All @@ -58,7 +52,7 @@ public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertibl
}

public static func == (lhs: Settings, rhs: Settings) -> Bool {
NSDictionary(dictionary: lhs.buildSettings).isEqual(to: rhs.buildSettings) &&
lhs.buildSettings == rhs.buildSettings &&
lhs.configSettings == rhs.configSettings &&
lhs.groups == rhs.groups
}
Expand Down Expand Up @@ -96,14 +90,14 @@ public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertibl

extension Settings: ExpressibleByDictionaryLiteral {

public init(dictionaryLiteral elements: (String, Any)...) {
var dictionary: [String: Any] = [:]
elements.forEach { dictionary[$0.0] = $0.1 }
self.init(dictionary: dictionary)
public init(dictionaryLiteral elements: (String, BuildSetting)...) {
var buildSettings: BuildSettings = [:]
elements.forEach { buildSettings[$0.0] = $0.1 }
self.init(buildSettings: buildSettings)
}
}

extension Dictionary where Key == String, Value: Any {
extension Dictionary where Key == String {

public func merged(_ dictionary: [Key: Value]) -> [Key: Value] {
var mergedDictionary = self
Expand All @@ -116,26 +110,56 @@ extension Dictionary where Key == String, Value: Any {
self[key] = value
}
}

public func equals(_ dictionary: BuildSettings) -> Bool {
NSDictionary(dictionary: self).isEqual(to: dictionary)
}
}

public func += (lhs: inout BuildSettings, rhs: BuildSettings?) {
guard let rhs = rhs else { return }
lhs.merge(rhs)
}

extension BuildSetting {

public init(any value: Any) {
if let array = value as? [String] {
self = .array(array)
} else if let bool = value as? Bool {
self = .init(booleanLiteral: bool)
} else {
self = .string("\(value)")
}
}

public func toAny() -> Any {
switch self {
case let .string(value): return value
case let .array(value): return value
}
}
}

extension ProjectAttribute {

public init(any value: Any) {
if let array = value as? [String] {
self = .array(array)
} else if let object = value as? PBXObject {
self = .targetReference(object)
} else {
self = .string("\(value)")
}
}
}

extension Settings: JSONEncodable {
public func toJSONValue() -> Any {
let anySettings = buildSettings.mapValues { $0.toAny() }
if groups.count > 0 || configSettings.count > 0 {
return [
"base": buildSettings,
"base": anySettings,
"groups": groups,
"configs": configSettings.mapValues { $0.toJSONValue() },
] as [String : Any]
}
return buildSettings
return anySettings
}
}
Loading