158
|
1 |
#!/bin/bash
|
|
2 |
|
|
3 |
# Simple Unix shell script to build STX:LIBJAVA using Jenkins CI
|
|
4 |
# Actually, it is used on Windows (with UnxUtils) as well.
|
|
5 |
|
|
6 |
PROJECT="Mercurial Support"
|
|
7 |
|
|
8 |
# Determine operating system, bit simple but works
|
|
9 |
if [ "$OS" == "Windows_NT" ]; then
|
|
10 |
WIN32=1
|
|
11 |
UNIX=0
|
|
12 |
else
|
|
13 |
WIN32=0
|
|
14 |
UNIX=1
|
|
15 |
fi
|
|
16 |
|
|
17 |
# Utility functions
|
|
18 |
|
|
19 |
function mk {
|
|
20 |
if [ "$WIN32" == "1" ]; then
|
|
21 |
cmd /C bmake.bat $1 $2
|
|
22 |
else
|
|
23 |
if [ ! -f makefile ]; then
|
|
24 |
if [ -f Makefile ]; then
|
|
25 |
make mf || error "Failed to generate makefile (make mf)"
|
|
26 |
else
|
|
27 |
make -f Makefile.init mf || error "Failed to generate makefile (make -f Makefile.init mf)"
|
|
28 |
fi
|
|
29 |
fi
|
|
30 |
make $1 $2 || error "Make failed"
|
|
31 |
fi
|
|
32 |
}
|
|
33 |
|
|
34 |
function sunit {
|
|
35 |
pushd stx/goodies/builder/reports
|
|
36 |
info "Running tests for $1"
|
|
37 |
if [ "$WIN32" == "1" ]; then
|
|
38 |
cmd /C report-runner.bat -D . -r Builder::TestReport -p "$1" || error "Failed to run reports"
|
|
39 |
else
|
|
40 |
(echo "" | ./report-runner.sh -D . -r Builder::TestReport -p "$1") || error "Failed to run reports"
|
|
41 |
fi
|
|
42 |
popd
|
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
function info {
|
|
47 |
echo "[INF] $1"
|
|
48 |
if [ ! -z "$2" ]; then
|
|
49 |
echo " $2"
|
|
50 |
fi
|
|
51 |
}
|
|
52 |
|
|
53 |
function error {
|
|
54 |
echo "[ERR] $1"
|
|
55 |
if [ ! -z "$2" ]; then
|
|
56 |
echo " $2"
|
|
57 |
fi
|
|
58 |
exit 1
|
|
59 |
}
|
|
60 |
|
|
61 |
# Main function
|
|
62 |
function main {
|
|
63 |
pushd "$BUILD"
|
|
64 |
if [ -z "$1" ]; then
|
|
65 |
info "Checking out..."
|
|
66 |
checkout
|
|
67 |
info "Compiling..."
|
|
68 |
compile
|
|
69 |
info "Running tests..."
|
|
70 |
runtests
|
|
71 |
else
|
|
72 |
case "$1" in
|
|
73 |
checkout)
|
|
74 |
info "Checking out..."
|
|
75 |
checkout;;
|
|
76 |
compile)
|
|
77 |
info "Compiling..."
|
|
78 |
compile;;
|
|
79 |
tests)
|
|
80 |
info "Running tests..."
|
|
81 |
runtests;;
|
|
82 |
test)
|
|
83 |
info "Running tests..."
|
|
84 |
runtests;;
|
|
85 |
*)
|
|
86 |
error "Invalid command ($1)"
|
|
87 |
esac
|
|
88 |
fi
|
|
89 |
popd
|
|
90 |
exit 0
|
|
91 |
}
|
|
92 |
|
|
93 |
# Setup...
|
|
94 |
if [ "$WIN32" == "1" ]; then
|
|
95 |
# WINDOWS
|
|
96 |
# MUST export this, otherwise libjpeg fails to build!!!"
|
|
97 |
if [ -z "$BCB"]; then
|
|
98 |
export BCB="C:\Borland\BCC55"
|
|
99 |
fi
|
|
100 |
# To make cvs/ssh happy
|
|
101 |
if [ -z "$CVS_RSH" ]; then
|
|
102 |
export CVS_RSH=plink
|
|
103 |
fi
|
|
104 |
# Set home
|
|
105 |
export HOME=$USERPROFILE
|
|
106 |
else
|
|
107 |
# LINUX
|
|
108 |
# to get Mercurial on build slave
|
|
109 |
export PATH=$PATH:/home/vrany/bin
|
|
110 |
fi
|
|
111 |
|
|
112 |
if [ -z "$CVSROOT" ]; then
|
|
113 |
error "CVSROOT not set!"
|
|
114 |
fi
|
|
115 |
|
|
116 |
# Sorry, it's lot easier for all to have all the messages in EN :-)
|
|
117 |
export LANG=en_GB.UTF-8
|
|
118 |
|
|
119 |
# Functions to override:
|
|
120 |
function checkout {
|
|
121 |
error "You have to override function 'checkout'"
|
|
122 |
}
|
|
123 |
|
|
124 |
function compile {
|
|
125 |
error "You have to override function 'compile'"
|
|
126 |
}
|
|
127 |
|
|
128 |
function runtests {
|
|
129 |
info "No tests specified" "To do so, override function runtests"
|
|
130 |
}
|
|
131 |
|
|
132 |
# When run interactively, Jenkins env variables
|
|
133 |
# may not be set...
|
|
134 |
if [ -z "$WORKSPACE" ]; then
|
|
135 |
WORKSPACE="$PWD"
|
|
136 |
INTERACTIVE=1
|
|
137 |
else
|
|
138 |
INTERACTIVE=0
|
|
139 |
fi
|
|
140 |
|
|
141 |
if [ "$INTERACTIVE" == "0" ]; then
|
|
142 |
if [ "$WIN32" == "1" ]; then
|
|
143 |
WORKSPACE="$PWD"
|
|
144 |
fi
|
|
145 |
fi
|
|
146 |
|
|
147 |
if [ -z "$BUILD_NUMBER" ]; then
|
|
148 |
BUILD_NUMBER=$(date +%Y_%m_%d_interactive)
|
|
149 |
fi
|
|
150 |
|
|
151 |
BUILD="."
|
|
152 |
|
|
153 |
|
|
154 |
echo "INFO: BUILD=\"$BUILD\""
|
|
155 |
|
|
156 |
if [ -d "$BUILD" ]; then
|
|
157 |
if [ "$BUILD" != "." ]; then
|
|
158 |
info "Build directory already exists!"
|
|
159 |
fi
|
|
160 |
else
|
|
161 |
mkdir -p "$BUILD"
|
|
162 |
fi
|
|
163 |
|
|
164 |
# Checkout
|
|
165 |
function checkout {
|
|
166 |
# Checkout stx
|
|
167 |
if [ ! -d stx ]; then
|
|
168 |
if ! cvs co stx; then
|
|
169 |
error "CVS: Cannot checkout stx";
|
|
170 |
fi
|
|
171 |
else
|
|
172 |
(cd stx && cvs update -d)
|
|
173 |
fi
|
|
174 |
|
|
175 |
# Checkout stx:libscm
|
|
176 |
repo="https://bitbucket.org/janvrany/stx-libscm"
|
|
177 |
if [ ! -d stx/libscm ]; then
|
|
178 |
hg clone "$repo" stx/libscm || error "HG: cannot clone stx:libscm"
|
|
179 |
else
|
|
180 |
hg --cwd stx/libscm pull "$repo" || error "HG: cannot pull stx:libscm"
|
|
181 |
hg --cwd stx/libscm update || error "HG: cannot update stx:libscm"
|
|
182 |
fi
|
|
183 |
}
|
|
184 |
|
|
185 |
|
|
186 |
# Compile
|
|
187 |
function compile {
|
|
188 |
TARGETS1="stx stx/libscm/common stx/libscm/mercurial stx/librun"
|
|
189 |
for target in $TARGETS1; do
|
|
190 |
if ! (cd "$target" && mk); then
|
|
191 |
echo "ERROR: cannot $MAKE in $target"
|
|
192 |
exit 3
|
|
193 |
fi
|
|
194 |
done
|
|
195 |
}
|
|
196 |
|
|
197 |
function runtests {
|
|
198 |
sunit "stx:libscm/mercurial"
|
|
199 |
}
|
|
200 |
|
|
201 |
|
|
202 |
# Now, call main
|
|
203 |
main $1 $2 $3
|