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

skayser at users.sourceforge.net skayser at users.sourceforge.net
Fri Apr 15 15:16:46 CEST 2011


Revision: 369
          http://opencsw.svn.sourceforge.net/opencsw/?rev=369&view=rev
Author:   skayser
Date:     2011-04-15 13:16:46 +0000 (Fri, 15 Apr 2011)

Log Message:
-----------
mgar: Looooots of changes (too many), mainly enable global BUILDSYS override

Introduce BUILDSYS_OVERRIDE in ~/.garrc to force a buildsys branch globally.
If this is in effect, users need to explicitly acknowledge commits to avoid
accidental commits where the build recipe won't be buildable with it's
configured externals/GARTYPE GAR branch.

Changes to commands:

* commit|ci: now only operates from within a package dir. This was
  required for the change above and could be tweaked to operate on a
  global level again if this is required.

* commit: automatically commit .. when package has been freshly 
  created (and the parent dir needs to be committed instead of
  the current dir).

New commands:

* newpkg: create a new package based on $BUILDTREE/newpkg-Makefile

* list-categories: list categories understood by GAR

* up --buildsys: update .buildsys only

Deleted commands:

* newpkg-*: use newpkg instead

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

Modified: gar-wrapper/mgar
===================================================================
--- gar-wrapper/mgar	2011-04-11 09:52:40 UTC (rev 368)
+++ gar-wrapper/mgar	2011-04-15 13:16:46 UTC (rev 369)
@@ -33,11 +33,6 @@
 #
 # Todos:
 # * Add template for ~/.garrc (think new users)
-# * Integrate the creation of a new package (with sanity check whether
-#   package already exists). Use per-directory Makefile.template files.
-#   Example:
-#     mgar newpkg foo (picks up Makefile.tmpl)
-#     mgar newpkg --documented foo (picks up Makefile.tmpl-documented)
 # * When packaging mgar, shield mgar up --self so that it won't override
 #   the package binary, but place it somewhere else.
 # * In commit mode, if (pwd.endswith('trunk') and svn.rev -eq 0) commit ..
@@ -149,7 +144,7 @@
 }
 
 function die_not_in_pkg_dir {
-  echo "ERROR: No package build description found in the current directory" >&2
+  echo "ERROR: This command needs to be run from within a package directory." >&2
   exit 2
 }
 
@@ -268,21 +263,50 @@
   fi
 }
 
+function assert_non_overriden_buildsys() {
+  [ -z "$BUILDSYS_OVERRIDE" ] && return
+  if [ "$BUILDSYS_OVERRIDE" != "$BUILDSYS_PKG" ]; then
+    echo "You are currently using a buildsys override."
+    echo ""
+    echo "Buildsys (override): $BUILDSYS_OVERRIDE"
+    echo "Buildsys  (package): $BUILDSYS_PKG"
+    echo ""
+    echo "If you really want to proceed, call commit with: -o"
+    exit 2
+  fi
+}
+
+function assert_no_untracked_files() {
+  local __untracked=`svn status | grep \? || :`
+  if [ -n "$__untracked" ]; then
+    echo "Attention: working directory contains untracked changes."
+    echo
+    echo "$__untracked"
+    echo
+    echo "If you really want to proceed, call commit with: -f"
+    exit 2
+  fi
+}
+
 # Commit working files (prefixes pkg path and checks for untracked changes)
 function verify_local_status_and_commit() {
-  local opts __forceflag __logmsg __untracked
+  local opts __forceflag __logmsg __untracked __override_buildsys
   # Beware: getopts stops on the first non-option argument, thus
   # "mgar . -m foo -f" won't see any getopts handling
-  while getopts "fm:" opts ; do
+  while getopts "fm:o" opts ; do
     case $opts in
       f) __forceflag=1;;
       m) __logmsg="$OPTARG";;
+      o) __override_buildsys=1;;
     esac
   done
   shift $((OPTIND-1))
 
+  [ -z "${__forceflag:-}" ] && assert_no_untracked_files
+  [ -z "${__override_buildsys:-}" ] && assert_non_overriden_buildsys
+
   # prefix the commitmsg with a pkg path prefix unless a prefix is given
-  __prefix=$( pwd | sed "s,^$BUILDTREE/,," )
+  local __prefix=$( pwd | sed "s,^$BUILDTREE/,," )
   if [ -n "${__logmsg:-}" ]; then
     if ! echo "$__logmsg" | ggrep -qE '^\S+:'; then
       __logmsg="$__prefix: $__logmsg"
@@ -297,18 +321,17 @@
     esac
   fi
 
-  __untracked=`svn status | grep \? || :`
-  if [ -n "$__untracked" -a -z "${__forceflag:-}" ]; then
-    echo "Attention: working directory contains untracked changes."
-    echo
-    echo "$__untracked"
-    echo
-    echo "If you really want to proceed, call \"mgar commit -f\""
-    return
+  # In a pkg build directory where the parent directory hasn't been
+  # checked in previously, we need to commit .. instead of .
+  local __pkg_rev=`get_rev .`
+  local __parent_rev=`get_rev ..`
+  if [ "${__pkg_rev}" == 0 -a "${__parent_rev}" == 0 ]; then
+    echo "Commiting package build for the first time (incl. parent dir)."
+    echo svn commit "${__log_args[@]:-}" ..
+  else
+    echo "Commiting changes."
+    echo svn commit "${__log_args[@]:-}" "$@"
   fi
-
-  echo "Commiting local changes."
-  svn commit "${__log_args[@]:-}" "$@"
 }
 
 function get_rev() {
@@ -379,6 +402,44 @@
   done
 }
 
+function newpkg() {
+  local __pkgname=$1
+  local __version=${2:-X.Y}
+
+  if [ -d ${__pkgname} ]; then
+    echo "ERROR: ${__pkgname} already exists" >&2
+    exit 1
+  fi
+
+  ### Add template find mechanism (upwards from PWD, until BUILDTREE reached)
+  local __template=$BUILDTREE/newpkg-Makefile
+  if [ ! -f ${__template} ]; then
+    echo "ERROR: Template $__template not found" >&2
+    echo "Likely fix:" >&2
+    echo "  (cd $BUILDTREE && svn up `basename ${__template}`)" >&2
+    exit 1
+  fi
+
+  echo "Creating package skeleton for ${__pkgname} ${__version}."
+  svn mkdir --parents ${__pkgname}/trunk/files ${__pkgname}/{branches,tags} 
+  touch ${__pkgname}/trunk/checksums
+  perl -p -e "\
+    s,%NAME%,${__pkgname},; \
+    s,%VERSION%,${__version},; \
+    " ${__template} > ${__pkgname}/trunk/Makefile
+  svn add ${__pkgname}/trunk/Makefile
+  svn add ${__pkgname}/trunk/checksums
+
+  svn ps svn:keywords Id ${__pkgname}/trunk/Makefile
+  svn ps svn:ignore \
+    -F <( echo -e "cookies\ndownload\nwork\n" ) ${__pkgname}/trunk
+  svn ps svn:externals "gar $GAR_REPO/v2" ${__pkgname}/trunk
+
+  echo ""
+  echo "Created successfully at $PWD/${__pkgname}/trunk" >&2
+  echo ""
+}
+
 function usage() {
   cat <<EOM
 Wrapper around the GAR build system. Usage: mgar <action> [options]
@@ -388,6 +449,7 @@
   index               Build/update the package build tree index
   locate <name>       Search a package within the package build tree index
   up [--all]          Update current (or all) package build descriptions
+  newpkg <name> [ver] Create new package build directory
 
 Package build actions (to be called from a package build directory):
   fetch               Download the package source
@@ -437,7 +499,9 @@
 if is_per_pkg_command $1; then
   assert_in_pkg_dir
   assert_no_conflicting_gar_dir_present
-  BUILDSYS=`get_pkg_buildsysdir`
+  BUILDSYS_OVERRIDE="`read_config_value OVERRIDE_BUILDSYS`"
+  BUILDSYS_PKG="`get_pkg_buildsysdir`"
+  BUILDSYS=${BUILDSYS_OVERRIDE:-$BUILDSYS_PKG}
   assert_buildsys_present "$BUILDSYS"
   create_legacy_gar_link "$BUILDSYS"
 fi
@@ -449,18 +513,21 @@
 # global-cmds
             index) build_index "$BUILDTREE";;
            locate) shift; search_index "$BUILDTREE" "${1-}";;
-         newpkg-*) gmake "$@";; # temporary, should be replaced, see TODO
+           newpkg) shift; newpkg ${1:-} ${2:-};;
      show-pkgtree) echo "$BUILDTREE";;
-        commit|ci) shift; verify_local_status_and_commit "$@";;
               scm) shift; svn $@;;
                up) if [ "${2:-}" == "--all" ]; then
                      $0 up-all
                    elif [ "${2:-}" == "--self" ]; then
                      update_self ${3:-}
+                   elif [ "${2:-}" == "--buildsys" ]; then
+                     $0 up-buildsys
                    else
                      $0 up-pkg
                    fi
                    ;;
+      up-buildsys) echo "Updating $BUILDTREE/.buildsys"
+                   svn up "$BUILDTREE/.buildsys";;
            up-all) echo "Updating full build tree (this will take some time)"
                    svn up \
                      --set-depth infinity --ignore-externals \
@@ -471,9 +538,11 @@
 # /global-cmds
 
 # per-pkg-cmds
+        commit|ci) shift; verify_local_status_and_commit "$@";;
         edit-file) $EDITOR `gfind \`get_srcdir\` -name "$2"`;;
         find-file) gfind "`get_srcdir`" \
                      -name .git -prune -o -name "${2:-*}" -print;;
+  list-categories) ls "$BUILDSYS/categories/";;
     show-buildsys) __rev=`get_rev "$BUILDSYS"`
                    __branch=`get_repourl "$BUILDSYS" | sed -e "s,$GAR_REPO,,"`
                    echo -e "$BUILDSYS\t(Revision: $__rev, Branch: $__branch)"


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