aboutsummaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorkris <kris@FreeBSD.org>2008-05-26 02:07:49 +0800
committerkris <kris@FreeBSD.org>2008-05-26 02:07:49 +0800
commit120fd0a3b45a5450c6ca35741a346744c4ebc1b0 (patch)
treec055b585b873c0a88191c32f4adecbbb1d6d1706 /Tools
parentdf314ceaaddf9bc48ce542453b797fe54268472c (diff)
downloadfreebsd-ports-gnome-120fd0a3b45a5450c6ca35741a346744c4ebc1b0.tar.gz
freebsd-ports-gnome-120fd0a3b45a5450c6ca35741a346744c4ebc1b0.tar.zst
freebsd-ports-gnome-120fd0a3b45a5450c6ca35741a346744c4ebc1b0.zip
Rewrite this in python instead of shell. Because we can read the
INDEX once and process internally instead of invoking many external utilities, runtime is improved from ~20 minutes to <10 seconds.
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/portbuild/scripts/chopindex94
1 files changed, 55 insertions, 39 deletions
diff --git a/Tools/portbuild/scripts/chopindex b/Tools/portbuild/scripts/chopindex
index 0b59a294049e..402735106460 100755
--- a/Tools/portbuild/scripts/chopindex
+++ b/Tools/portbuild/scripts/chopindex
@@ -1,39 +1,55 @@
-#!/bin/sh
-if [ $# != 2 ]; then
- echo "usage: chopindex <indexfile> <pkgdir>"
- return 1
-fi
-index=$1
-pkgdir=$2
-tmpindex=/tmp/index.$$
-
-# make a list of all pkgnames that don't have corresponding packages
-missing=$(/usr/bin/awk -v FS="|" -v pkgdir=$pkgdir '{
- if (system(sprintf("test -e %s/All/%s.t[bg]z\n", pkgdir, $1)))
- print $1 ;
-}' $index)
-
-# make an index for only the ports that have packages
-/usr/bin/awk -v FS="|" -v pkgdir=$pkgdir '{
- if (system(sprintf("test ! -e %s/All/%s.t[bg]z\n", pkgdir, $1)))
- print $0 ;
-}' $index > $tmpindex
-
-# find missing ports still in the index as a dependency
-delete=""
-sed=""
-for i in $missing; do
- if grep -q "[ |]$i[ |]" $tmpindex; then
- delete="$delete $i"
- sed="$sed -e s/$(echo $i | sed -e 's/\./\\./g')//g"
- fi
-done
-
-# delete them
-if [ "$delete" != "" ]; then
- echo "chopindex: deleting" $delete 1>&2
-fi
-
-sed $sed -e 's/ */ /g' -e 's/| /|/g' -e 's/ |/|/g' $tmpindex
-
-/bin/rm -f $tmpindex
+#!/usr/bin/env python
+
+import os, sys
+
+if len(sys.argv) != 3:
+ print "%s: <index> <pkgdir>" % sys.argv[0]
+ sys.exit()
+
+indexfile = sys.argv[1]
+pkgdir = sys.argv[2]
+
+if not pkgdir.endswith("/All"):
+ pkgdir = pkgdir + "/All"
+
+packages = [pkg for (pkg, ext) in map(os.path.splitext, os.listdir(pkgdir)) if ext == ".tbz"]
+
+index=[]
+pkgs=[]
+for i in file(indexfile):
+ out = i.rstrip().split("|")
+ out[7] = out[7].split(" ") # build dep
+ out[8] = out[8].split(" ") # run dep
+ index.append(out)
+
+ # Keep track of all the packages we have seen in the index. In
+ # principle there is no need to track the build/run deps since
+ # they will also be listed in field 0. We could add a sanity
+ # check for this.
+ pkgs.append(out[0])
+ pkgs.extend(out[7])
+ pkgs.extend(out[8])
+
+used=set(pkgs)
+notfound=used.difference(set(packages))
+
+# Write out the new index, stripping out the entries for missing
+# packages as well as dependencies from existing packages on the
+# missing ones.
+#
+# This is slightly dubious since it will intentionally list packages
+# that are present but missing dependencies on non-redistributable
+# things like jdk that were successfully built but removed already, so
+# the dependency lists will not be complete. It matches the old
+# chopindex.sh behaviour though.
+#
+# I think it would be better to just prune those incomplete packages
+# from the INDEX altogether, but I don't know if anyone is relying on
+# this historical behaviour.
+
+for data in index:
+ if data[0] not in notfound:
+ print "%s|%s|%s|%s" % ("|".join(data[:7]),
+ " ".join([j for j in data[7] if j not in notfound]),
+ " ".join([j for j in data[8] if j not in notfound]),
+ "|".join(data[9:]))