[go: nahoru, domu]

blob: 0c0a486b94a9f64179d8561c237c8e5da3163ac6 [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 Gastonc095a4b2022-01-14 12:25:49 -050013if [ "$MANIFEST" == "" ]; then
14 export MANIFEST="$DIST_DIR/manifest_${BUILD_NUMBER}.xml"
15fi
Jeff Gastone18bf2a2021-05-11 12:31:42 -040016# 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
17export OUT_DIR="$OUT_DIR/incremental"
18mkdir -p "$OUT_DIR"
19export DIST_DIR="$DIST_DIR/incremental"
20mkdir -p "$DIST_DIR"
Jeff Gastonc58f3152021-04-09 12:45:53 -040021
Jeff Gaston436e8d62021-09-24 11:44:09 -040022if echo "$BUILD_NUMBER" | grep "P" >/dev/null; then
23 PRESUBMIT=true
24else
25 PRESUBMIT=false
26fi
27
Jeff Gaston12827d72022-04-26 17:49:20 -040028export USE_ANDROIDX_REMOTE_BUILD_CACHE=gcp
29
Jeff Gastonf41aff52022-03-10 11:25:53 -050030# hash the files in the out dir in case we want to confirm which files changed during the build
Jeff Gastonc58f3152021-04-09 12:45:53 -040031function 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 Gaston737977a2023-04-04 14:40:27 +000039 (cd $OUT_DIR && find -type f | grep -v "$hashFile" | xargs --no-run-if-empty -P 32 -n 64 sha1sum > $DIST_DIR/$hashFile)
Jeff Gastonc58f3152021-04-09 12:45:53 -040040 echo "done hashing out dir"
41}
Jeff Gaston737977a2023-04-04 14:40:27 +000042# disable temporarily b/276812697
43# hashOutDir
Jeff Gastonc58f3152021-04-09 12:45:53 -040044
Jeff Gaston436e8d62021-09-24 11:44:09 -040045# If we encounter a failure in postsubmit, we try a few things to determine if the failure is
46# reproducible
47DIAGNOSE_ARG=""
48if [ "$PRESUBMIT" == "false" ]; then
Jeff Gaston41210cd2023-07-06 16:21:51 -040049 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 Gaston436e8d62021-09-24 11:44:09 -040056fi
57
Jeff Gaston07d7d692021-06-14 10:50:04 -040058EXIT_VALUE=0
Alan Viveretteb3587572022-04-14 15:27:59 +000059
60# Validate translation exports, if present
61if ! impl/check_translations.sh; then
62 echo check_translations failed
Jeff Gaston8dc5c802021-10-20 17:12:01 -040063 EXIT_VALUE=1
Alan Viveretteb3587572022-04-14 15:27:59 +000064else
65 # Run Gradle
Jeff Gaston2fca1fe2023-07-20 16:03:22 -040066 # TODO: when b/278730831 ( https://youtrack.jetbrains.com/issue/KT-58547 ) is resolved, remove "-Pkotlin.incremental=false"
Jeff Gaston7f1f0582023-07-31 10:07:39 -040067 if impl/build.sh $DIAGNOSE_ARG buildOnServer checkExternalLicenses listTaskOutputs exportSboms \
Jeff Gaston2fca1fe2023-07-20 16:03:22 -040068 --profile \
69 -Pkotlin.incremental=false \
70 "$@"; then
Alan Viveretteb3587572022-04-14 15:27:59 +000071 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 Gaston5248e302022-11-18 15:14:21 -050079 impl/parse_profile_data.sh
Jeff Gaston05918862021-05-19 16:57:42 -040080fi
Jeff Gastonc58f3152021-04-09 12:45:53 -040081
Alan Viveretteb3587572022-04-14 15:27:59 +000082echo "Completing $0 at $(date) with exit value $EXIT_VALUE"
Jeff Gaston07d7d692021-06-14 10:50:04 -040083
84exit "$EXIT_VALUE"