Op Fri, 18 Nov 2005 23:20:25 -0500 schreef Charles Wilson
in <437EA809.30204<at>cwilson.fastmail.fm>:
:  Igor Pechtchanski wrote:
[new gbs features]

:  Well, the problem is, logging is a decorator: it decorates the existing 
:  functions.  Unless you want a whole new build-with-logging() function 
:  that has to be maintained in parallel with the regular build() function 
:  for package foo, I don't see how this particular feature can be moved 
:  out of the core gbs without getting REAL ugly: building cmd strings, 
:  possibly decorating _those_, and then eval'ing them.  Sad, really.

How about:
build_with_logging() {
  build 2>&1 |tee <logfilename>
}
?

: >> Every new feature added to gbs makes it that much more difficult for
: >> maintainers to keep pace with gbs updates when they update their
: >> packages. Please think carefully before adding new stuff: is feature X
: >> *really* worth it?

So, I'm gonna suggest another feature. >:->

: > BTW, thanks for your comments, Chuck.  I'm afraid I lost sight of the fact
: > that many maintainers have private mods to the g-b-s, and that feature
: > updates may cause them trouble.  We should definitely rectify this.

:  The problem comes in when trying to 'upgrade' our fork to the ongoing 
:  development in the 'trunk'.  It really is a branch-and-merge-from type 
:  of operation.  Maybe I should give that local cvs mirror idea some more 
:  thought...

I came up with the following, which should make upgrading easier in
the future. You'll still have to hand-merge this into your existing
scripts though, sorry, but from then on, non-conflicting updates to
g-b-s should be easily retrieved.

How it works: When invoked with the `upgrade-self' command, the script
attempts to get the HEAD-version from cvs, if it hasn't in the last
24 hours. This HEAD-version is invoked with the `version' command
to get it's CVS-revision. If it was just downloaded, the HEAD revision
is stored in /usr/share/gbs as generic-build-script-HEAD and
generic-build-script-<HEAD-revision> If the HEAD-revision doesn't
match this build-script's CVS-revision, the build-script's revision
is gotten from /usr/share/gbs if available, otherwise it is gotten
through CVS and stored in /usr/share/gbs. Than merging is done
on a copy of the build-script. If the merge has conflicts, one is
given the possibility to edit the script and the option to reject the
new script. Finally the new script is copied into place and executed
with the remaining parameters.


ChangeLog-entry: (Please fix the <at>.)

2005-11-21  Bas van Gompel  <g-b-s-patch.buzz<at>bavag.tmfweb.nl>

        * templates/generic-build-script Add upgrade-self to main switch.
        (help): Add upgrade_self.
        (upgrade_self): new function.


L8r,

Buzz.
-- 
  ) |  | ---/ ---/  Yes, this | This message consists of true | I do not
--  |  |   /    /   really is |   and false bits entirely.    | mail for
  ) |  |  /    /    a 72 by 4 +-------------------------------+ any1 but
--  \--| /--- /---  .sigfile. |   |perl -pe "s.u(z)\1.as."    | me. 4^re
Index: packaging/templates/generic-build-script
===================================================================
RCS file: /cvs/cygwin-apps/packaging/templates/generic-build-script,v
retrieving revision 1.43
diff -u -p -r1.43 generic-build-script
--- packaging/templates/generic-build-script    18 Oct 2005 05:01:36 -0000      
1.43
+++ packaging/templates/generic-build-script    20 Nov 2005 21:05:49 -0000
@@ -163,7 +163,7 @@ Actions are:
     spkg, src-package  Prepare the source package ${src_pkg_name}
     finish             Remove source directory ${srcdir}
     checksig           Validate GPG signatures (requires gpg)
+    upgrade-self       Merge changes from upstream generic-build-script.
     first              Full run for spkg (mkdirs, spkg, finish)
     almostall          Full run for bin pkg, except for finish
     all                        Full run for bin pkg
@@ -402,6 +403,111 @@ checksig() {
     echo "You need the gnupg package installed in order to check signatures." 
; \
   fi
 }
+upgrade_self() {
+  # make sure we have cvs and merge.
+  if ! which merge >/dev/null || ! which cvs >/dev/null; then
+    echo "$0 upgrade-self: I need merge and cvs!"
+    exit 1
+  fi
+  scriptname=`basename $0`
+  my_gbs_ver="$(version |sed -e 's/.* //')"
+  gbs_cvs_repo=':pserver:[EMAIL PROTECTED]:/cvs/cygwin-apps'
+  gbs_cvs_dir='packaging/templates/'
+  mkdir -p /usr/share/gbs
+  share_gbs_fresh=false
+  test -n "$(find /usr/share/gbs -name generic-build-script-HEAD -mtime -1)" \
+    && share_gbs_fresh=true
+  # get HEAD
+  if ${share_gbs_fresh}; then
+    cp /usr/share/gbs/generic-build-script-HEAD \
+      /tmp/generic-build-script-HEAD-$$-1.sh
+  else
+    echo "$0 upgrade-self will now connect to the Red Hat CVS-server."
+    echo "If you are prompted for a password, press '<Enter>'."
+    cvs -z3 -d ${gbs_cvs_repo} co -p ${gbs_cvs_dir}generic-build-script \
+      >/tmp/generic-build-script-HEAD-$$-1.sh
+  fi
+  # fool version-check
+  touch /tmp/generic-build-script-HEAD-$$.tar
+  new_gbs_ver="$(
+    ( cd /tmp; sh -c "/tmp/generic-build-script-HEAD-$$-1.sh version"
+    ) |sed -e 's/.* //'
+  )"
+  if test "${my_gbs_ver}" != "${new_gbs_ver}"; then
+    # get ``my'' version
+    use_old_gbs=false
+    ${share_gbs_fresh} \
+      && test -f "/usr/share/gbs/generic-build-script-${my_gbs_ver}" \
+      && use_old_gbs=true
+    if ${use_old_gbs}; then
+      cp /usr/share/gbs/generic-build-script-${my_gbs_ver} \
+        /tmp/generic-build-script-${my_gbs_ver}-$$-1.sh
+    else
+      echo $0 upgrade-self will now connect to the Red Hat CVS-server.
+      echo If you are prompted for a password, press '<Enter>'.
+      cvs -z3 -d ${gbs_cvs_repo} co -r${my_gbs_ver} -p \
+       ${gbs_cvs_dir}generic-build-script \
+       >/tmp/generic-build-script-${my_gbs_ver}-$$-1.sh
+    fi
+    echo upgrading $0 from ${my_gbs_ver} to ${new_gbs_ver}
+    cp $0 /tmp/${scriptname}-$$
+    export merge_failed=false
+    echo Merging...
+    ( cd /tmp
+      merge -L "${scriptname}" -L "${my_gbs_ver}" -L "${new_gbs_ver}" \
+       ${scriptname}-$$ \
+       generic-build-script-${my_gbs_ver}-$$-1.sh \
+       generic-build-script-HEAD-$$-1.sh \
+    ) || export merge_failed=true
+    if ! ${share_gbs_fresh}; then
+      cp /tmp/generic-build-script-HEAD-$$-1.sh \
+        /usr/share/gbs/generic-build-script-HEAD
+      cp /tmp/generic-build-script-HEAD-$$-1.sh \
+        /usr/share/gbs/generic-build-script-${new_gbs_ver}
+    fi
+    if ! ${use_old_gbs}; then
+      cp /tmp/generic-build-script-${my_gbs_ver}-$$-1.sh \
+        /usr/share/gbs/generic-build-script-${my_gbs_ver}
+    fi
+    rm /tmp/generic-build-script-HEAD-$$.tar
+    rm /tmp/generic-build-script-HEAD-$$-1.sh
+    rm /tmp/generic-build-script-${my_gbs_ver}-$$-1.sh
+    if ${merge_failed}; then
+      echo \
+        'upgrade-self: Conflicts in merge. Edit the script before continuing.'
+      echo -n 'Press <Enter>. '
+      read dmy
+      ${EDITOR:-vim} "/tmp/${scriptname}-$$"
+      answer=
+      while test "${answer}" != "yes" -a "${answer}" != "no"; do
+       echo -n "Do you want to install the edited script as $0? (yes/no) "
+       read answer
+      done
+      if test "${answer}" = "yes"; then
+       export merge_failed=false
+      fi
+    fi
+    if ! ${merge_failed}; then
+      exec 5<&0 sh -es "$@"<<-EOSH
+       exec 0<&5
+       mv -f --backup=numbered /tmp/${scriptname}-$$ $0
+       echo "$0 upgraded to generic-build-script revision ${new_gbs_ver}."
+       shift
+       if test -n \$1; then
+         $0 "\$@"
+       fi
+       exit 0
+       EOSH
+      # not reached.
+    else
+      echo "$0 not replaced! keeping /tmp/${scriptname}-$$"
+      exit 1
+    fi
+  else
+    echo $0 already at generic-build-script version ${my_gbs_ver}
+  fi
+}
+
 while test -n "$1" ; do
   case $1 in
     help|--help)       help ; STATUS=$? ;;
@@ -428,6 +534,7 @@ while test -n "$1" ; do
     spkg)              spkg ; STATUS=$? ;;
     finish)            finish ; STATUS=$? ;;
     checksig)          checksig ; STATUS=$? ;;
+    upgrade-self)      upgrade_self "$@" ; STATUS=$? ;;
     first)             mkdirs && spkg && finish ; STATUS=$? ;;
     almostall)         checksig && prep && conf && build && install && \
                        strip && pkg && spkg ; STATUS=$? ;;

Reply via email to