[PC-BSD Commits] r19618 - pcbsd/current/src-sh/pbi-manager

svn at pcbsd.org svn at pcbsd.org
Tue Oct 9 09:22:09 PDT 2012


Author: kris
Date: 2012-10-09 16:22:09 +0000 (Tue, 09 Oct 2012)
New Revision: 19618

Modified:
   pcbsd/current/src-sh/pbi-manager/pbi-manager
Log:

Do some fancy footwork with the INDEX- file to speed up the builds

Also welcome support for using PKGNG as the backend when we cache packages



Modified: pcbsd/current/src-sh/pbi-manager/pbi-manager
===================================================================
--- pcbsd/current/src-sh/pbi-manager/pbi-manager	2012-10-08 22:18:14 UTC (rev 19617)
+++ pcbsd/current/src-sh/pbi-manager/pbi-manager	2012-10-09 16:22:09 UTC (rev 19618)
@@ -1297,7 +1297,6 @@
 	# Set sys vars
 	REALARCH="`uname -m`"
 	ARCH="$REALARCH"
-	FBSDMAJOR=`uname -r | cut -c 1`
 
         # Where is pbi-manager installed?
         PROGBASE="/usr/local" 
@@ -1305,6 +1304,10 @@
 	if [ -z "${PBI_APPDIR}" -o "`basename $0`" = "pbi_makeport_chroot" ] ; then
 		PBI_APPDIR="/usr/pbi"
         fi
+	# Set the FreeBSD Major & Release
+  	FBSDREL=`uname -r`
+	FBSDMAJOR=${FBSDREL%%.*}
+
 	PBI_WRAPPERFILE="${PBI_APPDIR}/.pbiwrapper"
 	PBI_CHROOTFILE="${PBI_APPDIR}/.pbi-world-$ARCH.txz"
 	if [ `id -u` = "0" ] ; then 
@@ -1464,6 +1467,19 @@
 	PBI_USESYSFONTS="YES"
 	PBI_VERBOSE="NO"
 	PORTSDIR="/usr/ports"
+
+	# Are we using pkgng?
+	WITH_PKGNG=$(make -f ${PORTSDIR}/Mk/bsd.port.mk -V WITH_PKGNG)
+        if [ -n "${WITH_PKGNG}" ]; then
+                export PKGNG=1
+                export PKG_ADD="pkg add"
+                export PKG_DELETE="pkg delete -y -f"
+        else
+                export PKGNG=0
+                export PKG_ADD=pkg_add
+                export PKG_DELETE=pkg_delete
+        fi
+
 }
 
 # Set and export vars used by module scripts
@@ -2121,13 +2137,13 @@
 		# Make sure this application has an associated PBI available
 		check_pbi_update "$aName" "nodisplay" \
 		 "$aName" "current" \
-		 "`uname -r`" "$_rArch" "${PBI_BROWSE_RID}"
+		 "$FBSDMAJOR" "$_rArch" "${PBI_BROWSE_RID}"
 		if [ "$?" != "0" ] ; then
 			# On amd64, see if 32bit version exists
 			if [ "$_rArch" = "amd64" ] ; then
 				check_pbi_update "$aName" "nodisplay" \
 		 		"$aName" "current" \
-		 		"`uname -r`" "i386" "${PBI_BROWSE_RID}"
+		 		"$FBSDMAJOR" "i386" "${PBI_BROWSE_RID}"
 				if [ "$?" != "0" ] ; then 
 					continue
 				else
@@ -4058,7 +4074,7 @@
 # Start copying pbi details into header file
 save_pbi_details_to_header() {
 	local _osArch="$ARCH"
-	local _osRel="`uname -r`"
+	local _osRel="$FBSDREL"
 	if [ -n "${PBI_OSREL}" ] ; then
 		_osRel="${PBI_OSREL}"
 	fi
@@ -4809,45 +4825,48 @@
 {
 	if [ "${PBI_PRUNEBUILDPORTS}" = "NO" ] ; then return ; fi
 
+  	local iFile="$PORTSDIR/INDEX-$FBSDMAJOR"
+
 	get_pkgname "${PORTSDIR}/${PBI_MAKEPORT}"
-	echo "${PKGNAME}" >/.keepports
+	echo "${PKGNAME}" > /.keepports
+	grep "^${PKGNAME}|" $iFile | cut -d '|' -f 9 | tr ' ' '\n' >>/.keepports
 
 	# Do the same for any OTHERPORTS
 	for port in ${PBI_MKPORTBEFORE}
 	do
                 if [ ! -d "${PORTSDIR}/${port}" ] ; then continue ; fi
 		get_pkgname "${PORTSDIR}/${port}"
-		echo "${PKGNAME}" >>/.keepports
+		echo "${PKGNAME}" >> /.keepports
+		grep "^${PKGNAME}|" $iFile | cut -d '|' -f 9 | tr ' ' '\n' >>/.keepports
         done
 
 	for port in ${PBI_MKPORTAFTER}
 	do
                 if [ ! -d "${PORTSDIR}/${port}" ] ; then continue ; fi
 		get_pkgname "${PORTSDIR}/${port}"
-		echo "${PKGNAME}" >>/.keepports
+		echo "${PKGNAME}" >> /.keepports
+		grep "^${PKGNAME}|" $iFile | cut -d '|' -f 9 | tr ' ' '\n' >>/.keepports
         done
+	
+	# Sort and clean the ports
+	cat /.keepports | sort | uniq > /.keepports.tmp
+	mv /.keepports.tmp /.keepports
 
-	# Now check what packages we have and prune those whom aren't needed
-	while
-	z="1"
+	# Define some commands
+     	if [ $PKGNG -eq 1 ] ; then
+		pkgInf="pkg info -f"
+     	else
+		pkgInf="pkg_info -I -a"
+	fi
+
+	# Now remove any unused ports
+	for j in `$pkgInf | cut -d " " -f 1`
 	do
-		FOUND=""
-		for j in `pkg_info -I -a | cut -d " " -f 1`
-		do
-			grep "${j}" "/.keepports" >/dev/null 2>/dev/null
-			if [ "$?" != "0" ] ; then 
-				pkg_info -R "${j}" | grep "Required" >/dev/null 2>/dev/null
-				if [ "$?" != "0" ] ; then 
-					echo "Removing non-required port: ${j}"
-					pkg_delete ${j} 
-					FOUND="1"
-					break 
-				fi
-			fi
-		done
-
-		# All done pruning ports
-		if [ -z "$FOUND" ] ; then break ; fi
+		grep -q "^${j}" "/.keepports"
+		if [ $? -ne 0 ] ; then 
+			echo "Removing non-required port: ${j}"
+			$PKG_DELETE ${j} 
+		fi
 	done
 }
 
@@ -5251,7 +5270,7 @@
 
 	check_pbi_update "$_rtar" "nodisplay" \
 	 "$_rtar" "$_rVer" \
-	 "`uname -r`" "$_rArch" "${PBI_ADDREPO_ID}"
+	 "$FBSDMAJOR" "$_rArch" "${PBI_ADDREPO_ID}"
 	if [ "$?" != "0" ] ; then 
 		exit_err "Could not find \"$_rtar\" in any indexes" 
 	fi
@@ -6633,7 +6652,7 @@
 		which svn >/dev/null 2>/dev/null
 		[ "$?" -ne 0 ] && exit_err "Subversion is required to rebuild the chroot environment!"
 
-                local _osRel=`uname -r`
+                local _osRel=$FBSDREL
                 if [ -n "${PBI_OSREL}" ]; then
                         _osRel="${PBI_OSREL}"
                 fi
@@ -6748,9 +6767,15 @@
 	get_pkgname "${PORTSDIR}/${PBI_MAKEPORT}"
 	_pname="${PKGNAME}"
 
- 	pkg_info -L ${_pname} | sed "s|^${PBI_PROGDIRPATH}/||g" \
-		| grep -v "^Information for" \
-		| grep -v "^Files:" \
+	# Define some commands
+     	if [ $PKGNG -eq 1 ] ; then
+		pkgInf="pkg info -L"
+     	else
+		pkgInf="pkg_info -L"
+	fi
+
+ 	$pkgInf ${_pname} | sed "s|^${PBI_PROGDIRPATH}/||g" \
+		| grep -v -e "^Information for" -e "^Files:" -e "owns the following" \
 		| tr -s '\t' ' ' \
 		| tr -d ' ' \
 		 > "${PBI_TMPDIR}/.pkg_flist.$$"
@@ -6882,11 +6907,23 @@
 do_port_build()
 {
   local _lPort="$1"
+
+  local iFile="$PORTSDIR/INDEX-$FBSDMAJOR"
+  if [ ! -e "$iFile" ] ; then
+     echo "Creating $iFile "
+     make -C ${PORTSDIR} index
+  fi
+
   echo "Checking port: $_lPort"
 
   # Make sure this port isn't already loaded
   local pkgName=`make -V PKGNAME -C $_lPort PORTSDIR=${PORTSDIR}`
-  if [ -e "/var/db/pkg/${pkgName}" ] ; then return ; fi
+  if [ $PKGNG -eq 1 ] ; then
+	pkg info -e ${pkgName}
+	if [ $? -eq 0 ] ; then return ; fi
+  else
+	if [ -e "/var/db/pkg/${pkgName}" ] ; then return ; fi
+  fi
 
   # Save any users / groups we need to create later
   local pUsers="`make -V USERS -C $_lPort PORTSDIR=${PORTSDIR}`"
@@ -6898,33 +6935,47 @@
      PBI_BUILD_GROUPS="$PBI_BUILD_GROUPS $pGroups"
   fi
 
-  # Parse the deps 
-  local TMPFILE=`mktemp /tmp/deplist.XXXXXXXX`
-  make all-depends-list -C $_lPort >$TMPFILE
-  while read line
+  # Parse the pkg deps 
+  for cPkg in `grep "^${pkgName}|" $iFile | cut -d '|' -f 8-9 | sed 's/|/ /g'`
   do
-    local _port="$line"
-    local _depPkgName=`make -V PKGNAME -C $_port PORTSDIR=${PORTSDIR}`
+    if [ -z "$cPkg" ] ; then continue ; fi
+
     # is this installed?
-    if [ -e "/var/db/pkg/${_depPkgName}" ] ; then continue ; fi
+    if [ $PKGNG -eq 1 ] ; then
+	pkg info -e ${cPkg}
+        if [ $? -eq 0 ] ; then continue ; fi
+    else
+	if [ -e "/var/db/pkg/${cPkg}" ] ; then continue ; fi
+    fi
 
+    local _port=`grep "^${cPkg}|" $iFile | cut -d '|' -f 2`
+
     # Not installed, do this one now until we drill down to the base
     do_port_build "${_port}" >&1 2>&1
-  done < $TMPFILE
-  rm ${TMPFILE}
+  done
 
+  if [ $PKGNG -eq 1 ] ; then
+  	pkgInf="pkg info -e"
+  	pkgDep="pkg info -d"
+  	pkgCreate="pkg create -f txz"
+  else
+  	pkgInf="pkg_info"
+  	pkgDep="pkg_info -r"
+  	pkgCreate="pkg_create -J -b"
+  fi
+
   # Not installed, see if we have a pkg to install instead
   if [ -e "/pkgs/${pkgName}.txz" ] ; then
      REBUILDPKG="NO"
      echo "Checking package: ${pkgName}"
-     pkg_info -r /pkgs/${pkgName}.txz | grep "Dependency:" | cut -d ' ' -f 2 > /tmp/deps.$$
+     $pkgDep /pkgs/${pkgName}.txz | grep -v -e "^Information" -e "depends on:" -e "^Depends" | sed '/^$/d' | sed 's|Dependency: ||g' > /tmp/deps.$$
      while read dLine
      do
-     	pkg_info $dLine >/dev/null 2>/dev/null
+     	$pkgInf $dLine >/dev/null 2>/dev/null
         if [ $? -ne 0 ] ; then
            echo "Package dependencies updated! Rebuilding port..."
            REBUILDPKG="YES"
-     	   break
+	   break
         fi
      done < /tmp/deps.$$
      rm /tmp/deps.$$
@@ -6935,7 +6986,7 @@
 
      if [ "$REBUILDPKG" = "NO" ] ; then
        echo "Adding package: ${pkgName}"
-       pkg_add -f /pkgs/${pkgName}.txz
+       $PKG_ADD -f /pkgs/${pkgName}.txz
        return
      fi
   fi
@@ -6977,10 +7028,12 @@
     done
 
     # Create new pkg
-    pkg_create -J -b ${pkgName}
+    ${pkgCreate} ${pkgName}
+    if [ $? -ne 0 ] ; then
+       exit_err "$pkgCreate ${pkgName} failed!"
+    fi
     mv ${pkgName}.txz /pkgs/
     sha256 -q /pkgs/${pkgName}.txz >/pkgs/${pkgName}.txz.sha256
-
   fi
 };
 



More information about the Commits mailing list