depend-cleanup: Add verbose (-v) and pretend/dry-run (-n) flags

These are useful for testing new additions to the script. Whilst here,
harden the script a little and improve error messages.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D31007
This commit is contained in:
Jessica Clarke 2023-07-11 01:53:04 +01:00
parent c70dd03a7f
commit 1ec7cb1b5d

View File

@ -17,22 +17,72 @@
# anyone would try a NO_CLEAN build against an object tree from before the
# related change. One year should be sufficient.
OBJTOP=$1
if [ ! -d "$OBJTOP" ]; then
echo "usage: $(basename $0) objtop" >&2
set -e
set -u
warn()
{
echo "$(basename "$0"):" "$@" >&2
}
err()
{
warn "$@"
exit 1
}
usage()
{
echo "usage: $(basename $0) [-v] [-n] objtop" >&2
}
VERBOSE=
PRETEND=
while getopts vn o; do
case "$o" in
v)
VERBOSE=1
;;
n)
PRETEND=1
;;
*)
usage
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ $# -ne 1 ]; then
usage
exit 1
fi
OBJTOP=$1
shift
if [ ! -d "$OBJTOP" ]; then
err "$OBJTOP: Not a directory"
fi
if [ -z "${MACHINE+set}" ]; then
echo "$(basename "$0"): MACHINE not set" >&2
exit 1
err "MACHINE not set"
fi
if [ -z "${MACHINE_ARCH+set}" ]; then
echo "$(basename "$0"): MACHINE_ARCH not set" >&2
exit 1
err "MACHINE_ARCH not set"
fi
run()
{
if [ "$VERBOSE" ]; then
echo "$@"
fi
if ! [ "$PRETEND" ]; then
"$@"
fi
}
# $1 directory
# $2 source filename w/o extension
# $3 source extension
@ -40,13 +90,13 @@ clean_dep()
{
if egrep -qw "$2\.$3" "$OBJTOP"/$1/.depend.$2.*o 2>/dev/null; then
echo "Removing stale dependencies and objects for $2.$3"
rm -f \
run rm -f \
"$OBJTOP"/$1/.depend.$2.* \
"$OBJTOP"/$1/$2.*o
fi
if egrep -qw "$2\.$3" "$OBJTOP"/obj-lib32/$1/.depend.$2.*o 2>/dev/null; then
echo "Removing 32-bit stale dependencies and objects for $2.$3"
rm -f \
run rm -f \
"$OBJTOP"/obj-lib32/$1/.depend.$2.* \
"$OBJTOP"/obj-lib32/$1/$2.*o
fi
@ -63,14 +113,14 @@ if [ -e "$OBJTOP"/cddl/lib/libzfs/.depend.libzfs_changelist.o ] && \
egrep -qw "cddl/contrib/opensolaris/lib/libzfs/common/libzfs_changelist.c" \
"$OBJTOP"/cddl/lib/libzfs/.depend.libzfs_changelist.o; then
echo "Removing old ZFS tree"
rm -rf "$OBJTOP"/cddl "$OBJTOP"/obj-lib32/cddl
run rm -rf "$OBJTOP"/cddl "$OBJTOP"/obj-lib32/cddl
fi
# 20200916 WARNS bumped, need bootstrapped crunchgen stubs
if [ -e "$OBJTOP"/rescue/rescue/rescue.c ] && \
! grep -q 'crunched_stub_t' "$OBJTOP"/rescue/rescue/rescue.c; then
echo "Removing old rescue(8) tree"
rm -rf "$OBJTOP"/rescue/rescue
run rm -rf "$OBJTOP"/rescue/rescue
fi
# 20210105 fda7daf06301 pfctl gained its own version of pf_ruleset.c
@ -78,13 +128,13 @@ if [ -e "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o ] && \
egrep -qw "sys/netpfil/pf/pf_ruleset.c" \
"$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o; then
echo "Removing old pf_ruleset dependecy file"
rm -rf "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o
run rm -rf "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o
fi
# 20210108 821aa63a0940 non-widechar version of ncurses removed
if [ -e "$OBJTOP"/lib/ncurses/ncursesw ]; then
echo "Removing stale ncurses objects"
rm -rf "$OBJTOP"/lib/ncurses "$OBJTOP"/obj-lib32/lib/ncurses
run rm -rf "$OBJTOP"/lib/ncurses "$OBJTOP"/obj-lib32/lib/ncurses
fi
# 20210608 f20893853e8e move from atomic.S to atomic.c
@ -96,7 +146,7 @@ clean_dep lib/libc pdfork S
if [ -e "$OBJTOP"/lib/libc++/libc++.ld ] && \
fgrep -q "/usr/lib/libc++.so" "$OBJTOP"/lib/libc++/libc++.ld; then
echo "Removing old libc++ linker script"
rm -f "$OBJTOP"/lib/libc++/libc++.ld
run rm -f "$OBJTOP"/lib/libc++/libc++.ld
fi
# 20220326 fbc002cb72d2 move from bcmp.c to bcmp.S
@ -108,7 +158,7 @@ fi
if stat "$OBJTOP"/tests/sys/kqueue/libkqueue/*kqtest* \
"$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.kqtest* >/dev/null 2>&1; then
echo "Removing old kqtest"
rm -f "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.* \
run rm -f "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.* \
"$OBJTOP"/tests/sys/kqueue/libkqueue/*
fi
@ -118,7 +168,7 @@ clean_dep usr.bin/rs rs c
# 20230110 bc42155199b5 usr.sbin/zic/zic -> usr.sbin/zic
if [ -d "$OBJTOP"/usr.sbin/zic/zic ] ; then
echo "Removing old zic directory"
rm -rf "$OBJTOP"/usr.sbin/zic/zic
run rm -rf "$OBJTOP"/usr.sbin/zic/zic
fi
# 20230208 29c5f8bf9a01 move from mkmakefile.c to mkmakefile.cc
@ -133,7 +183,7 @@ clean_dep lib/libc kqueue1 S
# 20230623 b077aed33b7b OpenSSL 3.0 update
if [ -f "$OBJTOP"/secure/lib/libcrypto/aria.o ]; then
echo "Removing old OpenSSL 1.1.1 tree"
rm -rf "$OBJTOP"/secure/lib/libcrypto \
run rm -rf "$OBJTOP"/secure/lib/libcrypto \
"$OBJTOP"/secure/lib/libssl \
"$OBJTOP"/obj-lib32/secure/lib/libcrypto \
"$OBJTOP"/obj-lib32/secure/lib/libssl