Skip to content

Commit

Permalink
WIP: swift calculate_output_groups
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Pennig <[email protected]>
  • Loading branch information
pennig committed Jun 6, 2024
1 parent 18b171c commit 79eedcb
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 84 deletions.
4 changes: 2 additions & 2 deletions tools/calculate_output_groups/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ load(
# fix that for us.
macos_command_line_application(
name = "calculate_output_groups",
minimum_os_version = "12.0",
minimum_os_version = "13.0",
visibility = ["//visibility:public"],
deps = [":calculate_output_groups.library"],
)
Expand Down Expand Up @@ -46,7 +46,7 @@ apple_universal_binary(
"x86_64",
"arm64",
],
minimum_os_version = "12.0",
minimum_os_version = "13.0",
platform_type = "macos",
visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions tools/calculate_output_groups/CalculateOutputGroups.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ArgumentParser
import Darwin
import Foundation
import ToolCommon

@main
Expand Down
32 changes: 32 additions & 0 deletions tools/calculate_output_groups/Errors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ToolCommon

extension UsageError {
static func buildMarker(_ path: String) -> Self {
.init(message: """
error: Build marker (\(path)) doesn't exist. If you manually cleared Derived \
Data, you need to close and re-open the project for the file to be created \
again. Using the "Clean Build Folder" command instead (⇧ ⌘ K) won't trigger \
this error. If this error still happens after re-opening the project, please \
file a bug report here: \
https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md
""")
}

static func pifCache(_ path: String) -> Self {
.init(message: """
error: PIFCache (\(path)) doesn't exist. If you manually cleared Derived \
Data, you need to close and re-open the project for the PIFCache to be created \
again. Using the "Clean Build Folder" command instead (⇧ ⌘ K) won't trigger \
this error. If this error still happens after re-opening the project, please \
file a bug report here: \
https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md
""")
}

static func buildRequest(_ path: String) -> Self {
.init(message: """
error: Couldn't find a build-request.json file inside \(path)". Please file a bug \
report here: https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md
""")
}
}
79 changes: 79 additions & 0 deletions tools/calculate_output_groups/Models.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
enum PIF {
struct Project: Decodable {
let targets: [String]
}

struct Target: Decodable {
struct BuildConfiguration: Decodable {
let name: String
let buildSettings: [String: String]
}

let guid: String
let buildConfigurations: [BuildConfiguration]
}
}

struct BuildRequest: Decodable {
let command: String = "build" // TODO: support other commands (e.g. "buildFiles")
let configurationName: String
let configuredTargets: [String]
let platform: String

enum Root: CodingKey {
case configuredTargets
case parameters

enum ConfiguredTargets: CodingKey {
case guid
}
enum Parameters: CodingKey {
case activeRunDestination
case configurationName

enum ActiveRunDestination: CodingKey {
case platform
}
}
}

init(from decoder: Decoder) throws {
let root = try decoder.container(keyedBy: Root.self)
let parameters = try root.nestedContainer(keyedBy: Root.Parameters.self, forKey: .parameters)

// configurationName
self.configurationName = try parameters.decode(String.self, forKey: .configurationName)

// configuredTargets
var configuredTargets = try root.nestedUnkeyedContainer(forKey: .configuredTargets)
var decodedTargets = [String]()
while !configuredTargets.isAtEnd {
let target = try configuredTargets.nestedContainer(keyedBy: Root.ConfiguredTargets.self)
decodedTargets.append(try target.decode(String.self, forKey: .guid))
}
self.configuredTargets = decodedTargets

// platform
let activeRunDestination = try parameters.nestedContainer(keyedBy: Root.Parameters.ActiveRunDestination.self, forKey: .activeRunDestination)
self.platform = try activeRunDestination.decode(String.self, forKey: .platform)
}
}

enum Output {
typealias Map = [String: Target]

struct Target: Codable {
struct Config: Codable {
struct Settings: Codable {
let base: [String]
var platforms: [String: Optional<[String]>]
}

let build: Settings?
let buildFiles: Settings?
}

let label: String
let configs: [String: Config]
}
}
Loading

0 comments on commit 79eedcb

Please sign in to comment.