From b90c37d4a08ad957df55bfde6dad94d2d59f3142 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 5 Dec 2022 22:15:48 -0800 Subject: [PATCH] ci: Update gen_install and gen_template_lib --- ci/release/gen_install.sh | 2 ++ ci/release/gen_template_lib.sh | 2 ++ ci/release/template/scripts/lib.sh | 56 ++++++++++++++++++++++++------ ci/sub | 2 +- install.sh | 56 ++++++++++++++++++++++++------ 5 files changed, 97 insertions(+), 21 deletions(-) diff --git a/ci/release/gen_install.sh b/ci/release/gen_install.sh index 082bdcc52..bd541106e 100755 --- a/ci/release/gen_install.sh +++ b/ci/release/gen_install.sh @@ -14,6 +14,7 @@ set -eu # install.sh was bundled together from # # - ./ci/sub/lib/rand.sh +# - ./ci/sub/lib/temp.sh # - ./ci/sub/lib/log.sh # - ./ci/sub/lib/flag.sh # - ./ci/sub/lib/release.sh @@ -30,6 +31,7 @@ EOF # script. sh_c cat \ ./ci/sub/lib/rand.sh \ + ./ci/sub/lib/temp.sh \ ./ci/sub/lib/log.sh \ ./ci/sub/lib/flag.sh \ ./ci/sub/lib/release.sh \ diff --git a/ci/release/gen_template_lib.sh b/ci/release/gen_template_lib.sh index 27e63ac9e..01eced365 100755 --- a/ci/release/gen_template_lib.sh +++ b/ci/release/gen_template_lib.sh @@ -13,6 +13,7 @@ sh_c cat >./ci/release/template/scripts/lib.sh <\>./ci/release/template/scripts/lib.sh diff --git a/ci/release/template/scripts/lib.sh b/ci/release/template/scripts/lib.sh index 9c3b9913b..759a95202 100644 --- a/ci/release/template/scripts/lib.sh +++ b/ci/release/template/scripts/lib.sh @@ -6,6 +6,7 @@ # lib.sh was bundled together from # # - ./ci/sub/lib/rand.sh +# - ./ci/sub/lib/temp.sh # - ./ci/sub/lib/log.sh # - ./ci/sub/lib/release.sh # @@ -22,7 +23,7 @@ pick() { seed="$1" shift - seed_file="$(mktemp)" + seed_file="$(mktempd)/pickseed" # We add 32 more bytes to the seed file for sufficient entropy. Otherwise both Cygwin's # and MinGW's sort for example complains about the lack of entropy on stderr and writes @@ -40,6 +41,44 @@ pick() { | head -n1 } #!/bin/sh +if [ "${LIB_TEMP-}" ]; then + return 0 +fi +LIB_TEMP=1 + +ensure_tmpdir() { + if [ -n "${_TMPDIR-}" ]; then + return + fi + + _TMPDIR=$(mktemp -d) + export _TMPDIR + trap temp_exittrap EXIT +} + +temp_exittrap() { + if [ -n "${_TMPDIR-}" ]; then + rm -r "$_TMPDIR" + fi +} + +temppath() { + ensure_tmpdir + while true; do + temppath=$_TMPDIR/$("$out" 2>&1 - code="$?" - set -e + out="$(mktempd)/hideout" + capcode "$@" >"$out" 2>&1 if [ "$code" -eq 0 ]; then return fi @@ -272,7 +308,7 @@ echo_dur() { sponge() { dst="$1" - tmp="$(mktemp)" + tmp="$(mktempd)/sponge" cat > "$tmp" cat "$tmp" > "$dst" } @@ -324,7 +360,7 @@ ensure_goos() { ensure_os case "$OS" in macos) export GOOS=darwin;; - *) export GOOS=$1;; + *) export GOOS=$OS;; esac } @@ -334,7 +370,7 @@ ensure_goarch() { fi ensure_arch case "$ARCH" in - *) export GOARCH=$1;; + *) export GOARCH=$ARCH;; esac } diff --git a/ci/sub b/ci/sub index 153c562ec..ce1b7341c 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 153c562ec591b7d32e265fabbd426a6b69e4fde8 +Subproject commit ce1b7341c09338260fe2799aa5e1400f369f8d7e diff --git a/install.sh b/install.sh index 3faf81ce0..8e4215cd2 100755 --- a/install.sh +++ b/install.sh @@ -7,6 +7,7 @@ set -eu # install.sh was bundled together from # # - ./ci/sub/lib/rand.sh +# - ./ci/sub/lib/temp.sh # - ./ci/sub/lib/log.sh # - ./ci/sub/lib/flag.sh # - ./ci/sub/lib/release.sh @@ -27,7 +28,7 @@ pick() { seed="$1" shift - seed_file="$(mktemp)" + seed_file="$(mktempd)/pickseed" # We add 32 more bytes to the seed file for sufficient entropy. Otherwise both Cygwin's # and MinGW's sort for example complains about the lack of entropy on stderr and writes @@ -45,6 +46,44 @@ pick() { | head -n1 } #!/bin/sh +if [ "${LIB_TEMP-}" ]; then + return 0 +fi +LIB_TEMP=1 + +ensure_tmpdir() { + if [ -n "${_TMPDIR-}" ]; then + return + fi + + _TMPDIR=$(mktemp -d) + export _TMPDIR + trap temp_exittrap EXIT +} + +temp_exittrap() { + if [ -n "${_TMPDIR-}" ]; then + rm -r "$_TMPDIR" + fi +} + +temppath() { + ensure_tmpdir + while true; do + temppath=$_TMPDIR/$("$out" 2>&1 - code="$?" - set -e + out="$(mktempd)/hideout" + capcode "$@" >"$out" 2>&1 if [ "$code" -eq 0 ]; then return fi @@ -277,7 +313,7 @@ echo_dur() { sponge() { dst="$1" - tmp="$(mktemp)" + tmp="$(mktempd)/sponge" cat > "$tmp" cat "$tmp" > "$dst" } @@ -460,7 +496,7 @@ ensure_goos() { ensure_os case "$OS" in macos) export GOOS=darwin;; - *) export GOOS=$1;; + *) export GOOS=$OS;; esac } @@ -470,7 +506,7 @@ ensure_goarch() { fi ensure_arch case "$ARCH" in - *) export GOARCH=$1;; + *) export GOARCH=$ARCH;; esac }