diagnose-build-failure support for OUT_DIR and DIST_DIR

in case we'd like to run it on the build servers

Bug: 187822154

Test:

  # run a build
  OUT_DIR=../../other-out DIST_DIR=../../other-dist ./gradlew --no-daemon createArchive; \

  # corrupt a file
  echo | tee ../../other-out/.gradle/caches/*/generated-gradle-jars/gradle-api-*.jar; \

  # run diagnose-build-failure
  OUT_DIR=../../other-out DIST_DIR=../../other-dist ./development/diagnose-build-failure/diagnose-build-failure.sh createArchive; \

  # see that neither ../../out nor ~/.gradle exists
  ls ../../out ~/.gradle

Change-Id: I92d629cb5163a4e5c710589e64be6b9d6500beda
diff --git a/development/diagnose-build-failure/diagnose-build-failure.sh b/development/diagnose-build-failure/diagnose-build-failure.sh
index 44b0cea..24be2ee 100755
--- a/development/diagnose-build-failure/diagnose-build-failure.sh
+++ b/development/diagnose-build-failure/diagnose-build-failure.sh
@@ -1,6 +1,5 @@
 #!/bin/bash
 set -e
-set -u
 
 scriptName="$(basename $0)"
 
@@ -65,13 +64,19 @@
   exit 1
 fi
 
+# resolve some paths
 scriptPath="$(cd $(dirname $0) && pwd)"
 vgrep="$scriptPath/impl/vgrep.sh"
 supportRoot="$(cd $scriptPath/../.. && pwd)"
 checkoutRoot="$(cd $supportRoot/../.. && pwd)"
 tempDir="$checkoutRoot/diagnose-build-failure/"
-if [ "${GRADLE_USER_HOME:-}" == "" ]; then
-  GRADLE_USER_HOME="$(cd ~ && pwd)/.gradle"
+if [ "$OUT_DIR" != "" ]; then
+  mkdir -p "$OUT_DIR"
+  OUT_DIR="$(cd $OUT_DIR && pwd)"
+fi
+if [ "$DIST_DIR" != "" ]; then
+  mkdir -p "$DIST_DIR"
+  DIST_DIR="$(cd $DIST_DIR && pwd)"
 fi
 COLOR_WHITE="\e[97m"
 COLOR_GREEN="\e[32m"
@@ -106,7 +111,8 @@
 function runBuild() {
   testCommand="$(getBuildCommand $*)"
   cd "$workingDir"
-  if eval $testCommand; then
+  echo Running $testCommand
+  if bash -c "$testCommand"; then
     echo -e "$COLOR_WHITE"
     echo
     echo '`'$testCommand'`' succeeded
@@ -122,7 +128,8 @@
 function backupState() {
   cd "$scriptPath"
   backupDir="$1"
-  ./impl/backup-state.sh "$backupDir" "$workingDir" "$2"
+  shift
+  ./impl/backup-state.sh "$backupDir" "$workingDir" "$@"
 }
 
 function restoreState() {