2013-04-02 Catherine Moore <clm@codesourcery.com>
[official-gcc.git] / contrib / reghunt / date_based / reg_periodic
bloba77567d4d5b5c332f2a9c3f0424d848e7c20e1f6
1 #! /bin/bash
3 ########################################################################
5 # File: reg_periodic
6 # Author: Janis Johnson
7 # Date: 2002/12/28
9 # Over a range of dates at specified intervals, invoke separate tools to
10 # update sources, do a build, and run one or more tests.
12 # Define these in a file whose name is the argument to this script:
13 # LOW_DATE: Date string recognized by the date command.
14 # HIGH_DATE: Date string recognized by the date command.
15 # INTERVAL: Time (in seconds) between dates for which to build.
16 # REG_UPDATE: Pathname of script to update your source tree.
17 # REG_BUILD: Pathname of script to build enough of the product to run
18 # the test.
19 # REG_TEST: Pathname of script to run one or more tests.
20 # Optional:
21 # VERBOSITY: Default is 0, to print only errors and final message.
22 # DATE_IN_MSG If set to anything but 0, include the time and date in
23 # messages
24 # REG_STOP Pathname of a file whose existence says to quit; default
25 # is STOP in the current directory.
28 # Copyright (c) 2002, 2003, 2005, 2009, 2010 Free Software Foundation, Inc.
30 # This file is free software; you can redistribute it and/or modify
31 # it under the terms of the GNU General Public License as published by
32 # the Free Software Foundation; either version 3 of the License, or
33 # (at your option) any later version.
35 # This program is distributed in the hope that it will be useful,
36 # but WITHOUT ANY WARRANTY; without even the implied warranty of
37 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 # GNU General Public License for more details.
40 # You should have received a copy of the GNU General Public License
41 # along with this program; see the file COPYING3. If not see
42 # <http://www.gnu.org/licenses/>.
44 ########################################################################
46 ########################################################################
47 # Functions
48 ########################################################################
50 # Issue a message if its verbosity level is high enough.
52 msg() {
53 test ${1} -gt ${VERBOSITY} && return
55 if [ "x${DATE_IN_MSG}" = "x" ]; then
56 echo "${2}"
57 else
58 echo "`${DATE}` ${2}"
62 # Issue an error message and exit with a nonzero status.
64 error() {
65 msg 0 "error: ${1}"
66 exit 1
69 # Turn seconds since the epoch into a date we can use with source
70 # control tools and report to the user.
72 make_date() {
73 MADE_DATE=`${DATE} -u +"%Y-%m-%d %H:%M %Z" --date "1970-01-01 ${1} seconds"` \
74 || error "make_date: date command failed"
77 # Build the components to test using sources as of a particular date and
78 # run a test case. Pass each of the scripts the date that we're
79 # testing; the first one needs it, the others can ignore it if they want.
81 process_date() {
82 TEST_DATE="${1}"
84 ${REG_UPDATE} "${TEST_DATE}"
85 if [ $? -ne 0 ]; then
86 msg 0 "source update failed for ${TEST_DATE}"
87 return
89 ${REG_BUILD} "${TEST_DATE}"
90 if [ $? -ne 0 ]; then
91 msg 0 "build failed for ${TEST_DATE}"
92 return
94 ${REG_TEST} "${TEST_DATE}"
97 ########################################################################
98 # Main program (so to speak)
99 ########################################################################
101 # If DATE isn't defined, use the default date command; the configuration
102 # file can override this.
104 if [ "x${DATE}" = "x" ]; then
105 DATE=date
108 # Process the configuration file.
110 if [ $# -ne 1 ]; then
111 echo Usage: $0 config_file
112 exit 1
115 CONFIG=${1}
116 if [ ! -f ${CONFIG} ]; then
117 error "configuration file ${CONFIG} does not exist"
120 # OK, the config file exists. Source it, make sure required parameters
121 # are defined and their files exist, and give default values to optional
122 # parameters.
124 . ${CONFIG}
126 test "x${REG_UPDATE}" = "x" && error "REG_UPDATE is not defined"
127 test "x${REG_BUILD}" = "x" && error "REG_BUILD is not defined"
128 test "x${REG_TEST}" = "x" && error "REG_TEST is not defined"
129 test "x${INTERVAL}" = "x" && error "INTERVAL is not defined"
130 test -x ${REG_TEST} || error "REG_TEST is not an executable file"
131 test "x${VERBOSITY}" = "x" && VERBOSITY=0
132 test "x${REG_STOP}" = "x" && REG_STOP="STOP"
134 msg 2 "LOW_DATE = ${LOW_DATE}"
135 msg 2 "HIGH_DATE = ${HIGH_DATE}"
136 msg 2 "INTERVAL = ${INTERVAL}"
137 msg 2 "REG_UPDATE = ${REG_UPDATE}"
138 msg 2 "REG_BUILD = ${REG_BUILD}"
139 msg 2 "REG_TEST = ${REG_TEST}"
140 msg 2 "VERBOSITY = ${VERBOSITY}"
142 # Change the dates into seconds since the epoch. This uses an extension
143 # in GNU date.
145 LOW_DATE=`${DATE} +%s --date "${LOW_DATE}"` || \
146 error "date command failed for \"${LOW_DATE}\""
147 HIGH_DATE=`${DATE} +%s --date "${HIGH_DATE}"` || \
148 error "date command failed for \"${LOW_DATE}\""
150 # Process each date in the range.
152 while [ ${LOW_DATE} -le ${HIGH_DATE} ]; do
154 # If a file called STOP appears, stop; this allows a clean way to
155 # interrupt a search.
157 if [ -f ${REG_STOP} ]; then
158 msg 0 "STOP file detected"
159 rm -f ${REG_STOP}
160 exit 1
163 # Get a version of the date that is usable by tools and readable
164 # by people, then process it.
166 make_date ${LOW_DATE}
167 process_date "${MADE_DATE}"
168 let LOW_DATE=LOW_DATE+INTERVAL
169 done
171 msg 1 "done"