Files
graphene/Scripts/clean-check
Jörg Thalheim 82caa0683d [Scripts] Make bash shebangs portable
Unlike /usr/bin/env which is a Posix standard, there is no guarentee
that /bin/bash exists. This is the case for operating systems such
as FreeBSD, NixOS and Guix. By using /usr/bin/env we also give
the user the option to provide their own bash in a different path
by setting the $PATH environemnt variable.
Distributions usually provide their own packaging wrappers
to fixup shebangs upon installation, however those are not convienent
to use when developing in the source tree.

See also other upstream discussions about the topic:

- https://github.com/systemd/systemd/pull/5816
2020-06-24 19:51:55 +02:00

52 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eu -o pipefail
top_dir="$(readlink -m "${BASH_SOURCE[0]}/../..")"
# Also allow operation on a copy named ${orig_top_dir}.clean-check.${something}
# I.e., .../graphene.clean-check.test/Scripts/clean-check will check:
# .../graphene.clean-check.test against .../graphene.clean-check.clean
clean_dir="${top_dir%.clean-check.*}.clean-check.clean"
if [ -n "${JENKINS_HOME:-}" ]; then
clean_dir="/tmp/$(basename "$clean_dir")"
fi
show_diff=false
if [ "${1:-}" == "--show-diff" ]; then
show_diff=true
fi
if ! [ -d "$clean_dir" ]; then
echo "ERROR: Copy of clean source directory not found!"
echo
echo "You need to call clean-check-prepare on the clean source directory before using"
echo "clean-check."
exit 1
fi
trap 'rm -rf "$diff"' EXIT
diff="$(mktemp)"
if [ "$show_diff" == true ]; then
diff_opts="-u"
else
diff_opts="-q"
fi
ok=true
diff "$diff_opts" -x .git -r "$clean_dir" "$top_dir" > "$diff" || ok=false
if [ "$ok" == true ]; then
echo "Source tree is unchanged. :]"
exit 0
fi
echo "================================================================================"
echo " ERROR: Source tree is not unchanged after clean:"
echo "--------------------------------------------------------------------------------"
cat "$diff"
echo "================================================================================"
exit 1