Skip to content
Snippets Groups Projects
Commit 2cd43a60 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

release script: Improve error diagnostics.

parent 680a4678
No related branches found
No related tags found
No related merge requests found
......@@ -61,13 +61,13 @@ if [[ ${TMPDIR+set} = '' ]]; then
fi
tmpsrc=$(mktemp -d "${TMPDIR-/tmp}/tmp.XXXXXXXXXX")
log=$(mktemp "${TMPDIR-/tmp}/tmp.XXXXXXXXXX")
exec 6>"$log"
echo "creating temporary source directory in $tmpsrc"
exec 6>"${log}"
echo "creating temporary source directory in ${tmpsrc}"
if (( ${DEBUG:-0} == 0)) && [[ -z "${KEEP_BUILDDIR-}" ]] ; then
trap 'rm -rf "$tmpsrc" "$log"' EXIT
trap 'rm -rf "${tmpsrc}" "${log}"' EXIT
fi
repo=$PWD
cd "$tmpsrc"
cd "${tmpsrc}"
if command -v rsync >/dev/null ; then
opts="-aHS"
rsync_options=$(rsync --help)
......@@ -86,11 +86,11 @@ if command -v rsync >/dev/null ; then
opts+=E
;;
esac
rsync ${opts} "$repo"/. .
rsync ${opts} "${repo}"/. .
else
cp -a "$repo"/. .
cp -a "${repo}"/. .
fi
bash -x "$reconfCmd" >&6 2>&6
bash -x "${reconfCmd}" >&6 2>&6
set +e
git update-index -q --ignore-submodules --refresh
set -e
......@@ -117,7 +117,7 @@ if git diff-index --exit-code HEAD -- >&6 ; then
else
echo "error: untracked/modified files found!" >&2
git status >&6 2>&6
${PAGER-less} "$log"
${PAGER-less} "${log}"
trap '' EXIT
exit 1
fi
......
......@@ -59,17 +59,81 @@ mkdir -p "$log_dir"
# trap functions are incorrectly diagnosed by shellcheck as unreachable
# shellcheck disable=SC2317
restore_extglob=$(shopt -p extglob || :)
shopt -s extglob
errMsg()
{
typeset cmd=$BASH_COMMAND pfx
typeset -i ofs=0 vpos src_lev=${#BASH_SOURCE[@]}
while [[ "${cmd:$ofs}" =~ \$\{([a-zA-Z_][a-zA-Z_0-9]*)\} ]]; do
typeset cmd=$BASH_COMMAND orig_cmd=$BASH_COMMAND pfx vpos
typeset -i ofs=0 src_lev=${#BASH_SOURCE[@]}
trap "$(shopt -p extglob)" RETURN
shopt -s extglob
while [[ "${cmd:$ofs}" \
=~ \$\{([a-zA-Z_][a-zA-Z_0-9]*(\[[^\]]*\]){0,1})(([\]+:/@\[\?-]){0,1}([a-zA-Z_0-9]*)(:[^:]*){0,1}){0,1}\} ]];
do
pfx=${cmd:ofs}; vpos=${pfx%%\$*}; ofs=$((ofs+${#vpos}))
cmd=${cmd/\$\{${BASH_REMATCH[1]}\}/${!BASH_REMATCH[1]}}
case ${BASH_REMATCH[4]} in
(-)
cmd=${cmd/\$\{${BASH_REMATCH[1]}${BASH_REMATCH[3]}\}/${!BASH_REMATCH[1]-${BASH_REMATCH[5]}}}
;;
(:-|:=)
cmd=${cmd/\$\{${BASH_REMATCH[1]}${BASH_REMATCH[3]}\}/${!BASH_REMATCH[1]:-${BASH_REMATCH[5]}}}
;;
(:+|:=)
cmd=${cmd/\$\{${BASH_REMATCH[1]}${BASH_REMATCH[3]}\}/${!BASH_REMATCH[1]:+${BASH_REMATCH[5]}}}
;;
(:\?)
ofs=$((ofs + ${#BASH_REMATCH[0]}))
;;
(+)
cmd=${cmd/\$\{${BASH_REMATCH[1]}${BASH_REMATCH[3]}\}/${!BASH_REMATCH[1]+${BASH_REMATCH[5]}}}
;;
(:)
if [[ ${#BASH_REMATCH[6]} > 0 ]]; then
cmd=${cmd/\$\{${BASH_REMATCH[1]}${BASH_REMATCH[3]}\}/${!BASH_REMATCH[1]:${BASH_REMATCH[5]}:${BASH_REMATCH[6]:1}}}
else
cmd=${cmd/\$\{${BASH_REMATCH[1]}${BASH_REMATCH[3]}\}/${!BASH_REMATCH[1]:${BASH_REMATCH[5]}}}
fi
;;
('')
case ${BASH_REMATCH[2]} in
('[@]')
vpos=${BASH_REMATCH[1]}
if [[ ${cmd:ofs-1:1} = \" \
&& ${cmd:ofs+${#BASH_REMATCH[0]}:1} = \" ]]; then
typeset subst
printf -v subst "'%s' " "${!vpos}"
subst=${subst:0:-1}
typeset -i adjust=1
else
printf -v subst "%s" "${!vpos}"
typeset -i adjust=0
fi
printf -v cmd "%s%s%s" "${cmd:0:ofs-adjust}" "$subst" \
"${cmd:ofs+${#BASH_REMATCH[0]}+adjust}"
ofs=$((ofs + ${#subst} - adjust))
;;
( '' | \[+([[:digit:]])\] )
cmd=${cmd/\$\{"${BASH_REMATCH[1]}"\}/${!BASH_REMATCH[1]}}
;;
(*)
printf "%s\n" "unhandled substitution: ${BASH_REMATCH[2]}" >&2
break
;;
esac
;;
(*)
printf "%s\n" "unhandled substitution: ${BASH_REMATCH[0]}" >&2
break
;;
esac
done
printf 'error: failed to run command\n%s\nat %s, line %d!\n' "$cmd" \
"${BASH_SOURCE[$src_lev-2]}" "${BASH_LINENO[$src_lev-2]}" >&2
printf 'error: failed to run command\n%s\n(original command: %s)\nin %s at %s, line %d!\n' "$cmd" \
"$orig_cmd" \
"${FUNCNAME[$src_lev-1]}" "${BASH_SOURCE[$src_lev-2]}" \
"${BASH_LINENO[$src_lev-2]}" >&2
}
$restore_extglob
unset restore_extglob
#
# Local Variables:
......
......@@ -48,7 +48,7 @@ if [[ ${TMPDIR+set} = '' ]]; then
fi
BUILD_DIR=$(mktemp -d "${TMPDIR}/${package}-distcheck.XXXXXX")
if (( ${DEBUG:-0} == 0)) && [[ -z "${KEEP_BUILDDIR-}" ]] ; then
trap 'chmod -R u+w "$BUILD_DIR" ; rm -rf "$BUILD_DIR"' EXIT
trap 'chmod -R u+w "${BUILD_DIR}" ; rm -rf "${BUILD_DIR}"' EXIT
fi
SRC_DIR=$PWD
cd "${BUILD_DIR}"
......@@ -57,9 +57,9 @@ for ((i=0; i < 2; ++i)); do
if ((i == 0)); then
args+=(--enable-maintainer-mode)
fi
"$SRC_DIR"/configure "${args[@]}" \
"${SRC_DIR}"/configure "${args[@]}" \
|| { status=$? ; gzip -c config.log \
>"$SRC_DIR/$log_dir/make-distcheck-config.log.gz" ; exit $status ; }
>"${SRC_DIR}/${log_dir}/make-distcheck-config.log.gz" ; exit $status ; }
mf_version=$(sed -n -e '/^PACKAGE_VERSION = /{
s/^PACKAGE_VERSION =[ ]*\(.*[^ ]\) *$/\1/; p ; q
}' Makefile)
......@@ -77,7 +77,7 @@ s/^MAKE =[ ]*\(.*[^ ]\) *$/\1/; p ; q
${MAKE} "${MAKE_DEBUG_ARGS[@]}" -j
${MAKE} "${MAKE_DEBUG_ARGS[@]}" -j check \
|| { gzip -c test/testsuite.log \
>"$SRC_DIR/$log_dir/make-distcheck-testsuite.log.gz" ; \
>"${SRC_DIR}/${log_dir}/make-distcheck-testsuite.log.gz" ; \
exit 1; }
case $i in
0)
......@@ -91,29 +91,29 @@ s/^MAKE =[ ]*\(.*[^ ]\) *$/\1/; p ; q
esac
done
if command -v xz >/dev/null ; then
gzip -dc "$package-$version.tar.gz" \
| xz > "$package-$version.tar.xz"
gzip -dc "${package}-${version}.tar.gz" \
| xz > "${package}-${version}.tar.xz"
fi
archives=("$package-$version.tar."*)
date=$(date '+%Y-%m-%d')
unset gz_archive xz_archive
if [[ -r "$package-$version.tar.gz" ]]; then
archive="$package-$version.tar.gz"
size=$(stat --format '%s' "$archive" 2>/dev/null || stat -f '%z' "$archive")
size=$(stat --format '%s' "${archive}" 2>/dev/null || stat -f '%z' "${archive}")
gz_archive="attachment:${archive} ($size bytes)|"
else
gz_archive="|"
fi
if [[ -r "$package-$version.tar.xz" ]]; then
archive="$package-$version.tar.xz"
size=$(stat --format '%s' "$archive" 2>/dev/null || stat -f '%z' "$archive")
size=$(stat --format '%s' "${archive}" 2>/dev/null || stat -f '%z' "${archive}")
xz_archive="attachment:${archive} ($size bytes)|"
else
xz_archive="|"
fi
echo "|$date|$version|${gz_archive}${xz_archive}"
echo "|${date}|${version}|${gz_archive}${xz_archive}"
cp "${archives[@]}" /tmp
echo 'Find archives in' /tmp/"$package-$version.tar."*
echo 'Find archives in' /tmp/"${package}-${version}.tar."*
#
# Local Variables:
# mode: sh
......
......@@ -69,7 +69,7 @@ if [[ -r configure && -r scripts/release/make-release-commit ]]; then
scripts/release/make-distcheck >"${log_dir}/make-distcheck.log" 2>&1
archive_msg=$(grep -E '^(Find archives in|\|2)' \
"${log_dir}/make-distcheck.log")
echo "$archive_msg"
echo "${archive_msg}"
while [[ $archive_msg = \|* ]]; do
archive_msg=${archive_msg#*
}
......@@ -79,15 +79,15 @@ if [[ -r configure && -r scripts/release/make-release-commit ]]; then
IFS=" " read -r -a archives <<< "${archive_msg}"
if [[ ${TAR+xset} != xset ]]; then
for tar in gnutar gtar ; do
if tarpath=$(command -v $tar) \
&& "$tarpath" --version | grep '^tar (GNU tar) ' >/dev/null; then
if tarpath=$(command -v ${tar}) \
&& "${tarpath}" --version | grep '^tar (GNU tar) ' >/dev/null; then
TAR=$tarpath
fi
done
fi
unset tarpath
scripts/release/compare_archive_to_tree --gnutar="${TAR-tar}" \
"${archives[0]}" "release-$version"
"${archives[0]}" "release-${version}"
else
echo "warning: release script missing." >&2
echo "Are you in the correct and autoreconf'ed directory?" >&2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment