Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 May 2012 08:42:44 GMT
From:      Akinori MUSHA <knu@FreeBSD.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/168222: Allowing to specify per-file PATCH_DIST_STRIP in PATCHFILES
Message-ID:  <201205220842.q4M8giSj077803@red.freebsd.org>
Resent-Message-ID: <201205220850.q4M8o27O001437@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         168222
>Category:       ports
>Synopsis:       Allowing to specify per-file PATCH_DIST_STRIP in PATCHFILES
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 22 08:50:02 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Akinori MUSHA
>Release:        FreeBSD 9.0-STABLE
>Organization:
>Environment:
>Description:
When trying to integrate multiple external patches, you are lucky if all of them have a common base directory, but if any of them has a different base directory, your head starts to ache thinking you'll have to do:

- move the PATCHFILES/PATCH_SITES entry to DISTFILES/MASTER_SITES
- add the patch file to EXTRACT_ONLY
- write a custom pre- or post-patch target by hand to apply it

You can alternatively download the patch files and put them under PATCHDIR, which means we duplicate a patch file that's available on the Internet and host it in our ports tree.  It is waste of space and we might lose the chance to notice when the patch file is withdrawn or updated by the author.

>How-To-Repeat:
A simple search only found three ports that call patch with -p# against a distfile:

/usr/ports/graphics/xv/Makefile
/usr/ports/mail/qmail/Makefile
/usr/ports/www/squidguard/Makefile

But I'm sure there are a lot of hidden third party patches in PATCHDIR's.
>Fix:
Apply the attached patch that enables per-file patch flags in PATCHFILES.

Patch attached with submission follows:

--- bsd.port.mk.~1.708.~	2012-03-14 07:49:12.000000000 +0900
+++ bsd.port.mk	2012-05-22 17:03:26.436896195 +0900
@@ -109,6 +109,9 @@
 #				  patches. Make will look for them at PATCH_SITES (see below).
 #				  They will automatically be uncompressed before patching if
 #				  the names end with ".gz", ".bz2" or ".Z".
+#				  For each file you can optionally specify a strip
+#				  flag of patch(1) after a colon if it has a different
+#				  base directory, e.g. "file1 file2:-p1 file3".
 #				  Default: not set.
 # PATCH_SITES	- Primary location(s) for distribution patch files
 #				  if not found locally.
@@ -2706,9 +2709,12 @@
 .endfor
 _G_TEMP=	DEFAULT
 .for _P in ${PATCHFILES}
-_P_TEMP=	${_P:S/^${_P:C/:[^:]+$//}//}
-.	if !empty(_P_TEMP)
-.		for _group in ${_P_TEMP:S/^://:S/,/ /g}
+_P_TEMP=	${_P:C/:[^-:][^:]*$//}
+_P_groups=	${_P:S/^${_P:C/:[^:]+$//}//:S/^://}
+_P_file=	${_P_TEMP:C/:-[^:]+$//}
+_P_strip=	${_P_TEMP:S/^${_P_TEMP:C/:-[^:]*$//}//:S/^://}
+.	if !empty(_P_groups)
+.		for _group in ${_P_groups:S/,/ /g}
 .			if !defined(_PATCH_SITES_${_group})
 _G_TEMP_TEMP=	${_G_TEMP:M/${_group}/}
 .				if empty(_G_TEMP_TEMP)
@@ -2717,11 +2723,15 @@
 .				endif
 .			endif
 .		endfor
-_PATCHFILES+=	${_P:C/:[^:]+$//}
-.	else
-_PATCHFILES+=	${_P}
+.	endif
+_PATCHFILES:=	${_PATCHFILES} ${_P_file}
+.	if !empty(_P_strip)
+_PATCH_DIST_STRIP_CASES:=	${_PATCH_DIST_STRIP_CASES} ("${_P_file}") printf %s "${_P_strip}" ;;
 .	endif
 .endfor
+_P_groups=
+_P_file=
+_P_strip=
 _G_TEMP=
 _G_TEMP_TEMP=
 ALLFILES?=	${_DISTFILES} ${_PATCHFILES}
@@ -2790,7 +2800,7 @@
 .endfor
 _PATCH_SITES_ENV=	_PATCH_SITES_DEFAULT="${_PATCH_SITES_DEFAULT}"
 .for _F in ${PATCHFILES}
-_F_TEMP=	${_F:S/^${_F:C/:[^:]+$//}//:S/^://}
+_F_TEMP=	${_F:S/^${_F:C/:[^-:][^:]*$//}//:S/^://}
 .	if !empty(_F_TEMP)
 .		for _group in ${_F_TEMP:S/,/ /g}
 .			if defined(_PATCH_SITES_${_group})
@@ -3508,8 +3518,9 @@
 	@cd ${_DISTDIR};\
 	${_PATCH_SITES_ENV} ; \
 	for _file in ${PATCHFILES}; do \
-		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^:]+$$//'` ; \
+		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^-:][^:]*$$//'` ; \
 		select=`${ECHO_CMD} $${_file#$${file}} | ${SED} -e 's/^://' -e 's/,/ /g'` ; \
+		file=`${ECHO_CMD} $$file | ${SED} -E -e 's/:-[^:]+$$//'` ; \
 		force_fetch=false; \
 		filebasename=$${file##*/}; \
 		for afile in ${FORCE_FETCH}; do \
@@ -3611,21 +3622,26 @@
 .if defined(PATCHFILES)
 	@${ECHO_MSG} "===>  Applying distribution patches for ${PKGNAME}"
 	@(cd ${_DISTDIR}; \
+	  patch_dist_strip () { \
+		case "$$1" in \
+		  ${_PATCH_DIST_STRIP_CASES} \
+		esac; \
+	  }; \
 	  for i in ${_PATCHFILES}; do \
 		if [ ${PATCH_DEBUG_TMP} = yes ]; then \
 			${ECHO_MSG} "===>   Applying distribution patch $$i" ; \
 		fi; \
 		case $$i in \
 			*.Z|*.gz) \
-				${GZCAT} $$i | ${PATCH} ${PATCH_DIST_ARGS}; \
+				${GZCAT} $$i; \
 				;; \
 			*.bz2) \
-				${BZCAT} $$i | ${PATCH} ${PATCH_DIST_ARGS}; \
+				${BZCAT} $$i; \
 				;; \
 			*) \
-				${PATCH} ${PATCH_DIST_ARGS} < $$i; \
+				${CAT} $$i; \
 				;; \
-		esac; \
+		esac | ${PATCH} ${PATCH_DIST_ARGS} `patch_dist_strip $$i`; \
 	  done)
 .endif
 .if defined(EXTRA_PATCHES)
@@ -4652,8 +4668,9 @@
 	@(cd ${_DISTDIR}; \
 	 ${_PATCH_SITES_ENV} ; \
 	 for _file in ${PATCHFILES}; do \
-		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^:]+$$//'` ; \
+		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^-:][^:]*$$//'` ; \
 		select=`${ECHO_CMD} $${_file#$${file}} | ${SED} -e 's/^://' -e 's/,/ /g'` ; \
+		file=`${ECHO_CMD} $$file | ${SED} -E -e 's/:-[^:]+$$//'` ; \
 		if [ ! -f $$file -a ! -f $${file##*/} ]; then \
 			if [ ! -z "$$select" ] ; then \
 				__PATCH_SITES_TMP= ; \
@@ -4720,9 +4737,10 @@
 	@(cd ${_DISTDIR}; \
 	${_PATCH_SITES_ENV} ; \
 	for _file in ${PATCHFILES}; do \
-		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^:]+$$//'` ; \
-			fileptn=`${ECHO_CMD} $$file | ${SED} 's|/|\\\\/|g;s/\./\\\\./g;s/\+/\\\\+/g;s/\?/\\\\?/g'` ; \
+		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^-:][^:]*$$//'` ; \
 		select=`${ECHO_CMD} $${_file#$${file}} | ${SED} -e 's/^://' -e 's/,/ /g'` ; \
+		file=`${ECHO_CMD} $$file | ${SED} -E -e 's/:-[^:]+$$//'` ; \
+		fileptn=`${ECHO_CMD} $$file | ${SED} 's|/|\\\\/|g;s/\./\\\\./g;s/\+/\\\\+/g;s/\?/\\\\?/g'` ; \
 		if [ ! -z "${LISTALL}" -o ! -f $$file -a ! -f $${file##*/} ]; then \
 			if [ ! -z "$$select" ] ; then \
 				__PATCH_SITES_TMP= ; \


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201205220842.q4M8giSj077803>