Windows: prevent //src:package-bazel* hanging

src/package-bazel.sh now creates a temp directory
and uses that as its root for all output.

Background: CI builds were recently hanging while
building //src:package-zip_jdk_minimal.

The target is a genrule executing a shell script
that runs `unzip` (among others). The build was
hanging at this `unzip` step. Using Process
Explorer I found the stdout and stderr of this
process and found out the process was waiting for
user input: asking if it could overwrite some
file under `<execroot>/recompress`.

@meisterT and I theorize that maybe Bazel built
another of the //src:package-zip<SUFFIX> targets
that already created the file in question. Actions
on Windows run with "standalone" spawn strategy,
meaning all actions run in the same execroot
without isolation, so actions see the inputs and
outputs of other actions, which is what we assume
happened here.

Change-Id: Ieeec5aa3c2f4a7619d5d7fa7f74142cd2e04c3f0

Closes #9441.

Change-Id: Ieeec5aa3c2f4a7619d5d7fa7f74142cd2e04c3f0
PiperOrigin-RevId: 271343526
diff --git a/src/package-bazel.sh b/src/package-bazel.sh
index a5e5e84..f1c3acc 100755
--- a/src/package-bazel.sh
+++ b/src/package-bazel.sh
@@ -34,21 +34,24 @@
 fi
 
 TMP_DIR=${TMPDIR:-/tmp}
-PACKAGE_DIR="$(mktemp -d ${TMP_DIR%%/}/bazel.XXXXXXXX)"
+ROOT="$(mktemp -d ${TMP_DIR%%/}/bazel.XXXXXXXX)"
+RECOMP="$ROOT/recomp"
+PACKAGE_DIR="$ROOT/pkg"
+DEPLOY_UNCOMP="$ROOT/deploy-uncompressed.jar"
 mkdir -p "${PACKAGE_DIR}"
-trap "rm -fr ${PACKAGE_DIR}" EXIT
+trap "rm -fr ${ROOT}" EXIT
 
 cp $* ${PACKAGE_DIR}
 
 if [[ $DEV_BUILD -eq 0 ]]; then
   # Unpack the deploy jar for postprocessing and for "re-compressing" to save
   # ~10% of final binary size.
-  unzip -q -d recompress ${DEPLOY_JAR}
-  cd recompress
+  unzip -q -d $RECOMP ${DEPLOY_JAR}
+  cd $RECOMP
 
   # Zero out timestamps and sort the entries to ensure determinism.
   find . -type f -print0 | xargs -0 touch -t 198001010000.00
-  find . -type f | sort | zip -q0DX@ ../deploy-uncompressed.jar
+  find . -type f | sort | zip -q0DX@ "$DEPLOY_UNCOMP"
 
   # While we're in the deploy jar, grab the label and pack it into the final
   # packaged distribution zip where it can be used to quickly determine version
@@ -58,9 +61,9 @@
         || echo -n 'no_version')"
   echo -n "${bazel_label:-no_version}" > "${PACKAGE_DIR}/build-label.txt"
 
-  cd ..
+  cd $WORKDIR
 
-  DEPLOY_JAR="deploy-uncompressed.jar"
+  DEPLOY_JAR="$DEPLOY_UNCOMP"
 fi
 
 # The server jar needs to be the first binary we extract. This is how the Bazel