refactor(mk): move build rules into separate scripts (#855)

See https://github.com/ooni/probe/issues/2218
This commit is contained in:
Simone Basso
2022-08-17 13:16:53 +02:00
committed by GitHub
parent 4e99e5030a
commit 5c0368c862
19 changed files with 538 additions and 272 deletions
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
set -euo pipefail
__version=$(date -u +%Y.%m.%d-%H%M%S)
cat ./MOBILE/android/template.pom | sed -e "s/@VERSION@/$__version/g" > ./MOBILE/android/oonimkall.pom
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
set -euo pipefail
__install_extra="build-tools;32.0.0 platforms;android-31"
__ndk_version="23.1.7779620"
GOOS=$(go env GOOS)
case $GOOS in
linux)
__sdk_dir=$HOME/Android/Sdk
;;
darwin)
__sdk_dir=$HOME/Library/Android/sdk
;;
*)
echo "FATAL: unsupported operating system" 1>&2
exit 1
;;
esac
ANDROID_HOME=${ANDROID_HOME:-$__sdk_dir}
if [[ ! -d $ANDROID_HOME ]]; then
echo "FATAL: expected to find android SDK at $ANDROID_HOME, but found nothing" 1>&2
echo "HINT: run ./MOBILE/android/setup to (re)install the SDK" 1>&2
exit 1
fi
__sdkmanager=$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager
if [[ ! -x $__sdkmanager ]]; then
echo "FATAL: expected to find sdkmanager at $__sdkmanager, but found nothing" 1>&2
echo "HINT: run ./MOBILE/android/setup to (re)install the SDK" 1>&2
exit 1
fi
set -x
echo "Yes" | $__sdkmanager --install $__install_extra "ndk;$__ndk_version"
+52
View File
@@ -0,0 +1,52 @@
#!/bin/bash
set -euo pipefail
GOOS=$(go env GOOS)
case $GOOS in
linux)
__sdk_dir=$HOME/Android/Sdk
;;
darwin)
__sdk_dir=$HOME/Library/Android/sdk
;;
*)
echo "FATAL: unsupported operating system" 1>&2
exit 1
;;
esac
ANDROID_HOME=${ANDROID_HOME:-$__sdk_dir}
__clitools_version=8512546
__clitools_file=commandlinetools-linux-${__clitools_version}_latest.zip
__clitools_sha256=2ccbda4302db862a28ada25aa7425d99dce9462046003c1714b059b5c47970d8
printf "checking for curl... "
command -v curl || {
echo "not found"
exit 1
}
printf "checking for shasum... "
command -v shasum || {
echo "not found"
exit 1
}
printf "checking for unzip... "
command -v unzip || {
echo "not found"
exit 1
}
set -x
rm -rf $ANDROID_HOME/cmdline-tools/latest
curl -fsSLO https://dl.google.com/android/repository/$__clitools_file
echo "$__clitools_sha256 $__clitools_file" >__SHA256
shasum --check __SHA256
rm -f __SHA256
unzip $__clitools_file
rm $__clitools_file
mkdir -p $ANDROID_HOME/cmdline-tools
# See https://stackoverflow.com/a/61176718 to understand why
# we need to reorganize the directories like this:
mv cmdline-tools $ANDROID_HOME/cmdline-tools/latest
+61
View File
@@ -0,0 +1,61 @@
#!/bin/bash
set -euo pipefail
if [[ $# -ne 2 ]]; then
echo "" 1>&2
echo "Calls gomobile for either Android or iOS to build PACKAGE." 1>&2
echo "" 1>&2
echo "usage: $0 TARGET PACKAGE" 1>&2
echo "" 1>&2
echo "TARGET must be one of: android, ios." 1>&2
echo "" 1>&2
echo "Features:" 1>&2
echo "" 1>&2
echo "* automatically sets -tags=ooni_psiphon_config when possible;" 1>&2
echo "" 1>&2
echo "* if GOLANG_EXTRA_FLAGS is set, pass it to the Go compiler." 1>&2
echo "" 1>&2
echo "Example:" 1>&2
echo "" 1>&2
echo " ./MOBILE/gomobile android ./pkg/oonimkall" 1>&2
echo "" 1>&2
exit 1
fi
TARGET=$1
PACKAGE=$2
if [[ $TARGET == "android" ]]; then
EXT="aar"
elif [[ $TARGET == "ios" ]]; then
EXT="xcframework"
else
echo "FATAL: unsupported target: $TARGET" 1>&2
exit 1
fi
if [[ -f ./internal/engine/psiphon-config.json.age &&
-f ./internal/engine/psiphon-config.key ]]; then
OONI_PSIPHON_TAGS=ooni_psiphon_config
else
OONI_PSIPHON_TAGS=""
fi
PRODUCT=$(basename $PACKAGE)
function cleanup() {
# Undoes the effects of go-getting golang.org/x/mobile/cmd/gomobile
go mod tidy
}
trap cleanup EXIT
set -x
go install golang.org/x/mobile/cmd/gomobile@latest
$(go env GOPATH)/bin/gomobile init
# Adding gomobile to go.mod as documented by golang.org/wiki/Mobile
go get -d golang.org/x/mobile/cmd/gomobile
$(go env GOPATH)/bin/gomobile bind -target $TARGET \
-o ./MOBILE/$TARGET/$PRODUCT.$EXT -tags="$OONI_PSIPHON_TAGS" \
-ldflags '-s -w' ${GOLANG_EXTRA_FLAGS:-} $PACKAGE
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail
EXPECTED_XCODE_VERSION=${EXPECTED_XCODE_VERSION:-13.4.1}
printf "checking for xcodebuild... "
command -v xcodebuild || {
echo "not found"
exit 1
}
printf "checking for Xcode version... "
__XCODEVERSION_REAL=$(xcodebuild -version | grep ^Xcode | awk '{print $2}')
echo $__XCODEVERSION_REAL
[[ "$EXPECTED_XCODE_VERSION" = "$__XCODEVERSION_REAL" ]] || {
echo "fatal: Xcode version must be $EXPECTED_XCODE_VERSION instead of $__XCODEVERSION_REAL"
exit 1
}
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
set -euo pipefail
__version=$(date -u +%Y.%m.%d-%H%M%S)
__release=$(git describe --tags || echo '0.0.0-dev')
cat ./MOBILE/ios/template.podspec | sed -e "s/@VERSION@/$__version/g" \
-e "s/@RELEASE@/$__release/g" >./MOBILE/ios/oonimkall.podspec
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
set -euxo pipefail
(
cd ./MOBILE/ios
rm -rf oonimkall.xcframework.zip
zip -yr oonimkall.xcframework.zip oonimkall.xcframework
)