Fix `calculate_output_groups.py` failing or hanging on `build-request.json` #3389
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3389"
general
weight: 0.35
aaronsky
Summary
calculate_output_groups.pyno longer fails whenbuild-request.jsonis empty or half-written, and no longer depends on Xcode writing it at all in BwB mode. The script now uses the targets in the current build'smanifest.json, which Xcode writes atomically before the build starts, and only readsbuild-request.jsonif the manifest is missing or has none of our targets. If neither is usable, it waits at most 30 seconds, then falls back to an earlier build description for the same scheme, or fails with an actionable error.Why this change is needed
Two failures in the "Generate Bazel Dependencies" phase, both seen with Xcode 27.1 on a large BwB project:
1. Build fails with a parse error.
Afterwards the same file was valid JSON (2,687 bytes), so the script read it while Xcode was still writing it.
2. Build hangs for 20+ minutes on
newest 'buildRequest.json' file not updated yet, waiting.... The current build's.xcbuilddatafolder had a completemanifest.jsonbut never got abuild-request.json. An earlier folder still had none 8 minutes after its build.Both come from how Xcode's build system saves a build description (swift-build
BuildDescriptionManager.swift):build-request.jsonis written last, with a non-atomic write (create/truncate, then write), so it's briefly empty.manifest.jsonis different (swift-buildBuildDescription.swift). It's the llbuild manifest, written atomically while the description is constructed, before the build starts, because llbuild loads the build from it.What changed
calculate_output_groups.py- An empty, truncated, or deleted
build-request.jsonis treated as "not ready yet" and polled again, for both the Xcode 14.3+ and older code paths.- BwB mode: the script reads the current build's
manifest.jsonfirst and uses its targets right away, without waiting forbuild-request.json. It only readsbuild-request.jsonif there's nomanifest.json(e.g. older Xcode versions) or the manifest has none of our targets. Configured targets appear there astarget-<name>-<guid>-<parameters>. The script matches those against the PIF target GUIDs, which takes about 0.06 seconds for an 11 MB manifest. In BwB mode, every target in the build graph needs Bazel outputs, so this set is correct. BwX mode doesn't use the manifest, because it would make Bazel also build the libraries Xcode compiles.- The Xcode 14.3+ wait stops after 30 seconds (
_BUILD_REQUEST_TIMEOUT_SECONDS). The script then uses, in order:1. the newest
manifest.jsonthat includes the scheme's target (BwB only);2. the newest
build-request.jsonwhose configuration, platform, and targets match.Either way it prints a warning naming the file. If neither matches, it fails with "Quit and reopen Xcode, then build again."
- It now takes
CONFIGURATION,PLATFORM_NAME, andRULES_XCODEPROJ_BUILD_MODEas arguments.generate_bazel_dependencies.shpasses those three values.CreateScheme.swift: the "Initialize Bazel Build Output Groups File" pre-action writes$BAZEL_LABEL(of the scheme's first build target) into the build marker file instead of just touching it. The post-timeout fallbacks only accept build descriptions that include that target, so they won't pick up another scheme's targets. An empty marker (a scheme generated before this change) disables them.Known trade-off
The post-timeout fallbacks can use an earlier build description for the same scheme. If the scheme's target list changed since then, the earlier list is used. The warning tells the user what to do in that case. The immediate manifest path doesn't have this problem, because it only reads the current build's folder.
Testing
//xcodeproj/internal/bazel_integration_files:calculate_output_groups_tests(35 tests): empty, truncated, and missing files; waiting then succeeding; timeouts; manifest GUID parsing, including GUIDs that contain-and:; preferring the manifest overbuild-request.json, and falling back tobuild-request.jsonwhen the manifest is missing or has no known targets; post-timeout fallback order and matching; warning and error output.//tools/generators/xcschemes:xcschemes_testspasses with the updated pre-action script._mainend to end against a real Xcode 27.1manifest.json, in a fake DerivedData folder whose current.xcbuilddatahas nobuild-request.json. The script used the manifest immediately and printed the expected output groups.manifest.jsonlists exactly the two targets that build needs.Related
.xcbuilddatafolders are deleted.