Skip to content

Commit 9d834b3

Browse files
committed
fix(ios):Enhance iOS dependency fix script to patch rclone source directly
1 parent 0608a90 commit 9d834b3

File tree

2 files changed

+175
-17
lines changed

2 files changed

+175
-17
lines changed
Lines changed: 98 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
66
if [ -f go.mod ]; then
@@ -15,26 +15,107 @@ fi
1515

1616
echo "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
3058
fi
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)"
34117
go mod tidy
35118
go 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"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
echo "Verifying rclone patch for iOS compatibility..."
4+
5+
# Find the module root
6+
if [ -f go.mod ]; then
7+
MODULE_ROOT="."
8+
elif [ -f ../go.mod ]; then
9+
MODULE_ROOT=".."
10+
cd ..
11+
else
12+
echo "Error: Cannot find go.mod"
13+
exit 1
14+
fi
15+
16+
echo "Working in module root: $(pwd)"
17+
18+
# Check if local rclone copy exists
19+
if [ -d "local_rclone" ]; then
20+
echo "✅ Local rclone copy found"
21+
22+
OSVERSION_FILE="local_rclone/lib/buildinfo/osversion.go"
23+
if [ -f "$OSVERSION_FILE" ]; then
24+
echo "✅ osversion.go found in local copy"
25+
echo ""
26+
echo "Current content of osversion.go:"
27+
echo "================================"
28+
cat "$OSVERSION_FILE"
29+
echo "================================"
30+
echo ""
31+
32+
# Check if it contains the expected patch
33+
if grep -q "//go:build !windows" "$OSVERSION_FILE" && grep -q "return$" "$OSVERSION_FILE"; then
34+
echo "✅ Patch successfully applied - file contains iOS-compatible code"
35+
else
36+
echo "❌ Patch not properly applied - file may still contain problematic code"
37+
fi
38+
else
39+
echo "❌ osversion.go not found in local copy at: $OSVERSION_FILE"
40+
fi
41+
else
42+
echo "ℹ️ No local rclone copy found - checking if rclone is patched in module cache"
43+
44+
# Try to find rclone in module cache
45+
RCLONE_PATH=$(go list -m -f '{{.Dir}}' github.com/rclone/rclone 2>/dev/null)
46+
47+
if [ -n "$RCLONE_PATH" ]; then
48+
echo "Found rclone in module cache at: $RCLONE_PATH"
49+
50+
OSVERSION_FILE="$RCLONE_PATH/lib/buildinfo/osversion.go"
51+
if [ -f "$OSVERSION_FILE" ]; then
52+
echo "osversion.go found in module cache"
53+
echo ""
54+
echo "Current content:"
55+
echo "================"
56+
cat "$OSVERSION_FILE" 2>/dev/null || echo "Cannot read file (may be read-only)"
57+
echo "================"
58+
else
59+
echo "osversion.go not found at: $OSVERSION_FILE"
60+
fi
61+
else
62+
echo "❌ Cannot locate rclone module"
63+
fi
64+
fi
65+
66+
# Check go.mod for replace directives
67+
echo ""
68+
echo "Checking go.mod for rclone replace directives..."
69+
if grep -q "github.com/rclone/rclone" go.mod; then
70+
echo "Found rclone references in go.mod:"
71+
grep "github.com/rclone/rclone" go.mod
72+
else
73+
echo "No rclone references found in go.mod"
74+
fi
75+
76+
echo ""
77+
echo "Verification completed."

0 commit comments

Comments
 (0)