Initial git import
[sxemacs] / contrib / do_builds.sh
1 #!/bin/sh
2 #
3
4 function do_log {
5     if [ -n "$LOG_FILE" ]; then
6         echo "$0 $(date): $@" >> $LOG_FILE
7     fi
8 }
9
10 if [ ! -f ./,,conf ]; then
11     cat > ./,,conf <<EOF
12 # --*-shell-script-*--
13 #
14 # The path to the SXEmacs source
15 SOURCE=/path/to/sxemacs
16 #
17 # Hammer value when doing autogen.sh [Check it for more details
18 HAMMER=""
19 #
20 # Autogen command [leave empty in order to skip it]
21 AUTOGEN="./autogen.sh"
22 #
23 # The command line arguments to pass to the make command
24 MAKE_ARGS="time-build-report"
25 #
26 # File to log progress to
27 LOG_FILE=",,build.log"
28 #
29 # Make a ++TAGS directory
30 MAKE_TAGS=""
31 #
32 # Remove the build directory when build is successful
33 # (and after reporting...) ?
34 # Yes or Y
35 REMOVE_ON_SUCCESS=""
36 #
37 # Report the build status with an email? 
38 # Yes or Y (All)
39 # Failures or F (Failures only)
40 # Success or S  (Successes only)
41 # Anything else - No reports at all
42 REPORT_STATUS="Yes"
43 #
44 # Send success email to this address instead of sxemacs-devel@sxemacs.org
45 MAIL_SUCCESS_TO=""
46 #
47 # Send failure email to this address instead of sxemacs-devel@sxemacs.org
48 MAIL_FAILURE_TO=""
49 #
50 # The email should come from this email address
51 # [ $USER@$(hostname -f  2> /dev/null || (hostname ; domainname)) will be used otherwise
52 MAIL_FROM=""
53 EOF
54     echo "Please review the generated ,,conf file and rerun."
55     exit 1
56 fi
57 source ./,,conf
58 if [ -z "${SOURCE}" -o ! -d "${SOURCE}" -o ! -f ${SOURCE}/sxemacs.pc.in ]; then
59     echo "No SXEmacs source found at ${SOURCE}"
60     exit 1
61 fi
62 if [ -z "${MAIL_FROM}" ]; then
63     MAIL_FROM="${USER}@$(hostname -f 2> /dev/null || (hostname ; domainname))"
64     echo "WARNING: No mail from defined. Will use ${MAIL_FROM} instead."
65 fi
66 STATUS=""
67 if [ -n "${AUTOGEN}"  ]; then
68     CURDIR="$(pwd)"
69     cd "${SOURCE}" 
70     PREFIX=$(pwd)
71     if [ -n "${HAMMER}" ]; then
72         echo HAMMER: ${HAMMER}
73     fi
74     (export HAMMER ; ${AUTOGEN} ) || STATUS=FAIL_AUTOGEN
75     cd "$CURDIR"
76 fi
77 if [ -n "${STATUS}" ]; then
78     do_log "Failure: ${STATUS}"
79     exit 1
80 fi
81 if [ -n "${BUILD_TAGS}" ]; then
82     # Let's build ourselfs the tags for this source tree,
83     mkdir -p ./++TAGS
84     CURDIR="$(pwd)"
85     cd ./++TAGS 
86     eval "${PREFIX}/configure" || STATUS="FAIL_CONFIGURE_$?"
87     if [ -z "${STATUS}" ]; then
88         make tags || STATUS="FAIL_TAGS_$?"
89     fi
90     cd "$CURDIR"
91 fi
92 if [ -n "${STATUS}"  ]; then
93     do_log "Failure: ${STATUS}"
94     exit 1
95 fi
96 for f in *.conf; do
97     if [ "$f" = "*.conf" ]; then
98         echo "Nothing to do - create some .conf files! "
99         exit 1
100     fi
101     STATUS=""
102     CONF_OPTS="$(cat $f)"
103     build_name="$(echo ${f} |sed 's/\.conf$//')"
104     do_log "Started building ${build_name}"
105     if [ -d "./${build_name}" ]; then
106         /bin/rm -rf "./${build_name}"
107     fi
108     mkdir -p "./${build_name}"
109     CURDIR="$(pwd)"
110     cd "./${build_name}" 
111     eval "${PREFIX}/configure ${CONF_OPTS}" || STATUS="FAIL_CONFIGURE_$?"
112     if [ "${STATUS}" = "FAIL_CONFIGURE_127" -a -f "./Installation" -a -f "./config.log" ]; then
113         if [ $(tail -1 ./config.log) = "configure: exit 0" ]; then
114             STATUS="FAIL_CONFIGURE_0"
115         fi
116     fi
117     if [ -z "${STATUS}" -o "${STATUS}" = "FAIL_CONFIGURE_0" ]; then
118         STATUS="Success"
119         make ${MAKE_ARGS} || STATUS="FAIL_MAKE_$?"
120         if [ "${STATUS}" = "FAIL_MAKE_0" ]; then
121             STATUS="Success"
122         fi
123         if egrep '^make.*:.*Error' ,,beta.out; then
124             STATUS="${STATUS}_ERROR_IN_BUILD"
125         else
126             if [ -f ,,make-check.out ]; then
127                 if [ ! "${STATUS}" = "Success" ]; then
128                     STATUS="Tests fail"
129                 elif [ -n "$(grep 'tests successful' ,,make-check.out | grep -v 100%)" ]; then
130                     STATUS="Sucess(Some tests fail)"
131                 fi
132             fi
133         fi
134     fi
135     DO_REPORT_FAILURE=""
136     REPORT_THIS="No"
137     if [ "${REPORT_STATUS}" = "Yes" -o  "${REPORT_STATUS}" = "Y" ]; then
138         REPORT_THIS="Yes"
139     elif [ "${STATUS}" = "Success" -o "${STATUS}" = "Sucess(Some tests fail)" ]; then
140         if [ "${REPORT_STATUS}" = "Success" -o  "${REPORT_STATUS}" = "S" ]; then
141             REPORT_THIS="Yes"
142         fi
143     elif [ "${REPORT_STATUS}" = "Failures" -o  "${REPORT_STATUS}" = "F" ]; then
144         REPORT_THIS="Yes"
145     fi
146     if [ "${REPORT_THIS}" = "Yes" ]; then
147         if [ "${STATUS}" = "Success" -o "${STATUS}" = "Tests fail" -o "${STATUS}" = "Sucess(Some tests fail)" ]; then
148             # First test if can actually send email from SXEmacs, otherwise just give up :-)
149             CLI=" -eval \"(unless (fboundp 'mail-send-and-exit) (kill-emacs 2))\""
150             if [ -n "${MAIL_FROM}" ]; then
151                 CLI="${CLI} -eval '(setq user-mail-address \"$MAIL_FROM\")'"
152             fi
153             if [ -n "$MAIL_SUCCESS_TO" ]; then
154                 CLI="${CLI} -eval '(setq build-rpt-email \"${MAIL_SUCCESS_TO}\")'"
155             fi
156             CLI="${CLI} -eval '(if (send-build-rpt \"${STATUS}\") (kill-emacs 0) (kill-emacs 1))'"
157             eval "src/sxemacs -batch ${CLI}" || DO_REPORT_FAILURE="YES" STATUS="${STATUS}-Build-Rpt-Failed-$?" 
158         else
159             DO_REPORT_FAILURE="YES"
160         fi
161         if [ "${DO_REPORT_FAILURE}" = "YES" ]; then
162             ${PREFIX}/contrib/report-build-failure.sh "${MAIL_FROM}" "${MAIL_FAILURE_TO}" "${STATUS}"
163         fi
164     fi
165     cd "$CURDIR"
166     if [ "${STATUS}" = "Success" ]; then
167         if [ "${REMOVE_ON_SUCCESS}" = "Yes" -o "${REMOVE_ON_SUCCESS}" = "Y" ]; then
168             /bin/rm -rf "./${build_name}"
169         fi
170     fi
171     do_log "Finished building ${build_name}: ${STATUS}"
172 done
173