Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Dec 2008 10:55:45 +0000
From:      "N.J. Mann" <njm@njm.me.uk>
To:        Dmitry Marakasov <amdmi3@amdmi3.ru>
Cc:        freebsd-ports@freebsd.org
Subject:   Re: Proposal: mechanism for local patches
Message-ID:  <20081213105545.GA40560@titania.njm.me.uk>
In-Reply-To: <20081212102516.GB7422@hades.panopticon>
References:  <20081202201610.GA8753@atarininja.org> <gh4d33$a55$1@hairball.ziemba.us> <20081203131234.GD70240@hades.panopticon> <20081211215712.GA72408@titania.njm.me.uk> <20081212102516.GB7422@hades.panopticon>

next in thread | previous in thread | raw e-mail | index | archive | help
In message <20081212102516.GB7422@hades.panopticon>,
	Dmitry Marakasov (amdmi3@amdmi3.ru) wrote:
> * N.J. Mann (njm@njm.me.uk) wrote:
> 
> > > I suppose that check was done to help to detect patching failures, so it
> > > may be removed.
> > 
> > I've just been trying out your patch and I think from an organisational
> > point of view it is very good.  What I mean by this is that with the
> > patch I am now able to keep my local patches completely separate from
> > the official, FreeBSD patches.  No more backing up the whole of
> > /usr/ports just in case I have a private patch in there somewhere.  Now
> > I just need to backup /usr/ports.localpatchdir (which is what I called
> > the directory LOCAPATCHDIR points to).
> 
> Nice to hear that it's useful :)

I found that it was not quite enough.  For one port I am developing
local patches for I found I either needed to modify the ports' FreeBSD
Makefile or add a post-extract script.  Since I no longer want to have
locally modified files in /usr/ports I needed to have a local
post-extract script.  So, I have modified your change to support both
patch files and script files.

%%%%%

--- bsd.port.mk~
+++ bsd.port.mk
@@ -591,6 +591,13 @@
 #				  Default: ${MASTERDIR}/files
 # PKGDIR		- A directory containing any package creation files.
 #				  Default: ${MASTERDIR}
+# LOCALDIRPREFIX
+#				- Root of local patches and scripts tree.
+# LOCALPATCHDIR	- An optional directory for storing local patches.
+#				  Default: ${LOCALDIRPREFIX}/${CATEGORY}/${PORT}/files
+# LOCALSCRIPTDIR
+#				- An optional directory for storing local scripts.
+#				  Default: ${LOCALDIRPREFIX}/${CATEGORY}/${PORT}/scripts
 #
 # Variables that serve as convenient "aliases" for your *-install targets.
 # Use these like: "${INSTALL_PROGRAM} ${WRKSRC}/prog ${PREFIX}/bin".
@@ -1371,6 +1378,11 @@
 SCRIPTDIR?=		${MASTERDIR}/scripts
 PKGDIR?=		${MASTERDIR}
 
+.if defined(LOCALDIRPREFIX)
+LOCALPATCHDIR?=		${LOCALDIRPREFIX}/${.CURDIR:C/^.*\/([^\/]+\/[^\/]+)$/\\1/}/files
+LOCALSCRIPTDIR?=	${LOCALDIRPREFIX}/${.CURDIR:C/^.*\/([^\/]+\/[^\/]+)$/\\1/}/scripts
+.endif
+
 .if defined(USE_IMAKE) && !defined(USE_X_PREFIX)
 USE_X_PREFIX=	yes
 .endif
@@ -3604,6 +3616,35 @@
 			done; \
 		fi; \
 	fi
+.if defined(LOCALPATCHDIR)
+	@if [ -d ${LOCALPATCHDIR} ]; then \
+		if [ "`${ECHO_CMD} ${LOCALPATCHDIR}/patch-*`" != "${LOCALPATCHDIR}/patch-*" ]; then \
+			${ECHO_MSG} "===>  Applying local patches for ${PKGNAME}" ; \
+			PATCHES_APPLIED="" ; \
+			for i in ${LOCALPATCHDIR}/patch-*; do \
+				case $$i in \
+					*.orig|*.rej|*~|*,v) \
+						${ECHO_MSG} "===>   Ignoring patchfile $$i" ; \
+						;; \
+					*) \
+						if [ ${PATCH_DEBUG_TMP} = yes ]; then \
+							${ECHO_MSG} "===>   Applying local patch $$i" ; \
+						fi; \
+						if ${PATCH} ${PATCH_ARGS} < $$i ; then \
+							PATCHES_APPLIED="$$PATCHES_APPLIED $$i" ; \
+						else \
+							${ECHO_MSG} `${ECHO_CMD} "=> Local patch $$i failed to apply cleanly." | ${SED} "s|${LOCALPATCHDIR}/||"` ; \
+							if [ x"$$PATCHES_APPLIED" != x"" ]; then \
+								${ECHO_MSG} `${ECHO_CMD} "=> Local patch(es) $$PATCHES_APPLIED applied cleanly." | ${SED} "s|${LOCALPATCHDIR}/||g"` ; \
+							fi; \
+							${FALSE} ; \
+						fi; \
+						;; \
+				esac; \
+			done; \
+		fi; \
+	fi
+.endif
 .endif
 
 .if !target(run-autotools)
@@ -4248,6 +4289,12 @@
 		cd ${.CURDIR} && ${SETENV} ${SCRIPTS_ENV} ${SH} \
 			${SCRIPTDIR}/${.TARGET:S/-script$//}; \
 	fi
+.if defined(LOCALSCRIPTDIR)
+	@if [ -f ${LOCALSCRIPTDIR}/${.TARGET:S/-script$//} ]; then \
+		cd ${.CURDIR} && ${SETENV} ${SCRIPTS_ENV} ${SH} \
+			${LOCALSCRIPTDIR}/${.TARGET:S/-script$//}; \
+	fi
+.endif
 .endif
 
 .endfor

%%%%%
 
> > However, please consider putting back in the test for *.orig and *~
> > files.  That way one can be actively be hacking on a patch without
> > having to keep deleting editor backup files, which you may not wish to
> > delete anyway, before attempting another build.  In my case I see no
> > need to skip *.rej and *,v files, but others may have a need for them.
> 
> Done, patch updated.
> 
> Btw, as someone who uses it, what do you think about the fact that
> local patches are applied after FreeBSD ones? (see my doubts up the
> thread).

I think the local patches should be applied after the FreeBSD ones.  It
just seems more logical.  I just see problems occurring if the local
patches are applied prior to the FreeBSD ones.  For example, if a
FreeBSD patch changes and no longer applies due to changes made by a
local (previously applied) patch, what do you do?  You would have to
modify the FreeBSD patch locally which surely is partly what the idea of
local patches is trying to prevent.  Conversely, when local patches are
applied after FreeBSD ones, if a local patch fails to apply because a
FreeBSD patch has changed, you change the local patch.  No problem! :-)


Cheers,
       Nick.
-- 




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