Statistics
| Branch: | Revision:

root / utils / autobuild.sh @ f9b0c192

History | View | Annotate | Download (3.03 KB)

1
#!/bin/bash
2
#
3
# Permission is hereby granted, free of charge, to any person
4
# obtaining a copy of this software and associated documentation
5
# files (the "Software"), to deal in the Software without
6
# restriction, including without limitation the rights to use,
7
# copy, modify, merge, publish, distribute, sublicense, and/or sell
8
# copies of the Software, and to permit persons to whom the
9
# Software is furnished to do so, subject to the following
10
# conditions:
11
#
12
# The above copyright notice and this permission notice shall be
13
# included in all copies or substantial portions of the Software.
14
#
15
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
# OTHER DEALINGS IN THE SOFTWARE.
23

    
24
if test "$1" = ""; then
25
    echo "usage: $0 <recipients>"
26
    exit 1
27
fi
28

    
29
RECIPIENTS=$1
30

    
31
REPO_URL=/projects/horizon/git/horizon-4.git
32
AUTOBUILD_DIR=$HOME/autobuild
33
CHECKOUT_DIR=$AUTOBUILD_DIR/$(date +"%Y-%m-%d-%H%M")
34

    
35
BRANCH_REVISION=-1
36
BRANCH_REVISION_FILE=$AUTOBUILD_DIR/last-revision
37
BRANCH_REVISION=$(git rev-list --max-count=1 HEAD)
38
SUBJECT="[autobuild Horizon 4] "
39

    
40
if [ -e $BRANCH_REVISION_FILE ] ; then
41
    LAST_REVISION=$(cat $BRANCH_REVISION_FILE)
42
else
43
    LAST_REVISION=-1
44
fi
45

    
46
CONFIGURATIONS_DIR=utils/configurations
47
CONFIGURATION=
48

    
49
# helper functions
50
run_program()
51
{
52
    $@ > log.txt 2>&1
53
    if [ $? -eq 0 ] ; then
54
        rm -f log.txt
55
        return 0
56
    else
57
        mail_notify
58
        cleanup 1
59
    fi
60
}
61

    
62
mail_notify()
63
{
64
    cat > $CHECKOUT_DIR/msg.txt <<EOF
65
revision: $BRANCH_REVISION
66
configuration: $CONFIGURATION
67
compiler output:
68
EOF
69
    cat log.txt >> $CHECKOUT_DIR/msg.txt
70
    subject="$SUBJECT FAILED"
71
    mailx -s "$subject" $RECIPIENTS < $CHECKOUT_DIR/msg.txt
72
    cat $CHECKOUT_DIR/msg.txt
73
}
74

    
75
cleanup()
76
{
77
    rm -rf "$CHECKOUT_DIR"
78
    echo $BRANCH_REVISION > $BRANCH_REVISION_FILE
79
    exit $1
80
}
81

    
82
compile()
83
{
84
    # source setenv doesn't work 
85
    omnetpp_root=`pwd`
86
    export PATH=$omnetpp_root/bin:$PATH
87
    export LD_LIBRARY_PATH=$omnetpp_root/lib:$LD_LIBRARY_PATH
88
    run_program "./configure" &&
89
    run_program "make"
90
}
91

    
92
# only run the autobuilder for newer revisions than the last one checked
93
if [ $BRANCH_REVISION = $LAST_REVISION ] ; then
94
    subject="$SUBJECT SKIPPED: Repository unchanged"
95
    echo " " | mailx -s "$subject" $RECIPIENTS
96
    exit 0
97
fi
98

    
99
git clone $REPO_URL $CHECKOUT_DIR || cleanup 1
100

    
101
cd "$CHECKOUT_DIR" || cleanup 1
102

    
103
#
104
# use different configurations to build Horizon
105
#
106
for config in `ls -1 $CONFIGURATIONS_DIR`
107
do
108
    echo $config
109
    cp $CONFIGURATIONS_DIR/$config configure.user
110
    CONFIGURATION=$config
111
    compile
112
    run_program "make clean"
113
done
114

    
115
subject="$SUBJECT SUCCESS: All configurations successfully built"
116
echo " " | mailx -s "$subject" $RECIPIENTS
117

    
118
cleanup 0