Project

General

Profile

Statistics
| Branch: | Revision:

root / utils / autobuild.sh @ 6797046b

History | View | Annotate | Download (2.8 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

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

    
45
CONFIGURATIONS_DIR=utils/configurations
46
CONFIGURATION=
47

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

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

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

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

    
91
# only run the autobuilder for newer revisions than the last one checked
92
if [ $BRANCH_REVISION = $LAST_REVISION ] ; then
93
    exit 0
94
fi
95

    
96
git clone $REPO_URL $CHECKOUT_DIR || cleanup 1
97

    
98
cd "$CHECKOUT_DIR" || cleanup 1
99

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

    
112
cleanup 0