summaryrefslogtreecommitdiffstats
path: root/bin/snapshot
blob: 731aa2b16b6eed315ce4b50344df0276bb987dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#!/bin/sh
#
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5.  The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html.  COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page.  It can also be found at
# http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have
# access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu.

# This script should be run nightly from cron.  It checks out hdf5
# from the CVS source tree and compares it against the previous
# snapshot.  If anything significant changed then a new snapshot is
# created, the minor version number is incremented, and the change is
# checked back into the CVS repository.
#

# function definitions
TIMESTAMP()
{
    echo "=====" "$1": "`date`" "====="
}

EXIT_BANNER()
{
TIMESTAMP "Exit $0 with status=$?"
}

# MAIN
echo "====================================="
echo "$0 $*"
echo "====================================="
TIMESTAMP MAIN
uname -a

# setup exit banner message
trap EXIT_BANNER 0

# The path isn't properly initialized on hawkwind -- /usr/local/bin is
# either missing or is after /usr/bin when it should be before.
PATH="/usr/local/bin:$PATH"

# Where are the snapshots stored?
ARCHIVES_default=/afs/ncsa/ftp/HDF/pub/outgoing/hdf5/snapshots
ARCHIVES=$ARCHIVES_default

# Where is the zlib library?
# At NCSA, half of the machines have it in /usr/lib, the other half at
# /usr/ncsa/lib.  Leave it unset.
ZLIB_default=
ZLIB=$ZLIB_default

# What compression methods to use?
METHODS="gzip bzip2"

# Use User's MAKE if set.  Else use generic make.
MAKE=${MAKE:-make}

# Make sure cvs would work
if [ -z "$CVSROOT" ]; then
    echo "Where is the CVS repository?" 1>&2
    exit 1
fi

#
# Command options
cmd="all"
test_opt=""
errcode=0
while [ $# -gt 0 ] ; do
    case "$1" in
	all)	
	    cmd="all"
	    ;;
	checkout)
	    cmdcheckout="checkout"
	    cmd=""
	    ;;
	diff)
	    cmddiff="diff"
	    cmd=""
	    ;;
	test)
	    cmdtest="test"
	    cmd=""
	    ;;
	srcdir)
	    #use srcdir option for test
	    srcdir="yes"
	    ;;
	srcdirname)
	    shift
	    if [ $# -lt 1 ]; then
		echo "srcdirname <dir> missing"
		errcode=1
		cmd="help"
		break
	    fi
	    SRCDIRNAME="$1"
	    ;;
	release)
	    cmdrel="release"
	    cmd=""
	    ;;
	clean | distclean)
	    cmdclean="$1"
	    cmd=""
	    ;;
	help)
	    cmd="help"
	    break
	    ;;
	echo)
	    set -x
	    break
	    ;;
	zlib)
	    shift
	    if [ $# -lt 1 ]; then
		echo "ZLIB information missing"
		errcode=1
		cmd="help"
		break
	    fi
	    ZLIB="$1"
	    ;;
	archive)
	    shift
	    if [ $# -lt 1 ]; then
		echo "Archive pathname missing"
		errcode=1
		cmd="help"
		break
	    fi
	    ARCHIVES="$1"
	    ;;
	--*)
	    OP_CONFIGURE="$OP_CONFIGURE $1"
	    ;;
	op-configure)
	    shift
	    if [ $# -lt 1 ]; then
		echo "op-configure option missing"
		errcode=1
		cmd="help"
		break
	    fi
	    OP_CONFIGURE="$OP_CONFIGURE $1"
	    ;;
	*)
	    echo "Unkown option $1"
	    errcode=1
	    cmd="help"
	    break
	    ;;
    esac
    shift
done

if [ "$cmd" = help ]; then
    set -
    cat <<EOF
Usage: $0 [all] [checkout] [diff] [test] [srcdir] [release] [help]
          [zlib <zlib_path>] [archive <arch_path>] [dir <dir>]
	  [op-configure <option>] [--<option>]
    all:      Run all commands (checkout, test & release)
              [Default is all]
    checkout: Run cvs checkout
    diff:     Run diff on current and previous versions.  Exit 0 if
              no significant differences are found.  Otherwise, non-zero.
    test:     Run test
    release:  Run release
    clean:    Run make clean
    distclean:Run make distclean
    srcdir:   Use srcdir option (does not imply other commands)
              "snapshot srcdir" is equivalent to "snapshot srcdir all"
              "snapshot srcdir checkout" is equivalent to "snapshot checkout"
    srcdirname <dir>:
              Use <dir> as the srcdir testing directory if srcdir is choosen.
              If <dir> starts with '-', it is append to the default name
              E.g., "snapshot srcdir srcdirname -xx" uses hostname-xx
              [Default is hostname]
    help:     Print this message
    echo:     Turn on shell echo
    zlib <zlib_path>:
              Use <zlib_path> as the ZLIB locations
              [Default is $ZLIB_default]
    archive <arch_path>:
              Use <arch_path> as the release ARCHIVE area
              [Default is $ARCHIVES_default]
    op-configure <option>:
              Pass <option> to the configure command
              E.g., "snapshot op-configure --enable-parallel"
                  configures for parallel mode
    --<option>:
              Pass --<option> to the configure command
              E.g., "snapshot --enable-parallel"
                  configures for parallel mode
EOF
    exit $errcode
fi

# Setup the proper configure option (--with-zlib) to use zlib library
# provide ZLIB is non-empty.
ZLIB=${ZLIB:+"--with-zlib="$ZLIB}
CONFIGURE="./configure $ZLIB $OP_CONFIGURE"

# Execute the requests
snapshot=yes

if [ -f bin/snapshot_version ]; then
    . bin/snapshot_version
else
    H5VERSION=hdf5
fi

BASEDIR=${HOME}/snapshots-${H5VERSION}
CURRENT=${BASEDIR}/current
PREVIOUS=${BASEDIR}/previous
HOSTNAME=`hostname | cut -f1 -d.`	# no domain part
if [ $H5VERSION != hdf5 ]; then
    CVSVERSION="-r $H5VERSION"
else
    CVSVERSION=				# use the default (main) version
fi

# Try finding a version of diff that supports the -I option too.
DIFF=diff
for d in `echo $PATH | sed -e 's/:/ /g'` ; do
    test -x $d/diff && $d/diff -I XYZ /dev/null /dev/null > /dev/null 2>&1 &&
	DIFF=$d/diff && break
done

#=============================
# Run CVS checkout
#=============================
if [ "$cmd" = "all" -o -n "$cmdcheckout" ]; then
    TIMESTAMP "checkout"
    # Create a working directory.  Hopefully one is left over from last
    # time that still has the contents of the previous release.  But if
    # not, just create one and assume that a snapshot is necessary.
    test -d ${BASEDIR} || mkdir -p ${BASEDIR} || exit 1

    # If there is a Makefile in ${CURRENT}, the last test done in it
    # has not been distclean'ed.  They would interfere with other
    # --srcdir build since make considers the files in ${CURRENT} 
    # take precedence over files in its own build-directory.  Run
    # a "make distclean" to clean them all out.  This is not really
    # part of the "checkout" functions but this is the most convenient
    # spot to do the distclean.  We will also continue the checkout process
    # regardless of the return code of distclean.
    ( cd ${CURRENT}; test -f Makefile && ${MAKE} distclean)

    # Check out the current version from CVS
    cvs -Q co -d ${CURRENT} ${CVSVERSION} hdf5 || exit 1
fi # Do CVS checkout


#=============================
# Run Test the HDF5 library
#=============================
if [ "$cmd" = "all" -o -n "$cmdtest" -o -n "$cmddiff" ]; then
    TIMESTAMP "diff"
    # setup if srcdir is used.
    if [ -z "$srcdir" ]; then
	TESTDIR=${CURRENT}
    else
	#create TESTDIR if not exist yet
	case "$SRCDIRNAME" in
	"")
	    SRCDIRNAME=$HOSTNAME
	    ;;
	-*)
	    SRCDIRNAME="$HOSTNAME$SRCDIRNAME"
	    ;;
	esac
	TESTDIR=${BASEDIR}/TestDir/${SRCDIRNAME}
	test -d ${TESTDIR} || mkdir ${TESTDIR}
    fi
    INSTALLDIR=${TESTDIR}/installdir
    test -d $INSTALLDIR || mkdir $INSTALLDIR
    # Make sure current version exists and is clean
    if [ -d ${TESTDIR} ]; then
	(cd ${TESTDIR} && ${MAKE} distclean)
    else
	errcode=$?
        snapshot=no
        exit $errcode
    fi

    # Compare it with the previous version.  Compare only files listed in
    # the MANIFEST plus the MANIFEST itself.
    if [ -d ${PREVIOUS} ]; then
	if (${DIFF} -c ${PREVIOUS}/MANIFEST ${CURRENT}/MANIFEST); then
	    snapshot=no
	    for src in `grep '^\.' ${CURRENT}/MANIFEST|expand|cut -f1 -d' '`; do
		if ${DIFF} -I H5_VERS_RELEASE -I " released on " \
		    -I " currently under development" \
		    ${PREVIOUS}/$src ${CURRENT}/$src
		then
		    :	#continue
		else
		    snapshot=yes
		    break
		fi
	    done
	fi
    fi

    # if diff is choosen, exit 0 if no significant differences are found.
    # otherwise, exit 1.  This includes cases of other failures.
    if [ -n "$cmddiff" ]; then
	if [ $snapshot = no ]; then
	    exit 0
	else
	    exit 1
	fi
    fi

    # Build, run tests and install procedures
    if [ "$snapshot" = "yes" ]; then
	if (cd ${TESTDIR} && \
	    TIMESTAMP "configure" && \
	    ${srcdir:+${CURRENT}/}${CONFIGURE} --prefix=$INSTALLDIR && \
	    TIMESTAMP "make" && \
	    ${MAKE} && \
	    TIMESTAMP "check" && \
	    ${MAKE} check && \
	    TIMESTAMP "install" && \
	    ${MAKE} install install-doc && \
	    TIMESTAMP "check-install" && \
	    ${MAKE} check-install && \
	    TIMESTAMP "uninstall" && \
	    ${MAKE} uninstall uninstall-doc); then
	    :
	else
	    errcode=$?
	    snapshot=no
	    exit $errcode
	fi
    fi
fi # Test the HDF5 library


#=============================
# Run Release snapshot, update version, and commit to cvs and tag
#=============================
if [ "$cmd" = "all" -o -n "$cmdrel" ]; then
    if [ "$snapshot" = "yes" ]; then
	TIMESTAMP "release"
	(cd ${CURRENT} && ${MAKE} distclean)
	(
	    # Turn on exit on error in the sub-shell so that it does not
	    # cvs commit if errors encounter here.
	    set -e
	    cd ${CURRENT}
	    bin/release -d $ARCHIVES $METHODS
	    RELEASE_VERSION="`perl bin/h5vers -v`"
	    perl bin/h5vers -i
	    cvs -Q commit -m "Snapshot $RELEASE_VERSION"
	)
	errcode=$?
    fi

    # Replace the previous version with the current version.
    # Should check if the errcode of the release process but there
    # are other failures after release was done (e.g. h5vers or cvs failures)
    # that should allow the replacement to occure.
    rm -rf ${PREVIOUS}
    mv ${CURRENT} ${PREVIOUS}
fi #Release snapshot


#=============================
# Clean the test area.  Default is no clean.
#=============================
if [ -n "$cmdclean" ]; then
    TIMESTAMP "clean"
    # setup if srcdir is used.
    if [ -z "$srcdir" ]; then
	TESTDIR=${CURRENT}
    else
	case "$SRCDIRNAME" in
	"")
	    SRCDIRNAME=$HOSTNAME
	    ;;
	-*)
	    SRCDIRNAME="$HOSTNAME$SRCDIRNAME"
	    ;;
	esac
	TESTDIR=${BASEDIR}/TestDir/${SRCDIRNAME}
    fi
    # Make sure current version exists and is clean
    if [ -d ${TESTDIR} ]; then
	(cd ${TESTDIR} && ${MAKE} $cmdclean )
    else
	errcode=$?
        snapshot=no
        exit $errcode
    fi
fi # Clean the Test directory

exit $errcode