[csw-devel] SF.net SVN: opencsw:[312] gar-wrapper/mgar

skayser at users.sourceforge.net skayser at users.sourceforge.net
Mon Feb 21 14:37:25 CET 2011


Revision: 312
          http://opencsw.svn.sourceforge.net/opencsw/?rev=312&view=rev
Author:   skayser
Date:     2011-02-21 13:37:25 +0000 (Mon, 21 Feb 2011)

Log Message:
-----------
mgar: enable multi-GAR-branch handling, adjust locate to use NAME (instead of GARNAME)

Modified Paths:
--------------
    gar-wrapper/mgar

Modified: gar-wrapper/mgar
===================================================================
--- gar-wrapper/mgar	2011-02-21 13:24:48 UTC (rev 311)
+++ gar-wrapper/mgar	2011-02-21 13:37:25 UTC (rev 312)
@@ -15,16 +15,16 @@
 # ----------------------------------------------------------------------------
 #
 # Todos:
-# * Integrate functionality to download/switch to different gar branches
+# * Recipes: Move from svn:externals to GARTYPE
 # * Integrate the creation of a new package (with sanity check whether
-#   package already exists)
+#   package already exists). Use per-directory Makefile.template files.
+# * Improve errors messages when buildsys can't be found
 #
 # Bugs:
 #
 # Ideas/thoughts:
+# * Should read_makefile_value support commandline overrides (like gmake)?
 # * mgar commit: check for and warn on stale checksums file
-# * mgar init: pulls gar/v2.*, how about a gar/current/ symlink in the repo
-#   to facilitate GAR version or location changes
 # * stuff that's indexed by namazu is overkill, reduce to speed up index?
 #
 # Possible issues:
@@ -41,9 +41,20 @@
 
 PATH=$PATH:/opt/csw/bin
 DEF_BUILDTREE=~/opencsw
-SVN_REPO=https://gar.svn.sourceforge.net/svnroot/gar/csw/mgar/
-SVN_BUILDSYS=gar/v2/
+GAR_REPO=https://gar.svn.sourceforge.net/svnroot/gar/csw/mgar/gar/
+PKG_REPO=https://gar.svn.sourceforge.net/svnroot/gar/csw/mgar/pkg/
 
+function read_config_value {
+  __param=$1
+  [ -f ~/.garrc ] || die_config_missing
+  ggrep -E "^$__param *=" ~/.garrc | tail -1 | cut -d= -f2 | sed -e 's/^ *//'
+}
+
+function read_makefile_value {
+  __param=$1
+  ggrep -E "^$__param *=" Makefile | tail -1 | cut -d= -f2 | sed -e 's/^ *//'
+}
+
 function die_config_missing {
   cat >&2 <<EOM
 Configuration not found. Have you initialized your build tree yet?
@@ -57,36 +68,41 @@
 
 function die_buildsys_not_found {
   cat >&2 <<EOM
-ERROR: Your ~/.garrc configuration doesn't point to a valid build system.
-Point BUILDTREE to directory where you want to keep your package build
-descriptions and point BUILDSYS to a checkout of GAR (optional, a default
-of BUILDTREE/.buildsys will be assumed). Example:
+ERROR: No build system found at $BUILDSYS
 
-BUILDTREE=~/opencsw/pkg
-BUILDSYS=~/opencsw/pkg/.buildsys-specialversion
-
 EOM
   exit 2
 }
 
+function assert_buildsys_present {
+  [ -f "$1/category.mk" ] || die_buildsys_not_found
+}
+
 function die_not_in_pkg_dir {
   echo "ERROR: No package build description found in the current directory" >&2
   exit 2
 }
 
-function read_config_value {
-  __param=$1
-  [ -f ~/.garrc ] || die_config_missing
-  ggrep -E "^$__param *=" ~/.garrc | tail -1 | cut -d= -f2 | sed -e 's/^ *//'
+function in_pkg_dir {
+  [ -f Makefile ] || return 1
+  grep "^include gar/category.mk" Makefile >/dev/null 2>&1 || return 1
 }
 
-function assert_buildsys_present {
-  [ -f "$1/category.mk" ] || die_buildsys_not_found
+function assert_in_pkg_dir {
+  in_pkg_dir || die_not_in_pkg_dir
 }
 
-function ensure_in_pkg_dir {
-  [ -f Makefile ] || die_not_in_pkg_dir
-  grep "^include gar/category.mk" Makefile >/dev/null 2>&1 || die_not_in_pkg_dir
+# Is this a per-pkg command? Relies on *-cmd markers in the code (c.f. ##main)
+function is_per_pkg_command {
+  __cmd=$1
+  __global_cmds=`sed -ne '/^# global-cmds/,/^# \/global-cmds/p' $0 | \
+    ggrep -E '^\s*[^)]+\) ' | cut -d\) -f1`
+
+  while read cmd; do
+    [ "$cmd" == "$1" ] && return 1
+  done < <( echo "$__global_cmds" )
+
+  return 0
 }
 
 function init_buildtree {
@@ -97,8 +113,8 @@
   fi
   mkdir -p $__buildtree/.buildsys
   echo "Initializing the package build tree at $__buildtree"
-  svn co $SVN_REPO/$SVN_BUILDSYS "$__buildtree/.buildsys"
-  svn co --depth empty $SVN_REPO/pkg "$__buildtree"
+  svn co $GAR_REPO "$__buildtree/.buildsys"
+  svn co --depth empty $PKG_REPO "$__buildtree"
   echo
   echo "Initialized the package build tree at $__buildtree."
   echo "Registering the package build tree location in ~/.garrc"
@@ -106,18 +122,33 @@
   echo >> ~/.garrc
   echo BUILDTREE="$__buildtree" >> ~/.garrc
   echo
-  echo 'Now you can fetch the package build descriptions via: "mgar up-pkgtree"'
+  echo 'Now you can fetch the package build descriptions via: "mgar up"'
   echo 'Please be advised that this will take some time. So grab yourself a cup'
   echo 'of tea/coffee :)'
 }
 
 function create_legacy_gar_link {
-  __buildsys=$1
+  __buildsys="$1"
   if [ ! -h "$__buildsys"/gar ]; then
     ( cd "$__buildsys" && ln -s . gar )
   fi
 }
 
+function assert_multi_buildsys_tree {
+  __buildsys_tree="$1"
+
+  # migrate from single-buildsys to multi-buildsys (<= mgar version 297)
+  if [ -f "$__buildsys_tree"/category.mk ]; then 
+    echo "Your GAR tree needs to be updated. To do so please run:"
+    echo
+    echo "  rm -rf $__buildsys_tree"
+    echo "  svn co $GAR_REPO \\"
+    echo "    $__buildsys_tree/"
+    echo
+    exit 2
+  fi
+}
+
 # Commit working files (prefixes pkg path and checks for untracked changes)
 function verify_local_status_and_commit() {
 
@@ -162,6 +193,15 @@
   $0 -f <( cat Makefile; echo -e '\npkgdir:\n\t at echo $(PKGROOT)' ) pkgdir
 }
 
+function get_pkg_buildsysdir() {
+  # fallback to svn:externals until builds are adjusted to carry GARYTPE
+  __gartype=`read_makefile_value GARTYPE`;
+  if [ -z "$__gartype" ]; then
+    __gartype=`svn pg svn:externals . | awk -F/ '/^gar/ { print $NF }'`
+  fi
+  echo $BUILDTREE/.buildsys/$__gartype
+}
+
 # Build the index for locating Makefiles within the package build tree
 function build_index() {
   __buildtree=$1
@@ -186,10 +226,10 @@
 
   case "$__term" in
     a:*) __term=${__term#a:}; __searchby="";;
-    g:*) __term=${__term#g:}; __searchby="GARNAME";;
+    g:*) __term=${__term#g:}; __searchby="NAME";;
     p:*) __term=${__term#p:}; __searchby="PACKAGES";;
     c:*) __term=${__term#c:}; __searchby="CATALOG";;
-      *)                      __searchby="(CATALOG|PACKAGES|GARNAME)";;
+      *)                      __searchby="(CATALOG|PACKAGES|NAME)";;
   esac
 
   namazu -slr "*$__term*" $__buildtree/.index | while read f; do
@@ -209,8 +249,7 @@
   init [dir]          Initialize package build tree, defaults to ~/opencsw/
   index               Build/update the package build tree index
   locate <name>       Search a package within the package build tree index
-  show-pkgtree        Show the location of the package build tree
-  up-pkgtree          Update the package build tree
+  up [--all]          Update current (or all) package build descriptions
 
 Package build actions (to be called from a package build directory):
   fetch               Download the package source
@@ -229,7 +268,7 @@
   modenv              Display employed compiler options
   scm <command>       Pass a command to the underlying SCM (currently: svn)
   show-buildsys       Display the location and version of the build system
-  up-buildsys         Update the build system
+  show-pkgtree        Show the location of the package build tree
   version             Display mgar version information
 
 EOM
@@ -238,14 +277,20 @@
 ## pre-flight checks
 
 [ $# -eq 0 -o "${1:-}" == "help" -o "${1:-}" == "--help" ] && { usage; exit; }
+[ $1 == "-x" ] && { shift; set -x; }
 
 # Unless we are going to "init", make sure that the build system is in place
 if [ "${1-}" != "init" ]; then
   BUILDTREE="`read_config_value BUILDTREE`"; eval BUILDTREE="$BUILDTREE"
-  BUILDSYS="`read_config_value BUILDSYS`"; eval BUILDSYS="$BUILDSYS"
-  if [ -z "$BUILDSYS" ]; then
-    BUILDSYS="$BUILDTREE/.buildsys"
-  fi
+fi
+
+assert_multi_buildsys_tree "$BUILDTREE/.buildsys"
+
+# When we execute a non-global (i.e. pkg scope) command, assert that we are
+# actually in a pkg directory and that the pkg relevant GAR branch can be found
+if is_per_pkg_command $1; then
+  assert_in_pkg_dir
+  BUILDSYS=`get_pkg_buildsysdir`
   assert_buildsys_present "$BUILDSYS"
   create_legacy_gar_link "$BUILDSYS"
 fi
@@ -253,24 +298,40 @@
 ## main
 
 case $1 in
+
+# global-cmds
              init) init_buildtree ${2-$DEF_BUILDTREE};;
             index) build_index "$BUILDTREE";;
            locate) shift; search_index "$BUILDTREE" "${1-}";;
      show-pkgtree) echo "$BUILDTREE";;
+        commit|ci) shift; verify_local_status_and_commit "$@";;
+              scm) shift; svn $@;;
+               up) if [ "${2:-}" == "--all" ]; then
+                     $0 up-all;
+                   else
+                     $0 up-pkg;
+                   fi
+                   ;;
+           up-all) echo "Updating full build tree (this will take some time)"
+                   svn up \
+                     --set-depth infinity --ignore-externals \
+                     "$BUILDTREE"
+                   svn up "$BUILDTREE/.buildsys"
+                   ;;
+          version) grep '^# $Id:' $0 | cut -d" " -f4;;
+# /global-cmds
+
+# per-pkg-cmds
     show-buildsys) __rev="`svn info "$BUILDSYS" | grep ^Revision:`"
                    __branch=`svn info "$BUILDSYS" | grep ^URL: | awk -F/ '{ print $(NF-1)"/"$NF }'`
                    echo -e "$BUILDSYS\t($__rev, Branch: $__branch)"
                    ;;
-      up-buildsys) cd "$BUILDSYS" && svn up;;
-       up-pkgtree) cd "$BUILDTREE" && \
-                     svn up --set-depth infinity --ignore-externals
+      show-srcdir) echo `get_srcdir`;;
+    show-stagedir) echo `get_stagedir`;;
+           up-pkg) echo "Updating current package directory + build system"
+                   svn up --ignore-externals; svn up $BUILDSYS;;
+                *) gmake -I "$BUILDSYS" "$@"
                    ;;
-      show-srcdir) ensure_in_pkg_dir; echo `get_srcdir`;;
-    show-stagedir) ensure_in_pkg_dir; echo `get_stagedir`;;
-              scm) shift; svn $@;;
-        commit|ci) shift; verify_local_status_and_commit "$@";;
-          version) grep '^# $Id:' $0 | cut -d" " -f4;;
-                *) ensure_in_pkg_dir
-                   gmake -I "$BUILDSYS" "$@"
-                   ;;
+# /per-pkg-cmds
+
 esac


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list