Subject: pkg_comp and xsrc
To: None <tech-pkg@netbsd.org>
From: Brook Milligan <brook@biology.nmsu.edu>
List: tech-pkg
Date: 08/07/2006 11:50:28
I have found that the sandbox created by pkg_comp is useful for
building the NetBSD system as well as building packages.  Currently,
however, it does not mount the xsrc directory anywhere.  As a result,
pkg_comp cannot be used to build an _entire_ NetBSD system (e.g., with
build.sh -x).

It would seem useful to do the following:

- Add some variables like REAL_XSRC and REAL_XSRC_OPTS to parallel the
  REAL_SRC* ones.

- If REAL_XSRC is not empty and points to a directory (same tests as
  for REAL_SRC), mount it as $DESTDIR/usr/xsrc.

This would allow one to use the sandbox for the full range of
possibilities.

I believe that the patch below will correctly accomplish this.

Cheers,
Brook

--- pkg_comp.sh.orig	2006-08-07 11:39:10.000000000 -0600
+++ pkg_comp.sh	2006-08-07 11:42:03.000000000 -0600
@@ -46,12 +46,12 @@
               LIBKVER_STANDALONE_PREFIX"
 
 _TEMPLATE_VARS="DESTDIR ROOTSHELL COPYROOTCFG BUILD_TARGET DISTRIBDIR SETS \
-                SETS_X11 REAL_SRC REAL_SRC_OPTS REAL_PKGSRC \
-                REAL_PKGSRC_OPTS REAL_DISTFILES REAL_DISTFILES_OPTS \
-                REAL_PACKAGES REAL_PACKAGES_OPTS REAL_PKGVULNDIR \
-                NETBSD_RELEASE MAKEROOT_HOOKS MOUNT_HOOKS UMOUNT_HOOKS \
-                SYNC_UMOUNT AUTO_TARGET AUTO_PACKAGES BUILD_PACKAGES \
-                REAL_CCACHE LIBKVER_STANDALONE_PREFIX"
+                SETS_X11 REAL_SRC REAL_SRC_OPTS REAL_XSRC REAL_XSRC_OPTS \
+                REAL_PKGSRC REAL_PKGSRC_OPTS REAL_DISTFILES \
+                REAL_DISTFILES_OPTS REAL_PACKAGES REAL_PACKAGES_OPTS \
+                REAL_PKGVULNDIR NETBSD_RELEASE MAKEROOT_HOOKS MOUNT_HOOKS \
+                UMOUNT_HOOKS SYNC_UMOUNT AUTO_TARGET AUTO_PACKAGES \
+                BUILD_PACKAGES REAL_CCACHE LIBKVER_STANDALONE_PREFIX"
 
 _BUILD_RESUME=
 
@@ -111,6 +111,8 @@
     : ${SETS_X11:=xbase.tgz xcomp.tgz xetc.tgz xfont.tgz xserver.tgz}
     : ${REAL_SRC:=/usr/src}
     : ${REAL_SRC_OPTS:=-t null -o ro}
+    : ${REAL_XSRC:=/usr/xsrc}
+    : ${REAL_XSRC_OPTS:=-t null -o ro}
     : ${REAL_PKGSRC:=/usr/pkgsrc}
     : ${REAL_PKGSRC_OPTS:=-t null -o ro}
     : ${REAL_DISTFILES:=/usr/pkgsrc/distfiles}
@@ -243,6 +245,15 @@
         mount $REAL_SRC_OPTS $REAL_SRC $DESTDIR/usr/src
     fi
 
+    if [ -n "$REAL_XSRC" ]; then
+        if [ ! -d "$REAL_XSRC" ]; then
+            echo " failed."
+            fsumount
+            err "REAL_XSRC $REAL_XSRC disappeared"
+        fi
+        mount $REAL_XSRC_OPTS $REAL_XSRC $DESTDIR/usr/xsrc
+    fi
+
     if [ -n "$REAL_PKGSRC" ]; then
         if [ ! -d "$REAL_PKGSRC" ]; then
             echo " failed."
@@ -323,6 +334,10 @@
         umount $DESTDIR/usr/src || fsfailed=yes
     fi
 
+    if [ -n "$REAL_XSRC" -a -d "$REAL_XSRC" ]; then
+        umount $DESTDIR/usr/xsrc || fsfailed=yes
+    fi
+
     if [ -n "$REAL_PKGSRC" -a -d "$REAL_PKGSRC" ]; then
         umount $DESTDIR/usr/pkgsrc || fsfailed=yes
     fi
@@ -429,7 +444,11 @@
         err "REAL_SRC $REAL_SRC does not exist"
     fi
 
+    if [ -n "$REAL_XSRC" -a ! -d "$REAL_XSRC" ]; then
+        err "REAL_XSRC $REAL_XSRC does not exist"
+    fi
+
     if [ -n "$REAL_PKGSRC" -a ! -d "$REAL_PKGSRC" ]; then
         err "REAL_PKGSRC $REAL_PKGSRC does not exist"
     fi
--- pkg_comp.8.orig	2006-08-07 11:43:13.000000000 -0600
+++ pkg_comp.8	2006-08-07 11:45:08.000000000 -0600
@@ -409,13 +409,24 @@
 .Sy -t null -o ro .
 .It REAL_SRC
 The src system tree.
-Usually useless, but may be needed by some packages, like sysutils/aperture.
+Usually useless, but may be needed by some packages, like sysutils/aperture,
+or for building the NetBSD system.
 Defaults to
 .Pa /usr/src .
 .It REAL_SRC_OPTS
 Mount options.
 Defaults to
 .Sy -t null -o ro .
+.It REAL_XSRC
+The xsrc system tree.
+Usually useless, but may be needed by some packages or for building the
+NetBSD system.
+Defaults to
+.Pa /usr/xsrc .
+.It REAL_XSRC_OPTS
+Mount options.
+Defaults to
+.Sy -t null -o ro .
 .It MAKEROOT_HOOKS
 A whitespace separated list of functions or external scripts to be executed
 after the sandbox is created.