| Jeff Gaston | c58f315 | 2021-04-09 12:45:53 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | echo "Starting $0 at $(date)" |
| 5 | |
| 6 | cd "$(dirname $0)" |
| 7 | |
| 8 | CHECKOUT_DIR="$(cd ../../.. && pwd)" |
| 9 | OUT_DIR="$CHECKOUT_DIR/out" |
| 10 | if [ "$DIST_DIR" == "" ]; then |
| 11 | DIST_DIR="$OUT_DIR/dist" |
| 12 | fi |
| Jeff Gaston | c095a4b | 2022-01-14 12:25:49 -0500 | [diff] [blame] | 13 | if [ "$MANIFEST" == "" ]; then |
| 14 | export MANIFEST="$DIST_DIR/manifest_${BUILD_NUMBER}.xml" |
| 15 | fi |
| Jeff Gaston | e18bf2a | 2021-05-11 12:31:42 -0400 | [diff] [blame] | 16 | # 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 |
| 17 | export OUT_DIR="$OUT_DIR/incremental" |
| 18 | mkdir -p "$OUT_DIR" |
| 19 | export DIST_DIR="$DIST_DIR/incremental" |
| 20 | mkdir -p "$DIST_DIR" |
| Jeff Gaston | c58f315 | 2021-04-09 12:45:53 -0400 | [diff] [blame] | 21 | |
| Jeff Gaston | 436e8d6 | 2021-09-24 11:44:09 -0400 | [diff] [blame] | 22 | if echo "$BUILD_NUMBER" | grep "P" >/dev/null; then |
| 23 | PRESUBMIT=true |
| 24 | else |
| 25 | PRESUBMIT=false |
| 26 | fi |
| 27 | |
| Jeff Gaston | 12827d7 | 2022-04-26 17:49:20 -0400 | [diff] [blame] | 28 | export USE_ANDROIDX_REMOTE_BUILD_CACHE=gcp |
| 29 | |
| Jeff Gaston | f41aff5 | 2022-03-10 11:25:53 -0500 | [diff] [blame] | 30 | # hash the files in the out dir in case we want to confirm which files changed during the build |
| Jeff Gaston | c58f315 | 2021-04-09 12:45:53 -0400 | [diff] [blame] | 31 | function hashOutDir() { |
| 32 | hashFile=out.hashes |
| 33 | echo "hashing out dir and saving into $DIST_DIR/$hashFile" |
| 34 | # We hash files in parallel for more performance (-P <number>) |
| 35 | # We limit the number of files hashed by any one process (-n <number>) to lower the risk of one |
| 36 | # process having to do much more work than the others. |
| 37 | # We do allow each process to hash multiple files (also -n <number>) to avoid spawning too many processes |
| 38 | # It would be nice to copy all files, but that takes a while |
| Jeff Gaston | f41aff5 | 2022-03-10 11:25:53 -0500 | [diff] [blame] | 39 | (cd $OUT_DIR && find -type f | grep -v "$hashFile" | xargs --no-run-if-empty -P 32 -n 64 sha1sum > $DIST_DIR/$hashFile) |
| Jeff Gaston | c58f315 | 2021-04-09 12:45:53 -0400 | [diff] [blame] | 40 | echo "done hashing out dir" |
| 41 | } |
| 42 | hashOutDir |
| 43 | |
| Jeff Gaston | 436e8d6 | 2021-09-24 11:44:09 -0400 | [diff] [blame] | 44 | # If we encounter a failure in postsubmit, we try a few things to determine if the failure is |
| 45 | # reproducible |
| 46 | DIAGNOSE_ARG="" |
| 47 | if [ "$PRESUBMIT" == "false" ]; then |
| 48 | DIAGNOSE_ARG="--diagnose" |
| 49 | fi |
| 50 | |
| Jeff Gaston | 07d7d69 | 2021-06-14 10:50:04 -0400 | [diff] [blame] | 51 | EXIT_VALUE=0 |
| Alan Viverette | b358757 | 2022-04-14 15:27:59 +0000 | [diff] [blame] | 52 | |
| 53 | # Validate translation exports, if present |
| 54 | if ! impl/check_translations.sh; then |
| 55 | echo check_translations failed |
| Jeff Gaston | 8dc5c80 | 2021-10-20 17:12:01 -0400 | [diff] [blame] | 56 | EXIT_VALUE=1 |
| Alan Viverette | b358757 | 2022-04-14 15:27:59 +0000 | [diff] [blame] | 57 | else |
| 58 | # Run Gradle |
| 59 | if impl/build.sh $DIAGNOSE_ARG buildOnServer checkExternalLicenses listTaskOutputs validateProperties \ |
| 60 | --profile "$@"; then |
| 61 | echo build succeeded |
| 62 | EXIT_VALUE=0 |
| 63 | else |
| 64 | echo build failed |
| 65 | EXIT_VALUE=1 |
| 66 | fi |
| 67 | |
| 68 | # Parse performance profile reports (generated with the --profile option above) and re-export the metrics in an easily machine-readable format for tracking |
| 69 | impl/parse_profile_htmls.sh |
| Jeff Gaston | 0591886 | 2021-05-19 16:57:42 -0400 | [diff] [blame] | 70 | fi |
| Jeff Gaston | c58f315 | 2021-04-09 12:45:53 -0400 | [diff] [blame] | 71 | |
| Alan Viverette | b358757 | 2022-04-14 15:27:59 +0000 | [diff] [blame] | 72 | echo "Completing $0 at $(date) with exit value $EXIT_VALUE" |
| Jeff Gaston | 07d7d69 | 2021-06-14 10:50:04 -0400 | [diff] [blame] | 73 | |
| 74 | exit "$EXIT_VALUE" |