|
| 1 | +enum PIF { |
| 2 | + struct Project: Decodable { |
| 3 | + let targets: [String] |
| 4 | + } |
| 5 | + |
| 6 | + struct Target: Decodable { |
| 7 | + struct BuildConfiguration: Decodable { |
| 8 | + let name: String |
| 9 | + let buildSettings: [String: String] |
| 10 | + } |
| 11 | + |
| 12 | + let guid: String |
| 13 | + let buildConfigurations: [BuildConfiguration] |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +struct BuildRequest: Decodable { |
| 18 | + let command: String = "build" // TODO: support other commands (e.g. "buildFiles") |
| 19 | + let configurationName: String |
| 20 | + let configuredTargets: [String] |
| 21 | + let platform: String |
| 22 | + |
| 23 | + enum Root: CodingKey { |
| 24 | + case configuredTargets |
| 25 | + case parameters |
| 26 | + |
| 27 | + enum ConfiguredTargets: CodingKey { |
| 28 | + case guid |
| 29 | + } |
| 30 | + enum Parameters: CodingKey { |
| 31 | + case activeRunDestination |
| 32 | + case configurationName |
| 33 | + |
| 34 | + enum ActiveRunDestination: CodingKey { |
| 35 | + case platform |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + init(from decoder: Decoder) throws { |
| 41 | + let root = try decoder.container(keyedBy: Root.self) |
| 42 | + let parameters = try root.nestedContainer(keyedBy: Root.Parameters.self, forKey: .parameters) |
| 43 | + |
| 44 | + // configurationName |
| 45 | + self.configurationName = try parameters.decode(String.self, forKey: .configurationName) |
| 46 | + |
| 47 | + // configuredTargets |
| 48 | + var configuredTargets = try root.nestedUnkeyedContainer(forKey: .configuredTargets) |
| 49 | + var decodedTargets = [String]() |
| 50 | + while !configuredTargets.isAtEnd { |
| 51 | + let target = try configuredTargets.nestedContainer(keyedBy: Root.ConfiguredTargets.self) |
| 52 | + decodedTargets.append(try target.decode(String.self, forKey: .guid)) |
| 53 | + } |
| 54 | + self.configuredTargets = decodedTargets |
| 55 | + |
| 56 | + // platform |
| 57 | + let activeRunDestination = try parameters.nestedContainer(keyedBy: Root.Parameters.ActiveRunDestination.self, forKey: .activeRunDestination) |
| 58 | + self.platform = try activeRunDestination.decode(String.self, forKey: .platform) |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +enum Output { |
| 63 | + typealias Map = [String: Target] |
| 64 | + |
| 65 | + struct Target: Codable { |
| 66 | + struct Config: Codable { |
| 67 | + struct Settings: Codable { |
| 68 | + let base: [String] |
| 69 | + var platforms: [String: Optional<[String]>] |
| 70 | + } |
| 71 | + |
| 72 | + let build: Settings? |
| 73 | + let buildFiles: Settings? |
| 74 | + } |
| 75 | + |
| 76 | + let label: String |
| 77 | + let configs: [String: Config] |
| 78 | + } |
| 79 | +} |
0 commit comments