|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -exu -o pipefail |
| 4 | +cat /VERSION |
| 5 | + |
| 6 | +BASE_DIR="$(pwd)" |
| 7 | + |
| 8 | +# Build Cronet |
| 9 | + |
| 10 | +cd "$BASE_DIR/github/grpc-java/cronet" |
| 11 | +./cronet_deps.sh |
| 12 | +../gradlew --include-build .. build |
| 13 | + |
| 14 | + |
| 15 | +# Install gRPC and codegen for the Android examples |
| 16 | +# (a composite gradle build can't find protoc-gen-grpc-java) |
| 17 | + |
| 18 | +cd "$BASE_DIR/github/grpc-java" |
| 19 | + |
| 20 | +export GRADLE_OPTS=-Xmx512m |
| 21 | +export PROTOBUF_VERSION=3.5.1 |
| 22 | +export LDFLAGS=-L/tmp/protobuf/lib |
| 23 | +export CXXFLAGS=-I/tmp/protobuf/include |
| 24 | +export LD_LIBRARY_PATH=/tmp/protobuf/lib |
| 25 | +export OS_NAME=$(uname) |
| 26 | + |
| 27 | +# Proto deps |
| 28 | +buildscripts/make_dependencies.sh |
| 29 | +ln -s "/tmp/protobuf-${PROTOBUF_VERSION}/$(uname -s)-$(uname -p)" /tmp/protobuf |
| 30 | + |
| 31 | +./gradlew install |
| 32 | + |
| 33 | +cd ./examples/android/clientcache |
| 34 | +./gradlew build |
| 35 | +cd ../routeguide |
| 36 | +./gradlew build |
| 37 | +cd ../helloworld |
| 38 | +./gradlew build |
| 39 | + |
| 40 | + |
| 41 | +# Skip APK size and dex count comparisons for non-PR builds |
| 42 | + |
| 43 | +if [[ -z "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" ]]; then |
| 44 | + echo "Skipping APK size and dex count" |
| 45 | + exit 0 |
| 46 | +fi |
| 47 | + |
| 48 | + |
| 49 | +# Save a copy of set_github_status.py (it may differ from the base commit) |
| 50 | + |
| 51 | +SET_GITHUB_STATUS="$TMPDIR/set_github_status.py" |
| 52 | +cp "$BASE_DIR/github/grpc-java/buildscripts/set_github_status.py" "$SET_GITHUB_STATUS" |
| 53 | + |
| 54 | + |
| 55 | +# Collect APK size and dex count stats for the helloworld example |
| 56 | + |
| 57 | +read -r ignored new_dex_count < \ |
| 58 | + <("${ANDROID_HOME}/tools/bin/apkanalyzer" dex references app/build/outputs/apk/release/app-release-unsigned.apk) |
| 59 | + |
| 60 | +new_apk_size="$(stat --printf=%s app/build/outputs/apk/release/app-release-unsigned.apk)" |
| 61 | + |
| 62 | + |
| 63 | +# Get the APK size and dex count stats using the pull request base commit |
| 64 | + |
| 65 | +cd $BASE_DIR/github/grpc-java |
| 66 | +git checkout HEAD^ |
| 67 | +./gradlew install |
| 68 | +cd examples/android/helloworld/ |
| 69 | +./gradlew build |
| 70 | + |
| 71 | +read -r ignored old_dex_count < \ |
| 72 | + <("${ANDROID_HOME}/tools/bin/apkanalyzer" dex references app/build/outputs/apk/release/app-release-unsigned.apk) |
| 73 | + |
| 74 | +old_apk_size="$(stat --printf=%s app/build/outputs/apk/release/app-release-unsigned.apk)" |
| 75 | + |
| 76 | +dex_count_delta="$((new_dex_count-old_dex_count))" |
| 77 | + |
| 78 | +apk_size_delta="$((new_apk_size-old_apk_size))" |
| 79 | + |
| 80 | + |
| 81 | +# Update the statuses with the deltas |
| 82 | + |
| 83 | +gsutil cp gs://grpc-testing-secrets/github_credentials/oauth_token.txt ~/ |
| 84 | + |
| 85 | +"$SET_GITHUB_STATUS" \ |
| 86 | + --sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \ |
| 87 | + --state success \ |
| 88 | + --description "New DEX reference count: $(printf "%'d" "$new_dex_count") (delta: $(printf "%'d" "$dex_count_delta"))" \ |
| 89 | + --context android/dex_diff --oauth_file ~/oauth_token.txt |
| 90 | + |
| 91 | +"$SET_GITHUB_STATUS" \ |
| 92 | + --sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \ |
| 93 | + --state success \ |
| 94 | + --description "New APK size in bytes: $(printf "%'d" "$new_apk_size") (delta: $(printf "%'d" "$apk_size_delta"))" \ |
| 95 | + --context android/apk_diff --oauth_file ~/oauth_token.txt |
0 commit comments