Re: CVS scripts



On Thu, Dec 03, 1998 at 09:43:03PM -0500, Joseph P. Turian scribbled:
> You know, I am sure that most of have scripts to automate CVS tasks (i.e.
> updating everything, compiling everything, etc.) Why doesn't someone with
> particular self-confidence post their scripts on the GNOME web-site so
> that CVS newbies who have trouble with autogen.sh will be able to quickly
> get on CVS?
> 
> Just a thought.
> 
> 	Joseph

  I don't have access to the Web site, but I've been fiddling with a rather
baroque compile script I wrote--I like it though, and it does stuff like trying
to update and compile at the same time.  It compiled most of Gnome today
(except for gnome-guile I believe), so I think it works.  I'm sure there are
a lot of improvements that could be made, though. :-)  (for example, it assumes
you've modified ld.so.conf; it shouldn't be hard to modify it to use
LD_*_PATH though.)

-- 
  Daniel Burrows

"I think that the surest sign that there is intelligent
 life out there is that none of it has tried to contact us."

  -- _Calvin and Hobbes_, Bill Watterson
#!/bin/sh 

echo "        Build version 0.3"
echo "Copyright (C) 1998 Daniel Burrows (dnb@brown.edu) and sm113@cornell.edu"

# Some variables needed later

build="failure"

# Path to the gnome sources
src_dir=$HOME/gnome
# Installation directory
prefix=/usr/local/gnome
# Email address to mail notifications to
email_alert_addresses=$USER
# How to become root if needed
get_privs=sudo
# Where to dump all compilation info into
final_log=$src_dir/build_log_`date "+%m-%d-%y.%H.%M.%S-$$"`
CVSROOT=":pserver:anonymous@anoncvs.gnome.org:/cvs/gnome"

# The modules to compile
modules="glib ORBit gtk+ imlib gtk-engines gnome-libs gnome-xml gnome-objc \
        libgtop gnome-core gnome-admin gnome-games gnome-guile \
	gnome-network gnome-utils gnome-print gnumeric balsa gtkicq mc gwp"

export src_dir
export prefix
export email_alert_addresses
export get_prics
export final_log

set_global_trap() {
trap '
        if [ "$build" = "failure" ]
        then
          echo "*********************  Failed to build Gnome at `date`" >> $final_log
          cat $final_log | mail -s "Build of Gnome failed!" $email_alert_addresses
        else
          echo "*********************  Succeeded in building Gnome at `date`" >> $final_log
          cat $final_log | mail -s "Build of Gnome succeeded!" $email_alert_addresses
        fi
        ln -sf $final_log $src_dir/build_log
' EXIT
}

# The next function was originally a separate file but is now part of
# the main build script.  It updates a single package from CVS.

update() {
# file to write update log to
log=$src_dir/tmp_update_log_$$

rm -f $log
touch $log

update=failure

#
# Email me with results of compilation/failure
# before we exit
#
trap '
    if [ $update = "failure" ]; then
        echo "" >> $log
        echo "Update failed at `date`" >> $log
        cat $log | mail -s "Failed to update $1 at `date`" $email_alert_addresses
    else
        cat $log | mail -s "Succeeded in updating $1 at `date`" $email_alert_addresses
    fi
    cat $log >> $final_log
    rm -f $log
' EXIT


cd $src_dir

echo "Updating $1 from CVS server $CVSROOT at `date`" >> $log 2>&1
echo "" >> $log 2>&1 

if [ -d $1 ]
then
  cvs -z3 -d $CVSROOT checkout $1 >> $log 2>&1 || exit 1
else
  if [ -e $1 ]
  then
    rm -f $1
  fi
  cvs -z3 -d $CVSROOT checkout $1 >> $log 2>&1 || exit 1
fi

update=success

exit 0

}


# Now stuff from compile

compile() {

# file to write log info to (temporary)
log=$src_dir/tmp_compile_log_$$

rm -f $log
touch $log

# set the aclocal flags
export ACLOCAL_FLAGS="-I $prefix/share/aclocal/"

# Set the path..  -- need export so sudo gets it
PATH=$prefix/bin:$PATH
export PATH

# assume the worst, hope for the best ;-)
compilation="failure"  

#
# Email me with results of compilation/failure
# before we exit
#
trap ' 
    if [ $compilation = "failure" ]; then
	echo "Compilation of $1 failed at `date`" >> $log
	cat $log | mail -s "Failed to compile $1 at `date`" $email_alert_addresses
    else
	cat $log | mail -s "Succeeded in compiling $1 at `date`" $email_alert_addresses
    fi
    cat $log >> $final_log
    rm $log
' EXIT

echo "Preparing to compile module: $1" >> $log

cd $src_dir/$1

$get_privs rm -rf /usr/local/gnome/share/aclocal/$1.m4
rm -rf `find . -name .deps -print`

#
# Compile stuff
#

# gtk+ and glib don't need the --with-* prefixes.
if [ $1 = glib ] || [ $1 = gtk+ ]
then
	with_stuff=""
else
	with_stuff="--with-gtk-prefix=$prefix --with-glib-prefix=$prefix"
fi
echo "" >> $log
echo "******************************************************" >> $log
echo "        Compiling $1 at `date`" >> $log
echo "******************************************************" >> $log
echo ""  >> $log
rm -f config.cache
./autogen.sh --prefix=$prefix --with-gtk-prefix=$prefix --with-glib-prefix=$prefix >> $log 2>&1 &&
( make clean >> $log 2>&1 || echo "**** Warning!  'make clean' failed for $1!" >> $log ) &&
make >> $log 2>&1 &&
$get_privs sh -c "PATH=$PATH; make install >> $log 2>&1" &&
$get_privs ldconfig >> $log 2>&1 || exit 1

# we made it!
echo "" >> $log
compilation="success"
echo "Congratulations!  Compilation of $1 succeeded at `date`" >> $log

exit 0

}

# This function is used to do the updating.

update_all() {
for i in $modules
do
  if [ -e "updating_from_cvs_$i" ]
  then
    echo "****** Warning!  update is already in progress for $i.  Remove the file"$'\n'"****** updating_from_cvs_$i to allow automated update to proceed."$'\n'"****** Skipping to next module..." >> $final_log
    continue
  fi
 
  touch "updating_from_cvs_$i"

  rm -f "update_failed_for_$i"
  rm -f "updated_$i"

  attempts=5         # Don't overload the CVS servers too much if something goes wrong :-)
  until [ "$attempts" -lt 0 ] || ( update $i )
  do
    attempts=$((attempts-1))
  done
  
  if [ "$attempts" -lt 0 ]
  then
    touch "update_failed_for_$i"
  else
    touch "updated_$i"
  fi
  
  rm -f "updating_from_cvs_$i"

done
}

# This function does the compiling.  The tests against update
# files mainly help avoid recompiling unchanged files, not too
# useful now.

compile_all() {
for i in $modules
do

  while [ -e "updating_from_cvs_$i" ]
  do
    sleep 15
  done

  if [ -e "compiling_$i" ]
  then
    echo "****** Warning!  compile is already in progress for $i.  Remove the file"$'\n'"****** compiling_$i to allow automated compile to proceed." >> $final_log
    exit 1
  fi

  touch "compiling_$i"

  if ( ! $force_compile ) && [ -e "update_failed_for_$i" ]
  then
    echo "****** Warning!  update failed for module $i.  Skipping." >> $final_log
    continue
  fi

  if ! [ -e "$i" ]
  then
    echo "****** Warning!  Module $i does not exist.  Skipping." >> $final_log
    continue
  fi

  if [ -e "updated_$i" ]
  then
    should_compile=true
  else
    should_compile=false
  fi

  if $force_compile || $should_compile
  then
    if ! $should_compile
    then
      echo "******* Alert: forcing questionable compile of module $i" >> $final_log
    fi
    ( compile $i ) || ( rm -f "compiling_$i"; exit 1 )
    rm -f "updated_$i" "update_failed_for_$i"
  else
    echo "******* module $i was not updated from CVS, skipping." >> $final_log
  fi

  rm -f "compiling_$i"
  
done
}

# Ok, real code starts here

set_global_trap

# Nuke stuff from the last compilation

rm -f $final_log # Well, it shouldn't exist but..

cd $src_dir

do_update=false
do_compile=false
force_compile=false # Force things to compile even when it seems like they may be broken

# Now parse parameters

while [ $# -gt 0 ]
do
  case "$1" in
    --update ) do_update=true;;
    --compile ) do_compile=true;;
    --force-compile ) force_compile=true;;
    --modules )
        shift
	modules=$1
	;;
    --clean )
      rm -f build_log* updated_* update_failed* updating* compiling*
      trap '' EXIT
      exit 0
      ;;
    --clean-all )
      rm -f build_log* updated_* update_failed* updating* compiling*
      rm -rf $modules
      trap '' EXIT
      exit 0
      ;;
    --cvsroot )
      shift
      CVSROOT=$1
      ;;
    --prefix )
      shift
      prefix=$1
      ;;
    --srcdir )
      shift
      srcdir=$1
      ;;
    --help | * )
      cat << END_MSG

  Usage: build [options...]

Actions:

  --update    Update modules from the CVS server
  --compile   Compile updated modules (if --update is also given,
             updating will be done first)
  --clean     Erase logs and lock files from build process
  --clean-all Erase logs, lock files AS WELL AS ALL MODULES

Options:

  --modules <modules>
              <modules> is a whitespace-separated list of
              modules to use.
  --cvsroot <cvsroot>
              Use a different value for the CVSROOT than the default.
  --prefix <prefix>
              Use a different install prefix than the default.
  --srcdir <srcdir>
              Use a differenc source directory than the default.
  --force-compile
              Compile modules even if they were not properly updated.

Other:

  --license   Display the license for the program
  --help      Display this help message
END_MSG
      trap '' EXIT
      exit 0
      ;;
    --license )
      cat << END_MSG
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
END_MSG
      trap '' EXIT
      exit 0
      ;;

  esac
  shift
done

if ! ( $do_update || $do_compile )
then
  echo "*************** No actions specified, please use either" | tee -a $final_log
  echo "*************** '--update' or '--compile' or both." | tee -a $final_log
  echo "*************** (use '--help' for more options)" | tee -a $final_log
  exit 1
fi

# Go!

if $do_update
then
update_all &
# Start updating stuff in the background
sleep 10
# Give it a decent head start. 
fi

if $do_compile
then
compile_all &
fi

build=success

wait

PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]