forked from cfengine/buildscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-remote
executable file
·338 lines (310 loc) · 10.2 KB
/
build-remote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/bin/sh
set -e
. `dirname "$0"`/build-scripts/functions
usage() {
echo
echo "Usage: build-remote [options] <user@host>"
echo
echo "Options:"
echo "-w <user@host>, --wix-machine=<user@host>"
echo " Windows machine used to build WIX installer."
echo "-c <target>, --cross-target=<target>"
echo " Target to compile CFEngine for."
echo "-p, <project>, --project=<project>"
echo " Project to compile (community/nova)."
echo "-b <branch>, --branch=<branch>"
echo " Which branch to use from each repository."
echo "--source=<url>"
echo " Where the git repositories are located. Default is github, but you can"
echo " specify a local path."
echo "--role=<hub|agent>"
echo " Either agent or hub."
echo "--version=<version string>"
echo " Which version string will appear in the binary and in package names."
echo "-t chroot, --test-machine=chroot"
echo " Which machine to use for unsafe tests. Currently chroot inside the"
echo " current machine is the only supported option."
echo "--test-shell"
echo " Instead of running the tests, will drop you directly into a shell"
echo " inside the test environment. You can also trigger this specifically"
echo " for the build-scripts/test script by passing TEST_SHELL=1 in the"
echo " environment. Some useful combos:"
echo " BUILD_TYPE=DEBUG TEST_MACHINE=chroot TEST_SHELL=1 \\"
echo " GAINROOT=env build-scripts/test"
echo " will drop you into a shell in a fresh test environment."
echo " BUILD_TYPE=DEBUG TEST_MACHINE=chroot TEST_SHELL=1 \\"
echo " GAINROOT=env build-scripts/test-on-testmachine"
echo " will drop you into a shell in the existing test environment, in other"
echo " words the existing build artifacts will still be there."
echo " Note that in any case the build will not continue afterwards."
echo "--no-tests"
echo " Do not run tests."
echo "-d /var/cfengine, --workdir=/var/cfengine"
echo " Specify directory which will be CFEngine's workdir. Does not work for"
echo " Windows binaries."
echo "--release|--debug|--docs|--release-and-debug"
echo " With or without debug symbols."
echo "-v, --verbose"
echo " Whether or not to echo the log as the build progresses."
echo
echo "Project defaults to 'nova'"
echo "Branch defaults to 'master', specify --branch=cp if you just want to do simple rsync from the source directories"
echo "workdir defaults to '/var/cfengine'"
echo "Build type defaults to DEBUG. You may request a RELEASE build using --release"
echo "Source defaults to [email protected]:cfengine/"
echo
echo "NOTE: The following environment variables will be carried to the remote machine:"
echo " CC CPPFLAGS CFLAGS LDFLAGS"
echo
echo "WiX machine and cross-compilation are not used by default"
echo
}
opts() {
OPTS=`getopt -o p:b:w:c:d:vht: --long project:,branch:,wix-machine:,cross-target:,workdir:,verbose,source:,role:,version:,release,debug,docs,help,test-machine:,test-shell,no-tests -n build-remote -- "$@"`
eval set -- "$OPTS"
echo "$?"
if [ $? != 0 ]
then
usage
exit 1
fi
DOCS=no
PROJECT=nova
BRANCH=master
BUILD_TYPE=DEBUG
[email protected]:cfengine
BUILD_NUMBER=${BUILD_NUMBER:-unknown}
EXPLICIT_ROLE=
TEST_MACHINE=${TEST_MACHINE:-}
NO_TESTS=${NO_TESTS:-0}
while true
do
case "$1" in
-p|--project)
PROJECT="$2"
shift 2;;
-b|--branch)
BRANCH="$2"
shift 2;;
-w|--wix-machine)
WIX_MACHINE="$2"
shift 2;;
-c|--cross-target)
CROSS_TARGET="$2"
shift 2;;
-d|--workdir)
PREFIX="$2"
shift 2;;
-v|--verbose)
VERBOSE=yes
shift;;
--release)
BUILD_TYPE=RELEASE
shift;;
--debug)
BUILD_TYPE=DEBUG
shift;;
--docs)
DOCS=yes
shift;;
--source)
SOURCE="$2"
shift 2;;
--role)
EXPLICIT_ROLE="$2"
shift 2;;
--version)
EXPLICIT_VERSION="$2"
shift 2;;
-h|--help)
usage
exit 0;;
-t|--test-machine)
TEST_MACHINE="$2"
case "$TEST_MACHINE" in
chroot)
;;
*)
echo "Only --test-machine=chroot is supported"
exit 1
;;
esac
shift 2;;
--test-shell)
TEST_SHELL=1
shift;;
--no-tests)
NO_TESTS=1
shift;;
--)
shift
break;;
*)
echo "Internal error!"
exit 1;;
esac
done
echo "$PROJECT $BRANCH $HOST $BUILD_TYPE $SOURCE"
if [ $# -ne 1 ]; then
usage
exit 1
fi
REPOSITORY=$PROJECT-$BRANCH
HOST=$1
export PROJECT BRANCH WIX_MACHINE CROSS_TARGET HOST BUILD_TYPE BUILD_NUMBER DOCS EXPLICIT_ROLE EXPLICIT_VERSION TEST_MACHINE TEST_SHELL PREFIX
export SCHEDULER=$PROJECT-$BRANCH-localbuild
}
prepare_workdir() {
mkdir -p "workdir-$PROJECT-$BRANCH-$HOST"
rm -rf "workdir-$PROJECT-$BRANCH-$HOST"/*
# In order for tail not to miss any output. If it doesn't exist, there is a small window between
# when it is created and when tail discovers it, where output may be missed.
touch "workdir-$PROJECT-$BRANCH-$HOST"/build-remote.log
SCRIPT="$(readlink -f "$0")"
AUTOBUILD_PATH="$(pwd)/workdir-$PROJECT-$BRANCH-$HOST/build/buildscripts"
export AUTOBUILD_PATH
cd "workdir-$PROJECT-$BRANCH-$HOST"
checkout
}
checkout() {
mkdir -p build
rsync -avr --exclude='workdir-*' ../ build/buildscripts >>rsync.log
REPOS="core masterfiles"
case "$PROJECT" in
nova)
REPOS="$REPOS nova design-center mission-portal"
esac
case "$PROJECT-$BRANCH" in
community-master)
git clone $SOURCE/core build/core
git clone $SOURCE/masterfiles build/masterfiles
(cd build/masterfiles && git checkout $VERSION) || false
git clone $SOURCE/design-center build/design-center
(cd build/design-center && git checkout $VERSION) || false
;;
community-3.4.x)
git clone $SOURCE/core build/core
(cd build/core && git checkout 3.4.x) || false
;;
community-3.3.x)
git clone $SOURCE/core build/core
(cd build/core && git checkout -b 3.3.x remotes/origin/3.3.x || git checkout 3.3.x) || false
;;
community-3.4.*)
VERSION=$BRANCH
git clone $SOURCE/core build/core
(cd build/core && git checkout $VERSION) || false
;;
nova-2.2.2)
VERSION=$BRANCH
git clone $SOURCE/nova build/nova
(cd build/nova && git checkout $VERSION) || false
git clone $SOURCE/core build/core
(cd build/core && git checkout 3.3.6) || false
;;
nova-3.5.x)
VERSION=$BRANCH
git clone $SOURCE/nova build/nova
(cd build/nova && git checkout $VERSION) || false
git clone $SOURCE/core build/core
(cd build/core && git checkout $VERSION) || false
git clone $SOURCE/mission-portal build/mission-portal
git clone $SOURCE/design-center build/design-center
(cd build/design-center && git checkout $VERSION)
;;
nova-2.2.*)
VERSION=$BRANCH
git clone $SOURCE/nova build/nova
(cd build/nova && git checkout $VERSION) || false
git clone $SOURCE/core build/core
(cd build/core && git checkout -b 3.3.x remotes/origin/3.3.x || git checkout 3.3.x) || false
;;
nova-master)
git clone $SOURCE/core build/core
git clone $SOURCE/enterprise build/enterprise
git clone $SOURCE/nova build/nova
git clone $SOURCE/mission-portal build/mission-portal
git clone $SOURCE/design-center build/design-center
git clone $SOURCE/masterfiles build/masterfiles
;;
nova-3.6.x)
VERSION=$BRANCH
git clone $SOURCE/core build/core
(cd build/core && git checkout $VERSION) || false
git clone $SOURCE/nova build/nova
(cd build/nova && git checkout $VERSION) || false
git clone $SOURCE/enterprise build/enterprise
(cd build/enterprise && git checkout $VERSION) || false
git clone $SOURCE/mission-portal build/mission-portal
(cd build/mission-portal && git checkout $VERSION) || false
git clone $SOURCE/design-center build/design-center
(cd build/design-center && git checkout $VERSION) || false
git clone $SOURCE/masterfiles build/masterfiles
(cd build/masterfiles && git checkout $VERSION)
;;
nova-cp)
rsync -avr --exclude='workdir-*' $AUTOBUILD_PATH/ build/buildscripts >>rsync.log
for d in core nova enterprise masterfiles design-center mission-portal
do
rsync -avr $SOURCE/$d build >>rsync.log
done
;;
nova-stable)
git clone $SOURCE/core build/core
(cd build/core && git checkout -b 3.4.x remotes/origin/3.4.x || git checkout 3.4.1n) || false
git clone $SOURCE/nova build/nova
(cd build/nova && git checkout -b 3.0.x remotes/origin/3.0.x || git checkout 3.0.0) || false
git clone $SOURCE/mission-portal build/mission-portal
(cd build/mission-portal && git checkout -b 3.0.x remotes/origin/3.0.x || git checkout 3.0.0) || false
;;
*)
for i in $REPOS
do
git clone $SOURCE/$i build/$i
(cd build/$i && git checkout -b $BRANCH remotes/origin/$BRANCH || git checkout $BRANCH) || false
done
esac
}
build_docs() {
remote_script configure-docs
remote_script compile
remote_script upload-docs
}
build() {
remote_script configure
remote_script compile
case "$BUILD_TYPE" in
RELEASE)
remote_script produce-debug-symbols
;;
esac
if [ "$NO_TESTS" != 1 ]
then
remote_script test
fi
remote_script package
remote_script prepare-results
local_script transfer-results
local_script install-results
local_script clean-results
}
common_build() {
if [ "$VERBOSE" = "yes" ]
then
tail -F --pid=$$ build-remote.log &
fi
local_script autogen
local_script transfer-to-buildmachine
remote_script build-environment-check
remote_script clean-buildmachine
remote_script install-dependencies
case "$DOCS" in
yes)
build_docs;;
no)
build;;
esac
}
opts "$@"
prepare_workdir
common_build