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 | 737977a | 2023-04-04 14:40:27 +0000 | [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 | } |
Jeff Gaston | 737977a | 2023-04-04 14:40:27 +0000 | [diff] [blame] | 42 | # disable temporarily b/276812697 |
| 43 | # hashOutDir |
Jeff Gaston | c58f315 | 2021-04-09 12:45:53 -0400 | [diff] [blame] | 44 | |
Jeff Gaston | 436e8d6 | 2021-09-24 11:44:09 -0400 | [diff] [blame] | 45 | # If we encounter a failure in postsubmit, we try a few things to determine if the failure is |
| 46 | # reproducible |
| 47 | DIAGNOSE_ARG="" |
| 48 | if [ "$PRESUBMIT" == "false" ]; then |
Jeff Gaston | 41210cd | 2023-07-06 16:21:51 -0400 | [diff] [blame] | 49 | if [ "$BUILD_NUMBER" == "" ]; then |
| 50 | # This is a local build so we can diagnose without a timeout. The user can cancel it when they're satisfied. |
| 51 | DIAGNOSE_ARG="--diagnose" |
| 52 | else |
| 53 | # This is running on the build server so we should not spend long trying to diagnose it |
| 54 | DIAGNOSE_ARG="--diagnose --diagnose-timeout 600" |
| 55 | fi |
Jeff Gaston | 436e8d6 | 2021-09-24 11:44:09 -0400 | [diff] [blame] | 56 | fi |
| 57 | |
Jeff Gaston | 07d7d69 | 2021-06-14 10:50:04 -0400 | [diff] [blame] | 58 | EXIT_VALUE=0 |
Alan Viverette | b358757 | 2022-04-14 15:27:59 +0000 | [diff] [blame] | 59 | |
| 60 | # Validate translation exports, if present |
| 61 | if ! impl/check_translations.sh; then |
| 62 | echo check_translations failed |
Jeff Gaston | 8dc5c80 | 2021-10-20 17:12:01 -0400 | [diff] [blame] | 63 | EXIT_VALUE=1 |
Alan Viverette | b358757 | 2022-04-14 15:27:59 +0000 | [diff] [blame] | 64 | else |
| 65 | # Run Gradle |
Jeff Gaston | 2fca1fe | 2023-07-20 16:03:22 -0400 | [diff] [blame] | 66 | # TODO: when b/278730831 ( https://youtrack.jetbrains.com/issue/KT-58547 ) is resolved, remove "-Pkotlin.incremental=false" |
Jeff Gaston | 7f1f058 | 2023-07-31 10:07:39 -0400 | [diff] [blame] | 67 | if impl/build.sh $DIAGNOSE_ARG buildOnServer checkExternalLicenses listTaskOutputs exportSboms \ |
Jeff Gaston | 2fca1fe | 2023-07-20 16:03:22 -0400 | [diff] [blame] | 68 | --profile \ |
| 69 | -Pkotlin.incremental=false \ |
| 70 | "$@"; then |
Alan Viverette | b358757 | 2022-04-14 15:27:59 +0000 | [diff] [blame] | 71 | echo build succeeded |
| 72 | EXIT_VALUE=0 |
| 73 | else |
| 74 | echo build failed |
| 75 | EXIT_VALUE=1 |
| 76 | fi |
| 77 | |
| 78 | # Parse performance profile reports (generated with the --profile option above) and re-export the metrics in an easily machine-readable format for tracking |
Jeff Gaston | 5248e30 | 2022-11-18 15:14:21 -0500 | [diff] [blame] | 79 | impl/parse_profile_data.sh |
Jeff Gaston | 0591886 | 2021-05-19 16:57:42 -0400 | [diff] [blame] | 80 | fi |
Jeff Gaston | c58f315 | 2021-04-09 12:45:53 -0400 | [diff] [blame] | 81 | |
Alan Viverette | b358757 | 2022-04-14 15:27:59 +0000 | [diff] [blame] | 82 | echo "Completing $0 at $(date) with exit value $EXIT_VALUE" |
Jeff Gaston | 07d7d69 | 2021-06-14 10:50:04 -0400 | [diff] [blame] | 83 | |
| 84 | exit "$EXIT_VALUE" |