blob: 06720978c896a95849aa7c36e57eb97dd8e6af00 [file] [log] [blame]
Jeff Gaston8aa46b32018-09-27 16:14:14 -04001#!/bin/bash
2set -e
Jeff Gaston8aa46b32018-09-27 16:14:14 -04003
4echo "IF THIS SCRIPT FIXES YOUR BUILD; OPEN A BUG."
Jeff Gastoncc0993d2019-04-02 18:02:44 -04005echo "In nearly all cases, it should not be necessary to run a clean build."
6echo
7echo "You may be more interested in running:"
8echo
9echo " ./development/diagnose-build-failure/diagnose-build-failure.sh $*"
10echo
11echo "which attempts to diagnose more details about build failures"
Jeff Gaston8aa46b32018-09-27 16:14:14 -040012# 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)
15echo
16
Jeff Gastonc1047042019-07-17 16:48:16 -040017DO_PROMPT=true
18if [ "$1" == "-y" ]; then
19DO_PROMPT=false
20shift
21fi
22
Jeff Gaston8aa46b32018-09-27 16:14:14 -040023goals="$@"
24
25function usage() {
Jeff Gastonc1047042019-07-17 16:48:16 -040026echo
27echo "Usage: $0 [-y] <tasks>"
Jeff Gaston8aa46b32018-09-27 16:14:14 -040028echo "Runs a clean build of <tasks>"
Jeff Gastonadffce42019-04-02 15:19:40 -040029echo
Jeff Gastonc1047042019-07-17 16:48:16 -040030echo
Jeff Gastonadffce42019-04-02 15:19:40 -040031echo "For example:"
32echo
33echo " $0 assembleDebug # or any other arguments you would normally give to ./gradlew"
Jeff Gastonc1047042019-07-17 16:48:16 -040034echo
35echo
36echo "-y"
37echo " Don't prompt the user to confirm that they want to run a clean build"
Jeff Gaston8aa46b32018-09-27 16:14:14 -040038exit 1
39}
40
41if [ "$goals" == "" ]; then
42usage
43fi
44
Jeff Gaston32308252019-07-10 13:28:54 -040045if [ ! -e "./gradlew" ]; then
46echo "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)
48exit 1
49fi
50
Jeff Gastoncc0993d2019-04-02 18:02:44 -040051function 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
54echo
55echo "Press <Enter> to run a clean build or Ctrl-C to cancel"
Jeff Gastonc1047042019-07-17 16:48:16 -040056if [ "$DO_PROMPT" == "true" ]; then
57read response
58fi
Jeff Gastoncc0993d2019-04-02 18:02:44 -040059}
60confirm
61
Jeff Gaston8aa46b32018-09-27 16:14:14 -040062export OUT_DIR=../../out
63function removeCaches() {
Jeff Gastoncc0993d2019-04-02 18:02:44 -040064echo removing caches
Jeff Gaston79a43f22019-04-09 16:19:12 -040065rm -rf .gradle
George Mount34ddc312018-10-24 13:53:18 -070066rm -rf buildSrc/.gradle
Jeff Gaston8aa46b32018-09-27 16:14:14 -040067rm -f local.properties
George Mount34ddc312018-10-24 13:53:18 -070068rm -rf ../../out
Jeff Gaston8aa46b32018-09-27 16:14:14 -040069}
70removeCaches
71
72echo running build
73GRADLE_USER_HOME=../../out ./gradlew --no-daemon $goals