-
Notifications
You must be signed in to change notification settings - Fork 10
/
appservices_local_xcframework.sh
executable file
·158 lines (129 loc) · 5.22 KB
/
appservices_local_xcframework.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Uses a local version of application services xcframework
# This script allows switches the usage of application services to a local xcframework
# built from a local checkout of application services
set -e
# CMDNAME is used in the usage text below
CMDNAME=$(basename "$0")
USAGE=$(cat <<EOT
${CMDNAME}
Tarik Eshaq <teshaq@mozilla.com>
Uses a local version of application services xcframework
This script allows switches the usage of application services to a local xcframework
built from a local checkout of application services
USAGE:
${CMDNAME} [OPTIONS] <LOCAL_APP_SERVICES_PATH>
OPTIONS:
-d, --disable Disables local development on application services
-h, --help Display this help message.
EOT
)
msg () {
printf "\033[0;34m> %s\033[0m\n" "${1}"
}
helptext() {
echo "$USAGE"
}
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PACKAGE_FILE="$THIS_DIR/Package.swift"
SWIFT_SOURCE="$THIS_DIR/swift-source"
FRAMEWORK_PATH="./MozillaRustComponents.xcframework"
FOCUS_FRAMEWORK_PATH="./FocusRustComponents.xcframework"
FRAMEWORK_PATH_ESCAPED=$( echo $FRAMEWORK_PATH | sed 's/\//\\\//g' )
FOCUS_FRAMEWORK_PATH_ESCAPED=$( echo $FOCUS_FRAMEWORK_PATH | sed 's/\//\\\//g' )
APP_SERVICES_REMOTE="https://github.com/mozilla/application-services"
DISABLE="false"
APP_SERVICES_DIR=
while (( "$#" )); do
case "$1" in
-d|--disable)
DISABLE="true"
shift
;;
-h|--help)
helptext
exit 0
;;
--) # end argument parsing
shift
break
;;
--*=|-*) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
APP_SERVICES_DIR=$1
shift
;;
esac
done
if [ "true" = $DISABLE ]; then
msg "Resetting $PACKAGE_FILE to use remote xcframework"
# We disable the local development and revert back
# ideally, users should just use git reset.
#
# This exist so local development can be easy to enable/disable
# and we trust that once developers are ready to push changes
# they will clean the files to make sure they are in the same
# state they were in before any of the changes happened.
perl -0777 -pi -e "s/ path: \"$FRAMEWORK_PATH_ESCAPED\"/ url: url,
checksum: checksum/igs" $PACKAGE_FILE
perl -0777 -pi -e "s/ path: \"$FOCUS_FRAMEWORK_PATH_ESCAPED\"/ url: focusUrl,
checksum: focusChecksum/igs" $PACKAGE_FILE
msg "Done reseting $PACKAGE_FILE"
git add $PACKAGE_FILE
msg "$PACKAGE_FILE changes staged"
if [ -d $FRAMEWORK_PATH ]; then
msg "Detected local framework, deleting it.."
rm -rf $FRAMEWORK_PATH
git add $FRAMEWORK_PATH
msg "Deleted and staged the deletion of the local framework"
fi
if [ -d $FOCUS_FRAMEWORK_PATH ]; then
msg "Detected local framework, deleting it.."
rm -rf $FOCUS_FRAMEWORK_PATH
git add $FOCUS_FRAMEWORK_PATH
msg "Deleted and staged the deletion of the local framework"
fi
msg "IMPORTANT: reminder that changes to this repository are not visable to consumers until
commited"
exit 0
fi
if [ -z $APP_SERVICES_DIR ]; then
msg "Please set the application-services path."
msg "This is a path to a local checkout of the application services repository"
msg "You can find the repository on $APP_SERVICES_REMOTE"
exit 1
fi
## We replace the url and checksum in the Package.swift with a refernce to the local
## framework path
perl -0777 -pi -e "s/ url: url,
checksum: checksum/ path: \"$FRAMEWORK_PATH_ESCAPED\"/igs" $PACKAGE_FILE
## We replace the url and checksum in the Package.swift with a refernce to the local
## framework path
perl -0777 -pi -e "s/ url: focusUrl,
checksum: focusChecksum/ path: \"$FOCUS_FRAMEWORK_PATH_ESCAPED\"/igs" $PACKAGE_FILE
rm -rf "$SWIFT_SOURCE"
## First we build the xcframework in the application services repository
msg "Building the xcframework in $APP_SERVICES_DIR"
msg "This might take a few minutes"
pushd $APP_SERVICES_DIR
./taskcluster/scripts/build-and-test-swift.py "$SWIFT_SOURCE" "$THIS_DIR" "$THIS_DIR/build/glean-dir" --force_build
popd
unzip -o "$THIS_DIR/MozillaRustComponents.xcframework.zip" && rm "$THIS_DIR/MozillaRustComponents.xcframework.zip"
unzip -o "$THIS_DIR/FocusRustComponents.xcframework.zip" && rm "$THIS_DIR/FocusRustComponents.xcframework.zip"
## We also add the xcframework and swiftsource to git, and remind the user that it **needs** to be committed
## for it to be used
msg "Staging the xcframework and package.swift changes to git"
git add $FRAMEWORK_PATH
git add $FOCUS_FRAMEWORK_PATH
git add $PACKAGE_FILE
msg "Swift source code also generated, staging it now"
git add $SWIFT_SOURCE
msg "Done setting up rust-components-swift to use $APP_SERVICES_DIR"
msg "IMPORTANT: Reminder that changes to this repository
MUST be commited before they can be used by consumers"