Multiple functioning workarounds can be found above.
I used this approach:
- Quitting Xcode
- Deleting
~/Library/Caches/org.swift.swiftpm
- Deleting
~/Library/Developer/Xcode/DerivedData/YourProjectName
- Launching Xcode
Unfortunately, re-downloading the packages could take a very long time - as well as compiling them all again, when only a single repo fails.
I am not sure why reason Xcode's initial fetch succeeds and its subsequent fetches fail - neither does Xcode: "unknown error". It would be good to figure out, what the cause is. Some setup on my machine seems to be wrong, as my colleagues don't have this problem. Unfortunately, I could not figure it out.
So I ended up building this workaround, that just does what, that Xcode does not do: fetching the repos, that usually fail. It does so by going into the DerivedData
folder and fetching either all or the specified repos. Xcode will then be able to resolve the packages.
I put this function into my .profile
(sorry, I am still using bash).
function updateXcodeSPM() {
local current_dir="$PWD"
local target_dir="$HOME/Library/Developer/Xcode/DerivedData"
local specific_libraries=("$@")
find "$target_dir" -type d -name "SourcePackages" | while read spm_dir; do
if [[ ! "$spm_dir" =~ \.noindex ]]; then
find "$spm_dir/repositories" -type d -mindepth 1 -maxdepth 1 | while read repo_dir; do
if [ ${#specific_libraries[@]} -eq 0 ]; then
# No specific libraries provided, update all
echo "Fetching in $repo_dir"
(cd "$repo_dir" && git fetch) &
sleep 0.1
else
# Update only specific libraries
for lib in "${specific_libraries[@]}"; do
if [[ "$repo_dir" == *"repositories/$lib-"* ]]; then
echo "Fetching in $repo_dir"
(cd "$repo_dir" && git fetch) &
sleep 0.1
fi
done
fi
done
fi
done
cd "$current_dir"
}
You can call this function without parameters or with the names of the packages failing to download:
> updateXcodeSPM FailingPackage1 FailingPackage2
or
> updateXcodeSPM
I recommend listing the failing package(s) because it is quicker.
Hope, it helps you.
SourcePackages
directory in DerivedData you can find two repos with the namemy_private_repo
. It seems swift packages calls prune on one of these repos and it leaves that ref dangling. Haven't been able to look much more into it though