Skip to content

Commit 79eedcb

Browse files
committed
WIP: swift calculate_output_groups
Signed-off-by: Matt Pennig <[email protected]>
1 parent 18b171c commit 79eedcb

File tree

6 files changed

+345
-84
lines changed

6 files changed

+345
-84
lines changed

tools/calculate_output_groups/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ load(
1818
# fix that for us.
1919
macos_command_line_application(
2020
name = "calculate_output_groups",
21-
minimum_os_version = "12.0",
21+
minimum_os_version = "13.0",
2222
visibility = ["//visibility:public"],
2323
deps = [":calculate_output_groups.library"],
2424
)
@@ -46,7 +46,7 @@ apple_universal_binary(
4646
"x86_64",
4747
"arm64",
4848
],
49-
minimum_os_version = "12.0",
49+
minimum_os_version = "13.0",
5050
platform_type = "macos",
5151
visibility = ["//visibility:public"],
5252
)

tools/calculate_output_groups/CalculateOutputGroups.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ArgumentParser
22
import Darwin
3+
import Foundation
34
import ToolCommon
45

56
@main
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import ToolCommon
2+
3+
extension UsageError {
4+
static func buildMarker(_ path: String) -> Self {
5+
.init(message: """
6+
error: Build marker (\(path)) doesn't exist. If you manually cleared Derived \
7+
Data, you need to close and re-open the project for the file to be created \
8+
again. Using the "Clean Build Folder" command instead (⇧ ⌘ K) won't trigger \
9+
this error. If this error still happens after re-opening the project, please \
10+
file a bug report here: \
11+
https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md
12+
""")
13+
}
14+
15+
static func pifCache(_ path: String) -> Self {
16+
.init(message: """
17+
error: PIFCache (\(path)) doesn't exist. If you manually cleared Derived \
18+
Data, you need to close and re-open the project for the PIFCache to be created \
19+
again. Using the "Clean Build Folder" command instead (⇧ ⌘ K) won't trigger \
20+
this error. If this error still happens after re-opening the project, please \
21+
file a bug report here: \
22+
https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md
23+
""")
24+
}
25+
26+
static func buildRequest(_ path: String) -> Self {
27+
.init(message: """
28+
error: Couldn't find a build-request.json file inside \(path)". Please file a bug \
29+
report here: https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md
30+
""")
31+
}
32+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

Comments
 (0)