-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup-iOS.sh
executable file
·132 lines (115 loc) · 4.14 KB
/
setup-iOS.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# set -e
usage() {
echo "Usage:"
echo
echo " source $1 <python version> [<support revision>]"
echo
echo "for example:"
echo
echo " source $1 3.12"
echo " source $1 3.12 3"
echo
}
# make sure the script is sourced
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
echo "This script must be sourced."
echo
usage $0
exit 1
fi
if [ -z "$1" ]; then
echo "Python version is not provided."
echo
usage $0
return
fi
PYTHON_VER=$1
if [ ! -z "$VIRTUAL_ENV" ]; then
echo "A virtual environment is already active; deactivate that environment before calling this script."
return
fi
# Create directories required by the script
mkdir -p deps
mkdir -p dist
mkdir -p downloads
mkdir -p published
if [ -z "$PYTHON_APPLE_SUPPORT" ]; then
export MOBILE_FORGE_SUPPORT_PATH=$(pwd)/support
if [ ! -d "$MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS" ]; then
if [ -z "$2" ]; then
case $PYTHON_VER in
3.9) SUPPORT_REVISION=14 ;;
3.10) SUPPORT_REVISION=10 ;;
3.11) SUPPORT_REVISION=5 ;;
3.12) SUPPORT_REVISION=4 ;;
3.13) SUPPORT_REVISION=1 ;;
*)
echo "No default support revision for $PYTHON_VER is known; it must be specified manually"
return
;;
esac
else
SUPPORT_REVISION=$2
fi
if [ ! -e "downloads/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz" ]; then
echo "Downloading Python ${PYTHON_VER} b${SUPPORT_REVISION} support package"
curl --location "https://github.com/beeware/Python-Apple-support/releases/download/${PYTHON_VER}-b${SUPPORT_REVISION}/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz" --output downloads/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz
fi
echo "Unpacking Python ${PYTHON_VER} b${SUPPORT_REVISION} support package"
mkdir -p $MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS
pushd $MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS
tar zxf ../../../downloads/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz
popd
fi
else
export MOBILE_FORGE_SUPPORT_PATH=$PYTHON_APPLE_SUPPORT/support
fi
echo "Using $MOBILE_FORGE_SUPPORT_PATH as the support folder"
BUILD_PYTHON=$(which python$PYTHON_VER)
if [ $? -ne 0 ]; then
echo "Can't find a Python $PYTHON_VER binary on the path."
return
fi
if [ ! -e $MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS/Python.xcframework/ios-arm64/bin/python$PYTHON_VER ]; then
echo "Support folder does not appear to contain a Python $PYTHON_VER iOS device binary."
return
fi
if [ ! -e $MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS/Python.xcframework/ios-arm64_x86_64-simulator/bin/python$PYTHON_VER ]; then
echo "Support folder does not appear to contain a Python $PYTHON_VER iOS simulator binary."
return
fi
if [ ! -d ./venv$PYTHON_VER ]; then
echo "Creating Python $PYTHON_VER virtual environment for build..."
echo "Using $BUILD_PYTHON as the build python"
$BUILD_PYTHON -m venv venv$PYTHON_VER
source ./venv$PYTHON_VER/bin/activate
# Install basic environment artefacts
pip install -U pip
pip install -U setuptools
pip install -e . wheel
echo "Python $PYTHON_VERSION environment has been created."
echo
echo "You can now build packages with forge; e.g.:"
echo
echo "Build all packages for all iOS targets:"
echo " forge iOS"
echo
echo "Build only the non-python packages, for all iOS targets:"
echo " forge iOS -s non-py"
echo
echo "Build all packages needed for a smoke test, for all iOS targets:"
echo " forge iOS -s smoke"
echo
echo "Build lru-dict for all iOS targets:"
echo " forge iOS lru-dict"
echo
echo "Build lru-dict for the ARM64 device target:"
echo " forge iphoneos:arm64 lru-dict"
echo
echo "Build all applicable versions of lru-dict for all iOS targets:"
echo " forge iOS --all-versions lru-dict"
echo
else
echo "Using existing Python $PYTHON_VER environment."
source ./venv$PYTHON_VER/bin/activate
fi