Skip to content

Commit 9d0f4aa

Browse files
committed
Convert calculate_output_groups.py into a Swift binary
Signed-off-by: Matt Pennig <mpennig@slack-corp.com>
1 parent 79eedcb commit 9d0f4aa

File tree

18 files changed

+68
-484
lines changed

18 files changed

+68
-484
lines changed

distribution/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ pkg_tar(
5959
remap_paths = dicts.add(
6060
{
6161
"MODULE.release.bazel": "MODULE.bazel",
62+
"tools/calculate_output_groups/BUILD.release.bazel": (
63+
"tools/calculate_output_groups/BUILD"
64+
),
6265
"tools/import_indexstores/BUILD.release.bazel": (
6366
"tools/import_indexstores/BUILD"
6467
),

examples/integration/test/fixtures/bwb.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/integration/test/fixtures/bwx.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rules_ios/test/fixtures/bwb.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/calculate_output_groups/CalculateOutputGroups.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ struct CalculateOutputGroups: AsyncParsableCommand {
1414
@OptionGroup var arguments: OutputGroupsCalculator.Arguments
1515

1616
func run() async throws {
17+
var output = StdoutOutputStream()
1718
let logger = DefaultLogger(
1819
standardError: StderrOutputStream(),
19-
standardOutput: StdoutOutputStream(),
20+
standardOutput: output,
2021
colorize: colorDiagnostics
2122
)
2223

23-
let calculator = OutputGroupsCalculator()
24+
let calculator = OutputGroupsCalculator(logger: logger)
2425

2526
do {
26-
try await calculator.calculateOutputGroups(arguments: arguments)
27+
let groups = try await calculator.calculateOutputGroups(arguments: arguments)
28+
print(groups, to: &output)
2729
} catch {
2830
logger.logError(error.localizedDescription)
2931
Darwin.exit(1)

tools/calculate_output_groups/Errors.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ToolCommon
33
extension UsageError {
44
static func buildMarker(_ path: String) -> Self {
55
.init(message: """
6-
error: Build marker (\(path)) doesn't exist. If you manually cleared Derived \
6+
Build marker (\(path)) doesn't exist. If you manually cleared Derived \
77
Data, you need to close and re-open the project for the file to be created \
88
again. Using the "Clean Build Folder" command instead (⇧ ⌘ K) won't trigger \
99
this error. If this error still happens after re-opening the project, please \
@@ -14,7 +14,7 @@ https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bu
1414

1515
static func pifCache(_ path: String) -> Self {
1616
.init(message: """
17-
error: PIFCache (\(path)) doesn't exist. If you manually cleared Derived \
17+
PIFCache (\(path)) doesn't exist. If you manually cleared Derived \
1818
Data, you need to close and re-open the project for the PIFCache to be created \
1919
again. Using the "Clean Build Folder" command instead (⇧ ⌘ K) won't trigger \
2020
this error. If this error still happens after re-opening the project, please \
@@ -25,7 +25,7 @@ https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bu
2525

2626
static func buildRequest(_ path: String) -> Self {
2727
.init(message: """
28-
error: Couldn't find a build-request.json file inside \(path)". Please file a bug \
28+
Couldn't find latest build-request.json file after 30 seconds. Please file a bug \
2929
report here: https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md
3030
""")
3131
}

tools/calculate_output_groups/OutputGroupsCalculator.swift

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import ToolCommon
33
import ZippyJSON
44

55
struct OutputGroupsCalculator {
6-
func calculateOutputGroups(arguments: Arguments) async throws {
6+
let logger: Logger
7+
8+
func calculateOutputGroups(arguments: Arguments) async throws -> String {
79
let pifCache = arguments.baseObjRoot.appendingPathComponent("XCBuildData/PIFCache")
810
let projectCache = pifCache.appendingPathComponent("project")
911
let targetCache = pifCache.appendingPathComponent("target")
@@ -30,12 +32,11 @@ struct OutputGroupsCalculator {
3032
targetCache: targetCache
3133
)
3234

33-
let output = try await outputGroups(
35+
return try await outputGroups(
3436
buildRequest: buildRequest,
3537
targets: targetMap,
3638
prefixes: arguments.outputGroupPrefixes
3739
)
38-
print(output)
3940
}
4041

4142
private func loadBuildRequestFile(inPath path: URL, since: Date) async throws -> BuildRequest {
@@ -54,22 +55,33 @@ struct OutputGroupsCalculator {
5455
}
5556

5657
// If the file was not immediately found, kick off a process to wait for the file to be created (or time out).
57-
let findTask = Task {
58-
while true {
59-
try Task.checkCancellation()
60-
try await Task.sleep(for: .seconds(1))
61-
if let buildRequestURL = findBuildRequestURL() {
62-
return buildRequestURL
58+
do {
59+
let findTask = Task {
60+
logger.logWarning("The latest build-request.json file has not been updated yet. Waiting…")
61+
while true {
62+
try Task.checkCancellation()
63+
try await Task.sleep(for: .seconds(1))
64+
if let buildRequestURL = findBuildRequestURL() {
65+
return buildRequestURL
66+
}
6367
}
6468
}
65-
}
66-
let timeoutTask = Task {
67-
try await Task.sleep(for: .seconds(10))
68-
findTask.cancel()
69-
}
69+
let waitingTask = Task {
70+
try await Task.sleep(for: .seconds(10))
71+
try Task.checkCancellation()
72+
logger.logWarning("""
73+
The latest build-request.json file has still not been updated after 10 seconds. If this happens frequently, please file a bug report here:
74+
https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md
75+
""")
76+
}
77+
let timeoutTask = Task {
78+
try await Task.sleep(for: .seconds(30))
79+
guard !Task.isCancelled else { return }
80+
findTask.cancel()
81+
}
7082

71-
do {
7283
let result = try await findTask.value
84+
waitingTask.cancel()
7385
timeoutTask.cancel()
7486
return try result.decode(BuildRequest.self)
7587
} catch {

tools/generators/legacy/src/Generator/AddBazelDependenciesTarget.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ extension Generator {
3535

3636
var buildSettings: BuildSettings = [
3737
"BAZEL_PACKAGE_BIN_DIR": "rules_xcodeproj",
38-
"CALCULATE_OUTPUT_GROUPS_SCRIPT": """
39-
$(BAZEL_INTEGRATION_DIR)/calculate_output_groups.py
40-
""",
4138
"INDEXING_SUPPORTED_PLATFORMS__": """
4239
$(INDEXING_SUPPORTED_PLATFORMS__NO)
4340
""",

tools/generators/legacy/src/Generator/SetTargetConfigurations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ $(BAZEL_OUT)\#(linkParams.path.string.dropFirst(9))
283283
buildSettings.set("TARGET_NAME", to: target.name)
284284

285285
if !target.product.isResourceBundle {
286-
// This is used in `calculate_output_groups.py`. We only want to set
286+
// This is used in `calculate_output_groups`. We only want to set
287287
// it on buildable targets
288288
buildSettings.set("BAZEL_LABEL", to: target.label.description)
289289
}

tools/generators/pbxnativetargets/src/Generator/CalculateSharedBuildSettings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ extension Generator.CalculateSharedBuildSettings {
114114
}
115115

116116
if productType != .resourceBundle {
117-
// This is used in `calculate_output_groups.py`. We only want to set
117+
// This is used in `calculate_output_groups`. We only want to set
118118
// it on buildable targets.
119119
buildSettings.append(
120120
.init(

0 commit comments

Comments
 (0)