blob: 9c29a311ec8b51e960d5046f0491c4b0b636fb14 [file] [log] [blame]
Jeff Gastonc58f3152021-04-09 12:45:53 -04001#!/bin/bash
2set -e
3
4echo "Starting $0 at $(date)"
5
6cd "$(dirname $0)"
7
8CHECKOUT_DIR="$(cd ../../.. && pwd)"
9OUT_DIR="$CHECKOUT_DIR/out"
10if [ "$DIST_DIR" == "" ]; then
11 DIST_DIR="$OUT_DIR/dist"
12fi
Jeff Gastone18bf2a2021-05-11 12:31:42 -040013# move OUT_DIR and DIST_DIR into subdirectories so that if diagnose-build-failure deletes them, it doesn't interfere with any files generated by buildbot code
14export OUT_DIR="$OUT_DIR/incremental"
15mkdir -p "$OUT_DIR"
16export DIST_DIR="$DIST_DIR/incremental"
17mkdir -p "$DIST_DIR"
Jeff Gastonc58f3152021-04-09 12:45:53 -040018
Jeff Gaston436e8d62021-09-24 11:44:09 -040019if echo "$BUILD_NUMBER" | grep "P" >/dev/null; then
20 PRESUBMIT=true
21else
22 PRESUBMIT=false
23fi
24
Jeff Gastonc58f3152021-04-09 12:45:53 -040025function hashOutDir() {
26 hashFile=out.hashes
27 echo "hashing out dir and saving into $DIST_DIR/$hashFile"
28 # We hash files in parallel for more performance (-P <number>)
29 # We limit the number of files hashed by any one process (-n <number>) to lower the risk of one
30 # process having to do much more work than the others.
31 # We do allow each process to hash multiple files (also -n <number>) to avoid spawning too many processes
32 # It would be nice to copy all files, but that takes a while
33 time (cd $OUT_DIR && find -type f | grep -v "$hashFile" | xargs --no-run-if-empty -P 32 -n 64 sha1sum > $DIST_DIR/$hashFile)
34 echo "done hashing out dir"
35}
36hashOutDir
37
Jeff Gaston05918862021-05-19 16:57:42 -040038# diagnostics to hopefully help us figure out b/188565660
39function zipKotlinMetadata() {
40 zipFile=kotlinMetadata.zip
41 echo "zipping kotlin metadata"
Jeff Gastonba5a22a2021-06-14 11:38:00 -040042 rm -f "$DIST_DIR/$zipFile"
Jeff Gaston0e056302021-07-16 15:19:41 -040043 (cd $OUT_DIR && find -name "*kotlin_module" | xargs zip -q -u "$DIST_DIR/$zipFile")
Jeff Gaston05918862021-05-19 16:57:42 -040044 echo done zipping kotlin metadata
45}
46
Jeff Gaston436e8d62021-09-24 11:44:09 -040047# If we encounter a failure in postsubmit, we try a few things to determine if the failure is
48# reproducible
49DIAGNOSE_ARG=""
50if [ "$PRESUBMIT" == "false" ]; then
51 DIAGNOSE_ARG="--diagnose"
52fi
53
Jeff Gastonc58f3152021-04-09 12:45:53 -040054# Run Gradle
Jeff Gaston07d7d692021-06-14 10:50:04 -040055EXIT_VALUE=0
Jeff Gaston436e8d62021-09-24 11:44:09 -040056if impl/build.sh $DIAGNOSE_ARG buildOnServer checkExternalLicenses listTaskOutputs validateAllProperties \
Jeff Gaston05918862021-05-19 16:57:42 -040057 --profile "$@"; then
58 echo build succeeded
Jeff Gaston07d7d692021-06-14 10:50:04 -040059 EXIT_VALUE=0
Jeff Gaston05918862021-05-19 16:57:42 -040060else
61 zipKotlinMetadata
62 echo build failed
Jeff Gaston436e8d62021-09-24 11:44:09 -040063 if [ "$PRESUBMIT" == "true" ]; then
Jeff Gaston52437492021-09-08 15:29:41 -040064 echo androidx_incremental ignoring presubmit failure
65 else
66 EXIT_VALUE=1
67 fi
Jeff Gaston05918862021-05-19 16:57:42 -040068fi
Jeff Gastonc58f3152021-04-09 12:45:53 -040069
70# Parse performance profile reports (generated with the --profile option above) and re-export the metrics in an easily machine-readable format for tracking
71impl/parse_profile_htmls.sh
72
73echo "Completing $0 at $(date)"
Jeff Gaston07d7d692021-06-14 10:50:04 -040074
75exit "$EXIT_VALUE"