Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 08 Feb 2001 15:47:42 -0800
From:      bmah@freebsd.org (Bruce A. Mah)
To:        freebsd-ports@freebsd.org
Cc:        bmah@freebsd.org
Subject:   [RFC] make upgrade target for bsd.port.mk
Message-ID:  <200102082347.f18NlgO12046@bmah-freebsd-0.cisco.com>

next in thread | raw e-mail | index | archive | help
--==_Exmh_-194770182P
Content-Type: multipart/mixed ;
	boundary="==_Exmh_-1948315890"

This is a multipart MIME message.

--==_Exmh_-1948315890
Content-Type: text/plain; charset=us-ascii

(Second try at sending this...apparently I'm so brain-dead I can't even 
spell "freebsd-ports" correctly.)

OK.  All of this talk about how to upgrade ports (plus
apparently-rampant abuse of "pkg_version -c") finally pushed me over the
edge and today I sat down to write some Makefile magic to actually
implement a ports upgrade target for bsd.port.mk.  It's based on a brain
dump I did to -ports last week.

Here it is.  Make sure you have backups...it'll probably blow something 
away you didn't expect.

Notes:  I've actually tried this on a few installed ports, and it seemed to
upgrade things OK.  It's good at preserving the dependency data for
things that depend on the port being upgraded.  It relies on the
existing ports mechanisms for finding things that a new version might
depend on, and on trying to upgrade those recursively (but only if
necessary to fulfill some dependency).  The port being upgraded *must*
have been installed with the ORIGIN feature was added to the ports
infrastructure.  I tried to make it as conservative as possible, but 
I'm pretty sure there'll be some cases it doesn't handle (shared 
library version bumps?).

Some material came out of some conversations surrounding pkg_upgrade(1).
Apologies for duplicating the efforts of several other people who have
done other scripts of this type; I wanted to try something that can be
well-integrated into the existing ports infrastructure.

I'm done with this for now.  If someone wants to run with it (preferably
someone who already understands bsd.port.mk) I'd be grateful.  I don't
know if I can spare any more cycles to look at this problem in the near 
future.

If someone finds this idea fatally flawed, that's fine too.

Cheers,

Bruce.
(crawling back to Real Work (TM))



--==_Exmh_-1948315890
Content-Type: text/plain ; name="bsd.port.mk.diff"; charset=us-ascii
Content-Description: bsd.port.mk.diff

Index: bsd.port.mk
===================================================================
RCS file: /cvsroot/ports/Mk/bsd.port.mk,v
retrieving revision 1.361
diff -c -r1.361 bsd.port.mk
*** bsd.port.mk	2001/01/16 09:25:16	1.361
--- bsd.port.mk	2001/02/08 22:24:46
***************
*** 100,105 ****
--- 100,106 ----
  # NO_CDROM		- Port may not go on CDROM.
  # NO_PACKAGE	- Port should not be packaged but distfiles can be put on
  #				  ftp sites and CDROMs.
+ # NO_UPGRADE	- Port should not be upgraded.
  # BROKEN_ELF	- Port doesn't build on ELF machines.
  # BROKEN		- Port is broken.
  #
***************
*** 306,311 ****
--- 307,313 ----
  #				  flag.
  # deinstall		- Remove the installation.
  # package		- Create a package from an _installed_ port.
+ # upgrade		- Upgrade an installed port.
  # describe		- Try to generate a one-line description for each port for
  #				  use in INDEX files and the like.
  # checkpatch	- Do a "patch -C" instead of a "patch".  Note that it may
***************
*** 455,460 ****
--- 457,467 ----
  #				  if this port is a beta version of another stable port
  #				  which is also in the tree.
  #
+ # For upgrade:
+ #
+ # TMPDEP		- Temporary file used for dependencies
+ #				  (default: ${WRKDIR}/.UPGRADE.mktmp
+ #
  # This is used in all stages:
  #
  # SCRIPTS_ENV	- Additional environment vars passed to scripts in
***************
*** 919,924 ****
--- 926,932 ----
  BUILD_COOKIE?=		${WRKDIR}/.build_done
  PATCH_COOKIE?=		${WRKDIR}/.patch_done
  PACKAGE_COOKIE?=	${WRKDIR}/.package_done
+ UPGRADE_COOKIE?=	${WRKDIR}/.upgrade_done
  
  # How to do nothing.  Override if you, for some strange reason, would rather
  # do something.
***************
*** 1053,1058 ****
--- 1061,1067 ----
  PKGMESSAGE?=	${PKGDIR}/pkg-message
  
  TMPPLIST?=	${WRKDIR}/.PLIST.mktmp
+ TMPDEP?=	${WRKDIR}/.UPGRADE.mktmp
  
  .if ${OSVERSION} >= 400000
  .for _CATEGORY in ${CATEGORIES}
***************
*** 1510,1515 ****
--- 1519,1526 ----
  	@${IGNORECMD}
  package:
  	@${IGNORECMD}
+ upgrade:
+ 	@${IGNORECMD}
  .endif
  
  .endif
***************
*** 1613,1618 ****
--- 1624,1639 ----
  .endif
  .endif
  
+ # Disable upgrade
+ .if defined(NO_UPGRADE) && !target(upgrade)
+ upgrade:
+ .if defined(IGNORE_SILENT)
+ 	@${DO_NADA}
+ .else
+ 	@${ECHO_MSG} "===>  ${PKGNAME} may not be upgraded: ${NO_UPGRADE}."
+ .endif
+ .endif
+ 
  # Disable describe
  .if defined(NO_DESCRIBE) && !target(describe)
  describe:
***************
*** 1926,1931 ****
--- 1947,2003 ----
  	@${ECHO} "[ -f ${PKGFILE} ] && (${ECHO} deleting ${PKGFILE}; ${RM} -f ${PKGFILE})"
  .endif
  
+ # Upgrade
+ 
+ .if !target(do-upgrade)
+ do-upgrade:
+ 	@oldpkg=`eval ${MAKE} find-installed-port`; \
+ 	if [ "x$$oldpkg" = "x" ]; then \
+         ${ECHO} "Installed port cannot be determined from origin information."; \
+         exit 1; \
+ 	fi; \
+ 	${ECHO_MSG} "===>  Upgrading $${oldpkg} to ${PKGNAME}"; \
+ 	cd ${.CURDIR} && DEPENDS_TARGET=upgrade-or-install ${MAKE} build; \
+ 	${ECHO_MSG} "===>  Preserving dependency information"; \
+ 	downdep=`${PKG_INFO} -q -R $${oldpkg}`; \
+ 	${ECHO_MSG} "===>  Deleting old port/package (warnings from pkg_delete may be ignored)"; \
+ 	${PKG_DELETE} -f $${oldpkg}; \
+ 	cd ${.CURDIR} && DEPENDS_TARGET=upgrade-or-install ${MAKE} install; \
+ 	dbdir=${PKG_DBDIR}/${PKGNAME}; \
+ 	${ECHO_MSG} "===>  Restoring dependency information"; \
+ 	${ECHO} "$${downdep}" > $${dbdir}/+REQUIRED_BY; \
+ 	${ECHO_MSG} "===>  Updating dependencies in other ports"; \
+     for p in $${downdep}; do \
+ 		${ECHO_MSG} "        $${p}"; \
+         ${RM} -f ${TMPDEP}; \
+         ${SED} "s/^@pkgdep $${oldpkg}/@pkgdep ${PKGNAME}/" < ${PKG_DBDIR}/$${p}/+CONTENTS > ${TMPDEP}; \
+         ${CP} ${TMPDEP} ${PKG_DBDIR}/$${p}/+CONTENTS; \
+ 	done
+ .endif
+ 
+ .if !target(find-installed-port)
+ find-installed-port:
+ 	@for p in `${PKG_INFO} -a -I | awk '{print $$1}'`; do \
+ 		o=`${PKG_INFO} -q -o $$p`; \
+ 		if [ "x$$o" != "x" ]; then \
+ 			if [ "$$o" = "${PKGORIGIN}" ]; then \
+ 				oldpkg=$$p; \
+ 			fi; \
+ 		fi; \
+ 	done; \
+ 	${ECHO} $$oldpkg
+ .endif
+ 
+ .if !target(upgrade-or-install)
+ upgrade-or-install:
+ 	@oldpkg=`cd ${.CURDIR} && ${MAKE} find-installed-port`; \
+ 	if [ "x$$oldpkg"="x" ]; then \
+ 		DEPENDS_TARGET="${DEPENDS_TARGET}" ${MAKE} install; \
+ 	else \
+ 		DEPENDS_TARGET="${DEPENDS_TARGET}" ${MAKE} upgrade; \
+     fi;
+ .endif
+ 
  ################################################################
  # This is the "generic" port target, actually a macro used from the
  # six main targets.  See below for more.
***************
*** 2064,2069 ****
--- 2136,2145 ----
  package: ${PACKAGE_COOKIE}
  .endif
  
+ .if !target(upgrade)
+ upgrade: ${UPGRADE_COOKIE}
+ .endif
+ 
  ${EXTRACT_COOKIE}:
  	@cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} fetch
  	@cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} real-extract
***************
*** 2114,2119 ****
--- 2190,2198 ----
  	@cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} install
  	@cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} real-package
  
+ ${UPGRADE_COOKIE}:
+ 	@cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} real-upgrade
+ 
  # And call the macros
  
  real-fetch: _PORT_USE
***************
*** 2128,2138 ****
  real-install: _PORT_USE
  	@${ECHO_MSG} "===>  Installing for ${PKGNAME}"
  real-package: _PORT_USE
  
  # Empty pre-* and post-* targets, note we can't use .if !target()
  # in the _PORT_USE macro
  
! .for name in fetch extract patch configure build install package
  
  .if !target(pre-${name})
  pre-${name}:
--- 2207,2219 ----
  real-install: _PORT_USE
  	@${ECHO_MSG} "===>  Installing for ${PKGNAME}"
  real-package: _PORT_USE
+ real-upgrade: _PORT_USE
+ 	@${ECHO_MSG} "===>  Upgrading for ${PKGNAME}"
  
  # Empty pre-* and post-* targets, note we can't use .if !target()
  # in the _PORT_USE macro
  
! .for name in fetch extract patch configure build install package upgrade
  
  .if !target(pre-${name})
  pre-${name}:

--==_Exmh_-1948315890--



--==_Exmh_-194770182P
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (FreeBSD)
Comment: Exmh version 2.2 06/23/2000

iD8DBQE6gzAe2MoxcVugUsMRAtL+AJ9DScp6OOKdxEFi1qCMMjB3lMEdSwCcDYiN
hFdMwXnSNovZmCeM63qLfbE=
=uoDr
-----END PGP SIGNATURE-----

--==_Exmh_-194770182P--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




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