1#!/bin/sh
2#
3# You pass the script a port where the library has changed its ABI.
4# The script will search for this port over the complete directory you are located now
5# and will bump all ports using `Tools/scripts/bump-revision.sh`
6#
7# Version 0.1
8# License: MIT
9# Matthias Fechner <mfechner@FreeBSD.org>
10
11usage() {
12	echo "$0 devel/libgit2"
13	echo ""
14	echo "Search for all ports having devel/libgit2 as a LIB_DEPENDS"
15	echo "and bump the REVISION using the script 'Tools/scripts/bump-revision.sh'"
16	echo "After this check all modified ports with portlint."
17	echo ""
18	echo "Make sure you execute the script in the ports directory."
19	exit 1
20}
21
22[ "${1}" != "" ] || usage
23
24# check that portlint is available
25if [ x`which portlint` = x"" ]; then
26	echo "Please install portlint with"
27	echo "mport install portlint"
28	echo "to continue."
29	exit 1;
30fi
31
32PORT_TO_SEARCH=${1}
33BASEDIR=$(pwd)
34# Get a list of all ports
35echo "Prepare a list of all ports"
36ports=`find . -name Makefile -maxdepth 3 -not \( -path "./distfiles/*" -prune \) -not \( -path "./Tools/*" -prune \) -print | sort`
37echo "done."
38echo
39
40PORTS_TO_BUMP=""
41echo Check ports with dependency to ${PORT_TO_SEARCH}
42for port in ${ports}; do
43	DIR=$(dirname "${port}")
44	printf "Analyse ${DIR}"
45	LIBDEPENDS=$(make -n -V LIB_DEPENDS -C ${DIR})
46	#echo "Search >${PORT_TO_SEARCH}< in >${LIBDEPENDS}<"
47	case "${LIBDEPENDS}" in
48		*"${PORT_TO_SEARCH}"*)
49			PORTS_TO_BUMP="${PORTS_TO_BUMP} ${DIR}";;
50	esac
51	printf "\033[2K\r"
52done
53echo "done."
54
55echo "Bump PORTREVISION of following ports:"
56for PORT_TO_BUMP in ${PORTS_TO_BUMP}; do
57	echo ${PORT_TO_BUMP}
58done
59echo
60read -p "Press CTRL+c to stop or ENTER to continue..." USERINPUT
61
62for PORT_TO_BUMP in ${PORTS_TO_BUMP}; do
63	sh ./Tools/scripts/bump-revision.sh ${PORT_TO_BUMP}
64done
65
66# Now we run portlint on all port we modified
67# I borrowed here code from doportlint
68echo
69TMPFILE=$(mktemp)
70while [ "1" = "1" ]
71do
72	FAILED_PORTS=""
73	FAILURES=0
74	echo "Use TMP file ${TMPFILE}"
75	for PORT in ${PORTS_TO_BUMP}; do
76		FAILURE=0
77		echo "Running portlint in ${PORT}"
78		cd ${PORT}
79		portlint > ${TMPFILE} 2> /dev/null || FAILURE=1
80		grep '^looks fine\.$' ${TMPFILE} > /dev/null 2> /dev/null || FAILURE=1
81
82		if [ x${FAILURE} = "x1" ]; then
83			FAILURES=$((${FAILURES}+1))
84			FAILED_PORTS="${FAILED_PORTS} ${PORT}"
85			{ echo '--------------- portlint failed for '${PORT}; \
86			grep -v '^OK:' ${TMPFILE} |\
87			sed -e 's/^0 fatal errors and //'; }
88			echo ""
89		fi
90		rm -f ${TMPFILE}
91		cd ${BASEDIR}
92	done
93	if [ x${FAILURES} = "x0" ]; then
94		echo "All portlint test successfull, please review the changes before you commit them carefully."
95		echo "You maybe want to run now"
96		echo "git diff"
97		echo
98		break;
99	fi
100	PORTS_TO_BUMP=${FAILED_PORTS}
101	read -p "${FAILURES} failures, please fix portlint error and warnings and press ENTER to retest" USERINPUT
102	echo
103	echo
104	echo "------------------------------------ NEW Portlint -----------------------------"
105done
106
107