summaryrefslogtreecommitdiff
path: root/mk/scripts
diff options
context:
space:
mode:
authordmcmahill <dmcmahill>2003-01-04 21:03:08 +0000
committerdmcmahill <dmcmahill>2003-01-04 21:03:08 +0000
commit884424321e9eb530569b118c20bb8a4b72977090 (patch)
treee4616d680a2576f904dc613cb43bbad891b8f61e /mk/scripts
parent3981a5f6dcd9b0d3016e417b1e1b8e730750caf3 (diff)
downloadpkgsrc-884424321e9eb530569b118c20bb8a4b72977090.tar.gz
add two scripts used for creating dependency databases. These scripts
can be used anytime one needs to extract the complete dependency information for a package for example, when creating a README.html file for the pkg. The approach used by mkdatabase requires exactly one make call per package which makes it scale well to packages with large dependency trees that have many paths to the leaves.
Diffstat (limited to 'mk/scripts')
-rwxr-xr-xmk/scripts/chkdatabase.awk115
-rwxr-xr-xmk/scripts/mkdatabase179
2 files changed, 294 insertions, 0 deletions
diff --git a/mk/scripts/chkdatabase.awk b/mk/scripts/chkdatabase.awk
new file mode 100755
index 00000000000..d07a2d22e03
--- /dev/null
+++ b/mk/scripts/chkdatabase.awk
@@ -0,0 +1,115 @@
+#!/usr/bin/awk -f
+#
+# $NetBSD: chkdatabase.awk,v 1.1 2003/01/04 21:03:08 dmcmahill Exp $
+#
+# Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Dan McMahill.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by the NetBSD
+# Foundation, Inc. and its contributors.
+# 4. Neither the name of The NetBSD Foundation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# This script reads a pkgsrc database created with the 'print-summary-data'
+# target and returns a lists of packages which are listed as DEPENDS and/or
+# BUILD_DEPENDS but do not have their own dependencies recorded yet.
+# This can be used as part of a loop which makes several passes to record
+# the complete dependency tree for a package in the database
+#
+
+BEGIN {
+ if(debug) {
+ printf("Reading database file\n") > "/dev/stderr";
+ fflush("/dev/stderr");
+ }
+}
+
+/^(build_)?depends / {
+#
+# Read in the entire depends tree
+# These lines look like:
+#
+#depends /usr/pkgsrc/math/scilab xless-[0-9]*:../../x11/xless pvm-3.4.3:../../parallel/pvm3
+#build_depends /usr/pkgsrc/math/scilab libtool-base>=1.4.20010614nb9:../../devel/libtool-base
+#
+ pkg = $2;
+
+# mark this package as having its depencencies listed
+ depended_pkgs[pkg] = 1;
+
+# now go through the dependency lists and pull out all pkg directories that
+# we will need to examine to ensure they have been depended.
+ for(i=3; i<=NF; i++) {
+ split($i,a,":");
+ pkgpat=a[1];
+ pkgdir=a[2];
+ sub(/[\.\/]*/,"",pkgdir);
+ if(pkgdir !~ /\//) {
+ pkgcat=pkg;
+ gsub(/\/.*/,"",pkgcat);
+ pkgdir=pkgcat "/" pkgdir;
+ if(debug) printf("Corrected missing category directory to get \"%s\"\n",pkgdir) > "/dev/stderr";
+ }
+ if(debug){
+ printf("package in directory %s %s on:\n",pkg,deptype) > "/dev/stderr";
+ printf("\tpkgpat = %s\n",pkgpat) > "/dev/stderr";
+ printf("\tpkgdir = %s\n",pkgdir) > "/dev/stderr";
+ }
+
+# mark this package directory as being one which is depended upon
+ depended_on_pkgs[pkgdir] = 1;
+
+ }
+ next;
+}
+
+
+END {
+ i=0;
+ for(pkg in depended_on_pkgs) {
+ if(pkg in depended_pkgs) {
+ if(debug) printf("Package: %s is already depended\n",pkg) > "/dev/stderr";
+ }
+ else {
+ if(debug)printf("Package: %s is NOT depended\n",pkg) > "/dev/stderr";
+ not_depended[i]=pkg;
+ i++;
+ }
+ }
+
+ i=0;
+ while(i in not_depended) {
+ printf("%s\n",not_depended[i]);
+ i++;
+ }
+ close("/dev/stderr");
+
+ exit(0);
+}
diff --git a/mk/scripts/mkdatabase b/mk/scripts/mkdatabase
new file mode 100755
index 00000000000..3e8af3b7460
--- /dev/null
+++ b/mk/scripts/mkdatabase
@@ -0,0 +1,179 @@
+#!/bin/sh
+# $NetBSD: mkdatabase,v 1.1 2003/01/04 21:03:08 dmcmahill Exp $
+#
+# Script for generating a database with complete dependency information
+# for a particular package
+#
+# Copyright (c) 2003 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Dan McMahill.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by the NetBSD
+# Foundation, Inc. and its contributors.
+# 4. Neither the name of The NetBSD Foundation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+
+TMPDIR=${TMPDIR:-/tmp}
+BMAKE=${BMAKE:-make}
+AWK=${AWK:-/usr/bin/awk}
+DATABASE=${DATABASE:-${TMPDIR}/pkgdb.$$}
+
+# as of 2003-01-04, metapkgs/gnome gets to pass #6 so
+# it is very likely that if you reach 25, something is broken
+MAX_PASS=${MAX_PASS:-25}
+
+prog=$0
+
+usage(){
+ echo "$prog - Generates a complete dependency tree for a particular package"
+ echo "Usage: $prog [-d|--debug] [-f|--database database]"
+ echo " "
+ echo " $prog -h|--help"
+ echo " "
+ echo " $prog -v|--version"
+ echo " "
+ echo "The options supported by $prog are: "
+ echo " "
+ echo " -d|--debug Enables debugging output"
+ echo " "
+ echo " -f|--database <file> Writes the database into file specified by <file>"
+ echo " "
+ echo " -h|--help Displays this help message"
+ echo " "
+ echo " -v|--version Displays the version of this script and exits."
+ echo " "
+ echo "Example: cd /usr/pkgsrc/graphics/gimp && $prog -d /tmp/gimp_database"
+ echo " "
+}
+
+clean_and_exit(){
+ exit 1
+}
+
+
+######################################################################
+#
+# Handle command line options
+#
+######################################################################
+
+DEBUG=
+
+while
+ test -n "$1"
+do
+ case "$1"
+ in
+
+ # Turn on debugging
+ -d|--debug)
+ DEBUG=yes
+ shift
+ ;;
+
+ # Use the specified database file
+ -f|--database)
+ DATABASE=$2
+ shift 2
+ ;;
+
+ # Help
+ -h|--help)
+ usage
+ exit 0
+ ;;
+
+ # Version
+ -v|--version)
+ ${AWK} '/^#[ \t]*\$NetBSD/ {gsub(/,v/,"",$3);printf("%s: Version %s, %s\n",$3,$4,$5); exit 0;}' $prog
+ exit 0
+ ;;
+
+ -*) echo "$prog: ERROR: $1 is not a valid option"
+ usage
+ clean_and_exit
+ ;;
+
+ *)
+ break
+ ;;
+
+ esac
+done
+
+if [ "x$DEBUG" = "xyes" ]; then
+ set -v
+fi
+
+if [ ! -d $TMPDIR ]; then
+ mkdir -p $TMPDIR
+fi
+
+prompt="----> "
+
+case ${DATABASE} in
+ /*)
+ # we already have the absolute path to the database file
+ # so do nothing
+ ;;
+
+ *)
+ # make sure we have the full path to the database file
+ DATABASE=`pwd`/${DATABASE}
+ ;;
+esac
+
+echo "$prompt Creating database in ${DATABASE}"
+
+${BMAKE} print-summary-data > ${DATABASE} || exit 1
+here=`pwd`
+echo "$prompt Depending in $here (pass #1)"
+dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${DEBUG} ${DATABASE}`
+pass=2
+while [ ! -z "$dirs" -a $pass -lt ${MAX_PASS} ]; do
+ for d in $dirs ; do
+ echo "$prompt Depending in ../../$d (pass #$pass)" ;\
+ cd ../../$d && ${BMAKE} print-summary-data >> ${DATABASE} || exit 1
+ cd $here
+ done
+ dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${DEBUG} ${DATABASE}`
+ pass=`expr $pass + 1`
+done
+
+if [ $pass -eq ${MAX_PASS} ]; then
+ echo "ERROR: You have reached $pass times through the dependency tree"
+ echo " and _still_ not finished. This is probably due to a broken"
+ echo " set of dependencies. You may wish to examine the partial"
+ echo " database left in ${DATABASE}"
+ exit 1
+else
+ echo "Complete dependency database left in ${DATABASE}"
+fi
+