summaryrefslogtreecommitdiffhomepage
path: root/tools/go_branch.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/go_branch.sh')
-rwxr-xr-xtools/go_branch.sh22
1 files changed, 14 insertions, 8 deletions
diff --git a/tools/go_branch.sh b/tools/go_branch.sh
index 026733d3c..392e40619 100755
--- a/tools/go_branch.sh
+++ b/tools/go_branch.sh
@@ -16,14 +16,25 @@
set -xeou pipefail
+# Remember our current directory.
+declare orig_dir
+orig_dir=$(pwd)
+readonly orig_dir
+
+# Record the current working commit.
+declare head
+head=$(git describe --always)
+readonly head
+
# Create a temporary working directory, and ensure that this directory and all
# subdirectories are cleaned up upon exit.
declare tmp_dir
tmp_dir=$(mktemp -d)
readonly tmp_dir
finish() {
- cd / # Leave tmp_dir.
- rm -rf "${tmp_dir}"
+ cd "${orig_dir}" # Leave tmp_dir.
+ rm -rf "${tmp_dir}" # Remove all contents.
+ git checkout -f "${head}" # Restore commit.
}
trap finish EXIT
@@ -37,7 +48,7 @@ readonly module origpwd othersrc
# Build an amd64 & arm64 gopath.
declare -r go_amd64="${tmp_dir}/amd64"
declare -r go_arm64="${tmp_dir}/arm64"
-make build BAZEL_OPTIONS="" TARGETS="//:gopath" 2>/dev/null
+make build BAZEL_OPTIONS="" TARGETS="//:gopath"
rsync --recursive --delete --copy-links bazel-bin/gopath/ "${go_amd64}"
make build BAZEL_OPTIONS=--config=cross-aarch64 TARGETS="//:gopath" 2>/dev/null
rsync --recursive --delete --copy-links bazel-bin/gopath/ "${go_arm64}"
@@ -70,11 +81,6 @@ declare -r go_merged="${tmp_dir}/merged"
rsync --recursive "${go_amd64}/" "${go_merged}"
rsync --recursive "${go_arm64}/" "${go_merged}"
-# Record the current working commit.
-declare head
-head=$(git describe --always)
-readonly head
-
# We expect to have an existing go branch that we will use as the basis for this
# commit. That branch may be empty, but it must exist. We search for this branch
# using the local branch, the "origin" branch, and other remotes, in order.