Jeff Gaston | 8aa46b3 | 2018-09-27 16:14:14 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -e |
Jeff Gaston | 8aa46b3 | 2018-09-27 16:14:14 -0400 | [diff] [blame] | 3 | |
| 4 | echo "IF THIS SCRIPT FIXES YOUR BUILD; OPEN A BUG." |
Jeff Gaston | cc0993d | 2019-04-02 18:02:44 -0400 | [diff] [blame] | 5 | echo "In nearly all cases, it should not be necessary to run a clean build." |
| 6 | echo |
| 7 | echo "You may be more interested in running:" |
| 8 | echo |
| 9 | echo " ./development/diagnose-build-failure/diagnose-build-failure.sh $*" |
| 10 | echo |
| 11 | echo "which attempts to diagnose more details about build failures" |
Jeff Gaston | 8aa46b3 | 2018-09-27 16:14:14 -0400 | [diff] [blame] | 12 | # one case where it is convenient to have a clean build is for double-checking that a build failure isn't due to an incremental build failure |
| 13 | # another case where it is convenient to have a clean build is for performance testing |
| 14 | # another case where it is convenient to have a clean build is when you're modifying the build and may have introduced some errors but haven't shared your changes yet (at which point you should have fixed the errors) |
| 15 | echo |
| 16 | |
Jeff Gaston | c104704 | 2019-07-17 16:48:16 -0400 | [diff] [blame] | 17 | DO_PROMPT=true |
| 18 | if [ "$1" == "-y" ]; then |
| 19 | DO_PROMPT=false |
| 20 | shift |
| 21 | fi |
| 22 | |
Jeff Gaston | 8aa46b3 | 2018-09-27 16:14:14 -0400 | [diff] [blame] | 23 | goals="$@" |
| 24 | |
| 25 | function usage() { |
Jeff Gaston | c104704 | 2019-07-17 16:48:16 -0400 | [diff] [blame] | 26 | echo |
| 27 | echo "Usage: $0 [-y] <tasks>" |
Jeff Gaston | 8aa46b3 | 2018-09-27 16:14:14 -0400 | [diff] [blame] | 28 | echo "Runs a clean build of <tasks>" |
Jeff Gaston | adffce4 | 2019-04-02 15:19:40 -0400 | [diff] [blame] | 29 | echo |
Jeff Gaston | c104704 | 2019-07-17 16:48:16 -0400 | [diff] [blame] | 30 | echo |
Jeff Gaston | adffce4 | 2019-04-02 15:19:40 -0400 | [diff] [blame] | 31 | echo "For example:" |
| 32 | echo |
| 33 | echo " $0 assembleDebug # or any other arguments you would normally give to ./gradlew" |
Jeff Gaston | c104704 | 2019-07-17 16:48:16 -0400 | [diff] [blame] | 34 | echo |
| 35 | echo |
| 36 | echo "-y" |
| 37 | echo " Don't prompt the user to confirm that they want to run a clean build" |
Jeff Gaston | 8aa46b3 | 2018-09-27 16:14:14 -0400 | [diff] [blame] | 38 | exit 1 |
| 39 | } |
| 40 | |
| 41 | if [ "$goals" == "" ]; then |
| 42 | usage |
| 43 | fi |
| 44 | |
Jeff Gaston | 3230825 | 2019-07-10 13:28:54 -0400 | [diff] [blame] | 45 | if [ ! -e "./gradlew" ]; then |
| 46 | echo "Error; ./gradlew does not exist. Must cd to a dir containing a ./gradlew first" |
| 47 | # so that this script knows which gradlew to use (in frameworks/support or frameworks/support/ui) |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
Jeff Gaston | cc0993d | 2019-04-02 18:02:44 -0400 | [diff] [blame] | 51 | function confirm() { |
| 52 | # Confirm whether the user wants to run this script instead of diagnose-build-failure.sh |
| 53 | # Recall that we already mentioned the existence of diagnose-build-failure.sh above |
| 54 | echo |
| 55 | echo "Press <Enter> to run a clean build or Ctrl-C to cancel" |
Jeff Gaston | c104704 | 2019-07-17 16:48:16 -0400 | [diff] [blame] | 56 | if [ "$DO_PROMPT" == "true" ]; then |
| 57 | read response |
| 58 | fi |
Jeff Gaston | cc0993d | 2019-04-02 18:02:44 -0400 | [diff] [blame] | 59 | } |
| 60 | confirm |
| 61 | |
Jeff Gaston | 561cac2 | 2019-11-27 17:57:20 -0500 | [diff] [blame] | 62 | scriptDir="$(cd $(dirname $0) && pwd)" |
| 63 | checkoutDir="$(cd $scriptDir/../.. && pwd)" |
| 64 | export OUT_DIR="$checkoutDir/out" |
Jeff Gaston | 8aa46b3 | 2018-09-27 16:14:14 -0400 | [diff] [blame] | 65 | function removeCaches() { |
Jeff Gaston | cc0993d | 2019-04-02 18:02:44 -0400 | [diff] [blame] | 66 | echo removing caches |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 67 | rm -rf .gradle |
George Mount | 34ddc31 | 2018-10-24 13:53:18 -0700 | [diff] [blame] | 68 | rm -rf buildSrc/.gradle |
Jeff Gaston | 8aa46b3 | 2018-09-27 16:14:14 -0400 | [diff] [blame] | 69 | rm -f local.properties |
Jeff Gaston | 561cac2 | 2019-11-27 17:57:20 -0500 | [diff] [blame] | 70 | rm -rf $OUT_DIR |
Jeff Gaston | 8aa46b3 | 2018-09-27 16:14:14 -0400 | [diff] [blame] | 71 | } |
| 72 | removeCaches |
| 73 | |
| 74 | echo running build |
Jeff Gaston | 561cac2 | 2019-11-27 17:57:20 -0500 | [diff] [blame] | 75 | ./gradlew --no-daemon $goals |