Skip to content

Fix path detection when Build appears in directory names#40

Merged
MartinP7r merged 1 commit intomainfrom
fix/build-path-detection
Mar 8, 2026
Merged

Fix path detection when Build appears in directory names#40
MartinP7r merged 1 commit intomainfrom
fix/build-path-detection

Conversation

@MartinP7r
Copy link
Copy Markdown
Owner

Summary

  • Fix components(separatedBy: "/Build/")[0] splitting on first occurrence instead of last
  • Use .range(of: "/Build/", options: .backwards) to match bash ${x%/Build/*} behavior
  • Update README run script to use robust parameter expansion with proper quoting

Supersedes #37 (which was based on stale pre-SwiftArgumentParser code and had significant scope creep).

Test plan

  • Verify path calculation works for standard Xcode DerivedData paths
  • Verify edge case: username containing "Build" (e.g., /Users/Build/Projects/...)
  • Build and run on a project with SPM dependencies

The old code used `components(separatedBy: "/Build/")[0]` which splits on
the first occurrence of "/Build/". This fails when usernames or project
paths contain "Build" (e.g., /Users/Build/Projects/App/Build/...).

Now uses `.range(of: "/Build/", options: .backwards)` to find the last
occurrence, matching the behavior of the shell `${x%/Build/*}` pattern.

Also updates the README run script to use the more robust `%/Build/*`
parameter expansion and proper quoting.

Closes #37
@MartinP7r MartinP7r self-assigned this Mar 8, 2026
@MartinP7r MartinP7r marked this pull request as ready for review March 8, 2026 07:22
Copilot AI review requested due to automatic review settings March 8, 2026 07:22
@MartinP7r MartinP7r merged commit 1d8ba54 into main Mar 8, 2026
2 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes AckGen’s SPM package cache path detection when "Build" appears earlier in PROJECT_TEMP_DIR (e.g., in a username or parent directory), and updates the README’s Xcode Run Script snippet to compute the AckGen checkout path more robustly.

Changes:

  • Update Swift path parsing to locate the last "/Build/" occurrence (matching ${x%/Build/*} behavior).
  • Update README Run Script to compute the AckGen checkout directory via shell parameter expansion and improve quoting/command substitution.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Sources/AckGenCLI/AckGen.swift Switches package cache base path detection to use a backwards "/Build/" match to avoid incorrect truncation when "Build" appears earlier in the path.
README.md Updates the recommended Xcode Run Script to compute the AckGen checkout path from PROJECT_TEMP_DIR using robust parameter expansion and proper quoting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +43 to +48
let packageCachePath: String
if let range = tempDirPath.range(of: "/Build/", options: .backwards) {
packageCachePath = String(tempDirPath[..<range.lowerBound]) + "/SourcePackages/checkouts"
} else {
packageCachePath = tempDirPath.components(separatedBy: "/Build/")[0] + "/SourcePackages/checkouts"
}
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else branch is redundant and keeps the old components(separatedBy: "/Build/")[0] logic around (which is the behavior this PR is trying to move away from). If "/Build/" isn't present, components(...)[0] is just tempDirPath anyway, so this can be simplified to make the intent clearer (e.g., use tempDirPath directly or compute a basePath once and append /SourcePackages/checkouts).

Suggested change
let packageCachePath: String
if let range = tempDirPath.range(of: "/Build/", options: .backwards) {
packageCachePath = String(tempDirPath[..<range.lowerBound]) + "/SourcePackages/checkouts"
} else {
packageCachePath = tempDirPath.components(separatedBy: "/Build/")[0] + "/SourcePackages/checkouts"
}
let basePath: String
if let range = tempDirPath.range(of: "/Build/", options: .backwards) {
basePath = String(tempDirPath[..<range.lowerBound])
} else {
basePath = tempDirPath
}
let packageCachePath = basePath + "/SourcePackages/checkouts"

Copilot uses AI. Check for mistakes.
Comment on lines +34 to 35
SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
swift run ackgen
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this shell snippet SDKROOT=$(...) only sets a shell variable; it is not exported, so swift run ackgen will not see SDKROOT in its environment. If the intent is to force the macOS SDK for the child process, export it (or set it inline on the swift run invocation); otherwise consider removing the line to avoid implying it has an effect.

Suggested change
SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
swift run ackgen
SDKROOT=$(xcrun --sdk macosx --show-sdk-path) swift run ackgen

Copilot uses AI. Check for mistakes.
@MartinP7r MartinP7r mentioned this pull request Mar 28, 2026
MartinP7r added a commit that referenced this pull request Mar 28, 2026
- Extract path-parsing logic into testable deriveCheckoutsPath() function
- Add 6 DeriveCheckoutsPathTests: standard path, archive builds (#6),
  "Build" in username (#40), multiple Build segments, fallback
- Add 5 PlistEncodingTests: both output formats, multiline license
  preservation, file write round-trip
- Fix ackgen.sh: missing $ in SDKROOT command substitution

Closes #43 Phase 2
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.

2 participants