From fa9b1f30248f7d2e63fb3dcdcb78a2a1db8e45e5 Mon Sep 17 00:00:00 2001 From: kshyanashree <109167932+kshyanashree@users.noreply.github.com> Date: Wed, 2 Nov 2022 14:40:12 -0700 Subject: [PATCH] Fix race condition in package-bazel.sh (#16642) `bazel build -c //src:bazel.exe //src:bazel_nojdk.exe` sometimes output corrupted binaries on Windows. The reason is when we are executing the genrule for packaging the bazel zip files, we are writing a "file.list" file into the execroot, however there is no sandbox on Windows. So two actions are actually sharing the same path for the "file.list", this PR fixes the issue by writing the "file.list" file under the tmp dir. Fixes https://github.com/bazelbuild/bazel/issues/16613 Closes #16614. PiperOrigin-RevId: 485578533 Change-Id: I74b69e58919a463d5cc40abaa6ae4ca36251cdac Co-authored-by: Yun Peng --- src/package-bazel.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/package-bazel.sh b/src/package-bazel.sh index c7fc3e3e75eed5..c69ac942093554 100755 --- a/src/package-bazel.sh +++ b/src/package-bazel.sh @@ -37,6 +37,7 @@ ROOT="$(mktemp -d ${TMP_DIR%%/}/bazel.XXXXXXXX)" RECOMP="$ROOT/recomp" PACKAGE_DIR="$ROOT/pkg" DEPLOY_UNCOMP="$ROOT/deploy-uncompressed.jar" +FILE_LIST="$ROOT/file.list" mkdir -p "${PACKAGE_DIR}" trap "rm -fr ${ROOT}" EXIT @@ -101,14 +102,14 @@ fi find . -type f | sort # And install_base_key must be last. echo install_base_key -) > files.list +) > $FILE_LIST # Move these after the 'find' above. cp $DEPLOY_JAR $PACKAGE_DIR/A-server.jar cp $INSTALL_BASE_KEY $PACKAGE_DIR/install_base_key # Zero timestamps. -(cd $PACKAGE_DIR; xargs touch -t 198001010000.00) < files.list +(cd $PACKAGE_DIR; xargs touch -t 198001010000.00) < $FILE_LIST if [[ "$DEV_BUILD" -eq 1 ]]; then # Create output zip with lowest compression, but fast. @@ -117,6 +118,6 @@ else # Create output zip with highest compression, but slow. ZIP_ARGS="-q9DX@" fi -(cd $PACKAGE_DIR; zip $ZIP_ARGS $WORKDIR/$OUT) < files.list +(cd $PACKAGE_DIR; zip $ZIP_ARGS $WORKDIR/$OUT) < $FILE_LIST