framework: add hook to detect whether new ports are hooked into the tree

This pre-commit hook looks for newly added files matching
	foo/bar/Makefile

For these files, it is checking that a SUBDIR+=bar entry is
present in foo/Makefile.

Example run output:
	> mkdir -p graphics/test_port
	> touch graphics/test_port/Makefile
	> git add graphics/test_port/Makefile
	> git commit -m "graphics/test_port: not hooked into the build"
	[pre-commit] ERROR: Missing 'SUBDIR += test_port' in graphics/Makefile

This should hopefully help reduce the number of index breakages.

Differential Revision: https://reviews.freebsd.org/D34015
This commit is contained in:
Tobias C. Berner 2022-01-24 20:53:11 +01:00
parent 4d1970829b
commit ea589ebd66

17
.hooks/pre-commit Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
#
# Check that ports are hooked into the build
#
newish_makefiles=$(git diff --name-only --cached --diff-filter=ACR | grep -E '^[^/]+/[^/]+/Makefile$')
if [ $? -eq 0 ] ; then
for newish_makefile in ${newish_makefiles} ; do
category=$(echo "${newish_makefile}" | awk -F '/' '{print $1}')
port=$(echo "${newish_makefile}" | awk -F '/' '{print $2}')
grep -q -E "^[[:space:]]+SUBDIR[[:space:]]\+=[[:space:]]*${port}\$" ${category}/Makefile
if [ $? -ne 0 ] ; then
echo "[pre-commit] ERROR: Missing 'SUBDIR += ${port}' in ${category}/Makefile"
exit 1
fi
done
fi