Skip to content

Extract shared helpers and async-friendly process execution#25

Merged
obj-p merged 4 commits intomainfrom
build-system
Mar 20, 2026
Merged

Extract shared helpers and async-friendly process execution#25
obj-p merged 4 commits intomainfrom
build-system

Conversation

@obj-p
Copy link
Owner

@obj-p obj-p commented Mar 20, 2026

Summary

  • Async process execution (Use async-friendly Process execution in SPMBuildSystem #6): Replace all blocking process.waitUntilExit() calls in SPMBuildSystem, Compiler, IOSHostBuilder, and IOSPreviewSession with a shared runAsync utility that uses withCheckedThrowingContinuation + terminationHandler. This avoids blocking actor cooperative threads during long-running subprocesses (e.g., swift build).

  • Shared helpers (Extract shared helpers for build-detection and device-resolution #4): Extract duplicated build-detection (5 instances) and device-resolution (3 instances) logic from RunCommand, SnapshotCommand, and MCPServer into detectAndBuild and resolveDeviceUDID helpers. Net result: -194 lines, +199 lines (including new tests and the two new files).

Closes #4, closes #6

Test plan

  • All 47 existing tests pass (swift test)
  • 4 new AsyncProcess unit tests added and passing
  • Manual smoke test: swift build && .build/debug/previewsmcp serve — verify MCP tools work with correct stderr logging

🤖 Generated with Claude Code

obj-p and others added 3 commits March 19, 2026 22:12
Replace all blocking `process.waitUntilExit()` calls with
`withCheckedThrowingContinuation` + `terminationHandler` via a shared
`runAsync` utility, matching the pattern already used in
`SimulatorManager.screenshot()`. This avoids blocking actor cooperative
threads during long-running subprocesses.

Extract duplicated build-detection and device-resolution logic from
RunCommand, SnapshotCommand, and MCPServer into shared `detectAndBuild`
and `resolveDeviceUDID` helpers in BuildHelpers.swift.

Closes #4, closes #6

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…Error

Read pipe data eagerly via readabilityHandler instead of inside
terminationHandler to prevent deadlock when child output exceeds the
~64KB pipe buffer. Keep using ArgumentParser's ValidationError for
CLI device resolution errors to preserve usage hint formatting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace inline Process/terminationHandler in SimulatorManager.screenshot()
with runAsync() to avoid pipe buffer deadlock when simctl produces large
stderr output. Add hot-reload logging with session IDs for diagnostics.
Update integration test skill with toggle tap guidance, sleep timing, and
log sanity check instructions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Format files added/modified by this branch to match the swift-format
config merged on main. Also replace readabilityHandler-based pipe
reading with DispatchGroup + background readDataToEndOfFile() to
eliminate a race where terminationHandler could read stdoutData before
the readabilityHandler had appended its chunk, causing empty output
for short-lived processes like `xcrun --show-sdk-path`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@obj-p obj-p merged commit a897405 into main Mar 20, 2026
2 checks passed
@obj-p obj-p deleted the build-system branch March 20, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use async-friendly Process execution in SPMBuildSystem Extract shared helpers for build-detection and device-resolution

1 participant