Subject: New, improved "make makepatchsum"
To: None <tech-pkg@NetBSD.ORG>
From: Frederick Bruckman <fb@enteract.com>
List: tech-pkg
Date: 10/12/1999 03:35:36
I intend to commit this within the next few days unless there are
significant objections. Key features:

1) Makes a placeholder iff there are no patches, but there exists a
patch-sum file already (indicating that there were patches before).
The purpose of this is to "catch" folks who switch from sup to cvs, or
who sup on top of a tarball, or who have old patches in their tree for
any other reason, without requiring undue effort on the part of the
committers. The original "patch-sum" mechanism has a flaw, in that if
the patches directory and patch-sum file, both, are "cvs rm"'d,
there's then no way to detect obsolete patches.

2) Don't do anything if the patch-sum file wouldn't change, except
emit a message. This should permit the cautious committer to run "make
makepatchsum" repeatedly, without leading to spurious "regen" commits.

Only one change to Standard Operating Procedure is contemplated,
namely that the committer run "make makepatchsum" after removing the
last patch. It's not necessary to run "make makepatchsum" on a new
package with no patches, nor would it have any effect. I also don't
believe it necessary to run the entire pkgsrc tree. Nor would that
have any effect either! It'll be good enough to make the placeholder
patch-sum file one by one, as individual packages go patch-free.

Index: bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.353
diff -c -r1.353 bsd.pkg.mk
*** bsd.pkg.mk	1999/10/07 16:04:57	1.353
--- bsd.pkg.mk	1999/10/12 08:34:59
***************
*** 1804,1827 ****
  
  .if !target(makepatchsum)
  makepatchsum:
! 	${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${FILESDIR}
! 	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${PATCH_SUM_FILE}
! 	${_PKG_SILENT}(${_PKG_DEBUG}					\
  	if [ -d ${PATCHDIR} ]; then					\
  		cd ${PATCHDIR};						\
- 		${ECHO} -n "$$" > ${PATCH_SUM_FILE};			\
- 		${ECHO} -n "NetBSD" >> ${PATCH_SUM_FILE}; 		\
- 		${ECHO} "$$" >> ${PATCH_SUM_FILE};			\
- 		${ECHO} "" >> ${PATCH_SUM_FILE};			\
  		for sumfile in "" patch-*; do				\
! 			if [ "X$$sumfile" = X"" ]; then continue; fi;	\
  			case $$sumfile in				\
! 			patch-local-*) ;;				\
! 			*.orig) continue ;;				\
! 			*)						\
! 				${ECHO} "MD5 ($$sumfile) = `${SED} -e '/\$$NetBSD.*/d' $$sumfile | ${MD5}`" >> ${PATCH_SUM_FILE}; \
  			esac;						\
  		done;							\
  	fi)
  .endif
  
--- 1804,1849 ----
  
  .if !target(makepatchsum)
  makepatchsum:
! 	${_PKG_SILENT}${_PKG_DEBUG}					\
! 	(${MKDIR} ${FILESDIR};						\
! 	if [ -f "${PATCH_SUM_FILE}" ]; then				\
! 		${AWK} -- '{print ; exit}' < ${PATCH_SUM_FILE} > ${PATCH_SUM_FILE}.new; \
! 	else								\
! 		${ECHO} -n "$$" > ${PATCH_SUM_FILE}.new;		\
! 		${ECHO} -n "NetBSD" >> ${PATCH_SUM_FILE}.new;		\
! 		${ECHO} "$$" >> ${PATCH_SUM_FILE}.new;			\
! 	fi;								\
! 	${ECHO} "" >> ${PATCH_SUM_FILE}.new;				\
  	if [ -d ${PATCHDIR} ]; then					\
  		cd ${PATCHDIR};						\
  		for sumfile in "" patch-*; do				\
! 			if [ "X$$sumfile" = "X" ]; then continue; fi;	\
! 			if [ "X$$sumfile" = "Xpatch-*" ]; then break; fi; \
  			case $$sumfile in				\
! 				patch-local-*) ;;			\
! 				*.orig) continue ;;			\
! 				*) ${ECHO} "MD5 ($$sumfile) = `${SED} -e '/\$$NetBSD.*/d' $$sumfile | ${MD5}`" >> ${PATCH_SUM_FILE}.new; \
  			esac;						\
  		done;							\
+ 	fi;								\
+ 	if [ "`${AWK} -- '{nlines++} END {print nlines}' < ${PATCH_SUM_FILE}.new`" = "2" ]; then \
+ 		if [ -f "${PATCH_SUM_FILE}" ]; then			\
+ 			${ECHO} "This placeholder file is generated by the \`\`makepatchsum'' target" >> ${PATCH_SUM_FILE}.new; \
+ 			${ECHO} "whenever the patches directory is empty or missing. Its purpose" >> ${PATCH_SUM_FILE}.new; \
+ 			${ECHO} "is to ensure that the presence of any obsolete patches will cause" >> ${PATCH_SUM_FILE}.new; \
+ 			${ECHO} "the proper error to be emitted at build time." >> ${PATCH_SUM_FILE}.new; \
+ 			${ECHO_MSG} "placeholder patch-sum file created"; \
+ 		else							\
+ 			${RM} -f ${PATCH_SUM_FILE}.new;			\
+ 			${ECHO_MSG} "no patch-sum file created";	\
+ 			exit 0;						\
+ 		fi;							\
+ 	fi;								\
+ 	if cmp -s ${PATCH_SUM_FILE}.new ${PATCH_SUM_FILE} ""; then	\
+ 		${RM} -f ${PATCH_SUM_FILE}.new;				\
+ 		${ECHO_MSG} "patch-sum file unchanged!";		\
+ 	else								\
+ 		${MV} ${PATCH_SUM_FILE}.new ${PATCH_SUM_FILE};		\
  	fi)
  .endif