11#! /bin/bash
22
3- echo " Fixing iOS incompatible dependencies..."
3+ echo " Fixing iOS incompatible dependencies by patching rclone source ..."
44
55# Find the module root
66if [ -f go.mod ]; then
1515
1616echo " Working in module root: $( pwd) "
1717
18- # Check for problematic dependencies
19- echo " Checking for iOS incompatible dependencies ..."
20- go list -m all | grep -E " (go-m1cpu|gopsutil) " || echo " No problematic dependencies found in module list "
18+ # Check for rclone dependency
19+ echo " Checking for rclone dependency ..."
20+ RCLONE_VERSION= $( go list -m all | grep " github.com/rclone/rclone " | awk ' {print $2} ' || echo " " )
2121
22- # Try to exclude problematic dependencies by replacing them with stubs
23- echo " Attempting to exclude iOS incompatible dependencies..."
22+ if [ -z " $RCLONE_VERSION " ]; then
23+ echo " No rclone dependency found, skipping patch"
24+ exit 0
25+ fi
26+
27+ echo " Found rclone version: $RCLONE_VERSION "
28+
29+ # Download dependencies to get the source
30+ echo " Downloading dependencies..."
31+ go mod download
32+
33+ # Find the rclone module path
34+ RCLONE_PATH=$( go list -m -f ' {{.Dir}}' github.com/rclone/rclone 2> /dev/null)
35+
36+ if [ -z " $RCLONE_PATH " ]; then
37+ echo " Could not find rclone module path, trying alternative method..."
38+ # Try to find it in GOPATH/pkg/mod
39+ GOPATH_MOD=$( go env GOPATH) /pkg/mod
40+ RCLONE_PATH=$( find " $GOPATH_MOD " -name " rclone@$RCLONE_VERSION " -type d 2> /dev/null | head -1)
41+ fi
42+
43+ if [ -z " $RCLONE_PATH " ]; then
44+ echo " Could not locate rclone source directory, skipping patch"
45+ exit 0
46+ fi
47+
48+ echo " Found rclone source at: $RCLONE_PATH "
49+
50+ # Path to the problematic file
51+ OSVERSION_FILE=" $RCLONE_PATH /lib/buildinfo/osversion.go"
2452
25- # Replace go-m1cpu with a no-op version if it exists
26- if go list -m all | grep -q " go-m1cpu " ; then
27- echo " Found go-m1cpu dependency, attempting to exclude ..."
28- # Try to replace with a version that doesn't use iOS incompatible APIs
29- go mod edit -replace github.com/shoenig/go-m1cpu=github.com/shoenig/go-m1cpu@v0.1.5 || true
53+ if [ ! -f " $OSVERSION_FILE " ] ; then
54+ echo " osversion.go file not found at: $OSVERSION_FILE "
55+ echo " Checking if file exists with different structure ..."
56+ find " $RCLONE_PATH " -name " osversion.go " -type f 2> /dev/null || echo " No osversion.go found in rclone source "
57+ exit 0
3058fi
3159
32- # Clean and rebuild
33- echo " Cleaning and rebuilding module..."
60+ echo " Found osversion.go at: $OSVERSION_FILE "
61+
62+ # Check if file is writable (some module caches are read-only)
63+ if [ ! -w " $OSVERSION_FILE " ]; then
64+ echo " File is not writable, attempting to make it writable..."
65+ chmod +w " $OSVERSION_FILE " 2> /dev/null || {
66+ echo " Cannot make file writable, trying to copy module to local directory..."
67+
68+ # Create local copy of rclone module
69+ LOCAL_RCLONE_DIR=" ./local_rclone"
70+ mkdir -p " $LOCAL_RCLONE_DIR "
71+
72+ echo " Copying rclone source to local directory..."
73+ cp -r " $RCLONE_PATH " /* " $LOCAL_RCLONE_DIR /" 2> /dev/null || {
74+ echo " Failed to copy rclone source, skipping patch"
75+ exit 0
76+ }
77+
78+ # Update the file path to local copy
79+ OSVERSION_FILE=" $LOCAL_RCLONE_DIR /lib/buildinfo/osversion.go"
80+
81+ # Add replace directive to use local copy
82+ echo " Adding replace directive to use local rclone copy..."
83+ go mod edit -replace github.com/rclone/rclone=" ./local_rclone"
84+ fi
85+ fi
86+
87+ # Backup original file
88+ echo " Backing up original osversion.go..."
89+ cp " $OSVERSION_FILE " " $OSVERSION_FILE .backup" 2> /dev/null || echo " Could not create backup"
90+
91+ # Replace the file content with iOS-compatible version
92+ echo " Patching osversion.go for iOS compatibility..."
93+ cat > " $OSVERSION_FILE " << 'EOF '
94+ //go:build !windows
95+
96+ package buildinfo
97+
98+ // GetOSVersion returns OS version, kernel and bitness
99+ func GetOSVersion() (osVersion, osKernel string) {
100+ return
101+ }
102+ EOF
103+
104+ echo " Successfully patched osversion.go"
105+
106+ # Verify the patch
107+ if [ -f " $OSVERSION_FILE " ]; then
108+ echo " Verifying patch..."
109+ echo " New file content:"
110+ cat " $OSVERSION_FILE "
111+ echo " "
112+ fi
113+
114+ # Clean and rebuild to apply changes
115+ echo " Cleaning and rebuilding module with patched rclone..."
116+ go clean -modcache 2> /dev/null || echo " Could not clean mod cache (this is normal)"
34117go mod tidy
35118go mod download
36119
37- echo " Updated dependencies:"
38- go list -m all | grep -E " (mobile|m1cpu|gopsutil)" || echo " No relevant dependencies found"
39-
40- echo " iOS dependency fix completed"
120+ echo " iOS dependency fix completed by patching rclone source"
121+ echo " The problematic gopsutil calls in rclone have been disabled for iOS builds"
0 commit comments