Skip to content

Fix path detection for SPM packages when "Build" appears in paths#37

Closed
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-ackgen-install-issue
Closed

Fix path detection for SPM packages when "Build" appears in paths#37
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-ackgen-install-issue

Conversation

Copilot AI commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

AckGen's path detection fails when usernames or project paths contain "Build" (e.g., /Users/Build/Projects/App/Build/Intermediates). The original implementation split on the first /Build/ occurrence instead of removing from the last occurrence, producing incorrect base paths.

Changes

Core Fix

  • Swift (AckGen.swift): Changed from components(separatedBy: "/Build/")[0] to .range(of: "/Build/", options: .backwards)
  • Bash (README, scripts): Changed from awk -F'/Build/' '{print $1}' to ${PROJECT_TEMP_DIR%/Build/*}
// Before: splits on first /Build/, fails for /Users/Build/Projects/App/Build/...
let base = tempDirPath.components(separatedBy: "/Build/")[0]

// After: finds last /Build/, handles edge cases correctly
let base: String
if let range = tempDirPath.range(of: "/Build/", options: .backwards) {
    base = String(tempDirPath[..<range.lowerBound])
} else {
    base = tempDirPath
}

Testing

  • Added IntegrationTests.swift with calculateBasePath() helper matching production logic
  • Covers standard paths, nested builds, username/path edge cases
  • Shell-based validation suite in test_path_calculation.sh

Diagnostic Tools

  • diagnose_path.swift - Swift diagnostic tool with environment analysis
  • diagnose_path.sh - Shell equivalent for quick checks
  • Both provide actionable troubleshooting steps

Documentation

  • Updated README installation script to use parameter expansion
  • Added troubleshooting section explaining edge case handling
  • CI workflow for integration tests on macOS

Example Edge Case

# Input path
PROJECT_TEMP_DIR="/Users/Build/Projects/App/Build/Intermediates.noindex/App.build"

# Old approach (wrong)
BASE_DIR=$(echo "$PROJECT_TEMP_DIR" | awk -F'/Build/' '{print $1}')
# Result: /Users (incorrect - stops at username)

# New approach (correct)
BASE_DIR="${PROJECT_TEMP_DIR%/Build/*}"
# Result: /Users/Build/Projects/App (correct - stops at actual Build directory)
Original prompt

This section details on the original issue you should resolve

<issue_title>AckGen not found...</issue_title>
<issue_description>Hi,

I'm constantly getting the ...
AckGen not found. Please install the package via SPM (https://github.com/MartinP7r/AckGen#installation)
... message

I've had a bit of look around and can't find the folder it's looking for.

I've had this issue with Xcode 13.3, and now 13.4.

Any ideas ?

Thanks,

Jules.</issue_description>

<agent_instructions>As mentioned in the comments in this issue, depending on the project setup, the patch to the packages might be different.
Let's find out why and how to consistently integration test it.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@MartinP7r Sorry, I haven't had a chance to look at that. Maybe I get to it in the coming days. Are you running this from a ScriptPhase script as described in the readme? @MartinP7r @JulesMoorhouse are you by any chance using something other than SPM to install this package? If so the package will not reside in `DIR=$PROJECT_TEMP_DIR/../../../SourcePackages/checkouts/AckGen`, so you would need to change the path in your RunScript accordingly. @MartinP7r @JulesMoorhouse I'll close this for now. Please feel free to reopen if the issue still happens. Please let me know.

PS:

I've had a bit of look around and can't find the folder it's looking for.

You can find the folder it's looking for by printing $PROJECT_TEMP_DIR from your run script and investigate from there.</comment_new>
<comment_new>@MartinP7r
@beekeweerts Hallöchen!

Thanks for sharing.
I just tried with Xcode 14.3.1 and it works normally for me, so I'm thinking there might we some difference between our Xcode environments.

As mentioned above, for investigation. Could you print $PROJECT_TEMP_DIR and share the output? Since mine looks like below, yours must be at least 3 folders deeper.

/Users/[USERNAME]/Library/Developer/Xcode/DerivedData/[APPNAME]-fkztgoovyeymvbaqsqyonvjdlabf/Build/Intermediates.noindex/[APPNAME].build

Also, if you are able to share a minimum reproducible example project, that would be helpful.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits February 7, 2026 01:03
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>
Co-authored-by: MartinP7r <2669027+MartinP7r@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix AckGen not found error in Xcode Fix path detection for SPM packages when "Build" appears in paths Feb 7, 2026
Copilot AI requested a review from MartinP7r February 7, 2026 01:20
MartinP7r added a commit that referenced this pull request Mar 8, 2026
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

Copy link
Copy Markdown
Owner

Closing in favor of #40 which applies the core path detection fix cleanly on the current main branch (post-SwiftArgumentParser migration from #31).

This PR had the right idea but was based on stale code and included significant scope creep (diagnostic scripts, test scripts, CI workflows). The essential fix (using .backwards search for "/Build/") has been preserved in #40.

@MartinP7r MartinP7r closed this Mar 8, 2026
MartinP7r added a commit that referenced this pull request Mar 8, 2026
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
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.

AckGen not found...

2 participants