|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | + |
| 7 | +# Uses a local version of application services xcframework |
| 8 | + |
| 9 | +# This script allows switches the usage of application services to a local xcframework |
| 10 | +# built from a local checkout of application services |
| 11 | + |
| 12 | +set -e |
| 13 | + |
| 14 | +# CMDNAME is used in the usage text below |
| 15 | +CMDNAME=$(basename "$0") |
| 16 | +USAGE=$(cat <<EOT |
| 17 | +${CMDNAME} |
| 18 | + |
| 19 | +
|
| 20 | +Uses a local version of application services xcframework |
| 21 | +
|
| 22 | +This script allows switches the usage of application services to a local xcframework |
| 23 | +built from a local checkout of application services |
| 24 | +
|
| 25 | +
|
| 26 | +USAGE: |
| 27 | + ${CMDNAME} [OPTIONS] <LOCAL_APP_SERVICES_PATH> |
| 28 | +
|
| 29 | +OPTIONS: |
| 30 | + -d, --disable Disables local development on application services |
| 31 | + -h, --help Display this help message. |
| 32 | +EOT |
| 33 | +) |
| 34 | + |
| 35 | +msg () { |
| 36 | + printf "\033[0;34m> %s\033[0m\n" "${1}" |
| 37 | +} |
| 38 | + |
| 39 | +helptext() { |
| 40 | + echo "$USAGE" |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" |
| 46 | +PACKAGE_FILE="$THIS_DIR/Package.swift" |
| 47 | +SWIFT_SOURCE="$THIS_DIR/swift-source" |
| 48 | +FRAMEWORK_PATH="./MozillaRustComponents.xcframework" |
| 49 | +FRAMEWORK_PATH_ESCAPED=$( echo $FRAMEWORK_PATH | sed 's/\//\\\//g' ) |
| 50 | +APP_SERVICES_REMOTE="https://github.com/mozilla/application-services" |
| 51 | + |
| 52 | +DISABLE="false" |
| 53 | +APP_SERVICES_DIR= |
| 54 | +while (( "$#" )); do |
| 55 | + case "$1" in |
| 56 | + -d|--disable) |
| 57 | + DISABLE="true" |
| 58 | + shift |
| 59 | + ;; |
| 60 | + -h|--help) |
| 61 | + helptext |
| 62 | + exit 0 |
| 63 | + ;; |
| 64 | + --) # end argument parsing |
| 65 | + shift |
| 66 | + break |
| 67 | + ;; |
| 68 | + --*=|-*) # unsupported flags |
| 69 | + echo "Error: Unsupported flag $1" >&2 |
| 70 | + exit 1 |
| 71 | + ;; |
| 72 | + *) # preserve positional arguments |
| 73 | + APP_SERVICES_DIR=$1 |
| 74 | + shift |
| 75 | + ;; |
| 76 | + esac |
| 77 | +done |
| 78 | + |
| 79 | +if [ "true" = $DISABLE ]; then |
| 80 | + msg "Resetting $PACKAGE_FILE to use remote xcframework" |
| 81 | + # We disable the local development and revert back |
| 82 | + # ideally, users should just use git reset. |
| 83 | + # |
| 84 | + # This exist so local development can be easy to enable/disable |
| 85 | + # and we trust that once developers are ready to push changes |
| 86 | + # they will clean the files to make sure they are in the same |
| 87 | + # state they were in before any of the changes happened. |
| 88 | + perl -0777 -pi -e "s/ path: \"$FRAMEWORK_PATH_ESCAPED\"/ url: url, |
| 89 | + checksum: checksum/igs" $PACKAGE_FILE |
| 90 | + |
| 91 | + msg "Done reseting $PACKAGE_FILE" |
| 92 | + git add $PACKAGE_FILE |
| 93 | + msg "$PACKAGE_FILE changes staged" |
| 94 | + |
| 95 | + if [ -d $FRAMEWORK_PATH ]; then |
| 96 | + msg "Detected local framework, deleting it.." |
| 97 | + rm -rf $FRAMEWORK_PATH |
| 98 | + git add $FRAMEWORK_PATH |
| 99 | + msg "Deleted and staged the deletion of the local framework" |
| 100 | + fi |
| 101 | + msg "IMPORTANT: reminder that changes to this repository are not visable to consumers until |
| 102 | + commited" |
| 103 | + exit 0 |
| 104 | +fi |
| 105 | + |
| 106 | +if [ -z $APP_SERVICES_DIR ]; then |
| 107 | + msg "Please set the application-services path." |
| 108 | + msg "This is a path to a local checkout of the application services repository" |
| 109 | + msg "You can find the repository on $APP_SERVICES_REMOTE" |
| 110 | + exit 1 |
| 111 | +fi |
| 112 | + |
| 113 | +## First we build the xcframework in the application services repository |
| 114 | +msg "Building the xcframework in $APP_SERVICES_DIR" |
| 115 | +msg "This might take a few minutes" |
| 116 | +pushd $APP_SERVICES_DIR/megazords/ios-rust/ |
| 117 | +./build-xcframework.sh |
| 118 | +popd |
| 119 | + |
| 120 | +## Once built, we want to move the frameowork to this repository, then unzip it |
| 121 | +mv $APP_SERVICES_DIR/megazords/ios-rust/MozillaRustComponents.xcframework $THIS_DIR/MozillaRustComponents.xcframework |
| 122 | + |
| 123 | +## We replace the url and checksum in the Package.swift with a refernce to the local |
| 124 | +## framework path |
| 125 | +perl -0777 -pi -e "s/ url: url, |
| 126 | + checksum: checksum/ path: \"$FRAMEWORK_PATH_ESCAPED\"/igs" $PACKAGE_FILE |
| 127 | + |
| 128 | +## We also add the xcframework to git, and remind the user that it **needs** to be committed |
| 129 | +## for it to be used |
| 130 | +msg "Staging the xcframework and package.swift changes to git" |
| 131 | +git add $FRAMEWORK_PATH |
| 132 | +git add $PACKAGE_FILE |
| 133 | + |
| 134 | + |
| 135 | +## We should also get the swift-source code copied and staged as well |
| 136 | +msg "Generating swift source code..." |
| 137 | +./generate.sh $APP_SERVICES_DIR |
| 138 | +msg "Swift source code also generated, staging it now" |
| 139 | +git add $SWIFT_SOURCE |
| 140 | + |
| 141 | +msg "Done setting up rust-components-swift to use $APP_SERVICES_DIR" |
| 142 | +msg "IMPORTANT: Reminder that changes to this repository |
| 143 | + MUST be commited before they can be used by consumers" |
0 commit comments