forked from openSUSE/obs-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·1029 lines (924 loc) · 30 KB
/
build
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Script to build a package. It uses init_buildsystem to setup a chroot
# building tree. This script needs a directory as parameter. This directory
# has to include sources and a spec file.
#
# BUILD_ROOT here the packages will be built
#
# (c) 1997-2006 SuSE GmbH Nuernberg, Germany
test -z "$BUILD_DIR" && BUILD_DIR=/usr/lib/build
test -z "$BUILD_ROOT" && BUILD_ROOT=/var/tmp/build-root
export BUILD_ARCH BUILD_ROOT BUILD_DIR
ccache=0
icecream=0
definesnstuff=()
repos=()
DO_INIT=true
CLEAN_BUILD=false
SPECFILES=()
SRCDIR=
BUILD_JOBS=
ABUILD_TARGET_ARCH=
CREATE_BASELIBS=
USEUSEDFORBUILD=
LIST_STATE=
XENIMAGE=
XENSWAP=
XENMEMORY=
RUNNING_IN_XEN=
RPMLIST=
RELEASE=
REASON=
NOROOTFORBUILD=
LOGFILE=
KILL=
CHANGELOG=
export PATH=$BUILD_DIR:$PATH
# This is for insserv
export YAST_IS_RUNNING=instsys
unset LANGUAGE
unset LANG
export LC_ALL=POSIX
umask 022
echo_help () {
cat << EOT
Some comments for build
-----------------------
With build you can create rpm packages. They will be built in a chroot
system. This chroot system will be setup automatically. Normally you can
simply call build with a spec file as parameter - nothing else has to be
set.
If you want to set the directory were the chroot system will be setup
(at the moment it uses $BUILD_ROOT),
simply set the the environment variable BUILD_ROOT.
Example:
export BUILD_ROOT=/var/tmp/mybuildroot
Normally build builds the complete package including src.rpm (rpmbuild -ba).
If you want let build only make the binary package, simply set
export BUILD_RPM_BUILD_STAGE=-bb
(or -bc, -bp, -bi, ... see "Maximum RPM" for more details [*]).
When the build command succeeds, the rpm files can be found under
$BUILD_ROOT/usr/src/packages/RPMS/
Known Parameters:
--help You already got it :)
--clean Delete old build root before initializing it
--no-init Skip initialization of build root and start with build
immediately.
--rpms path1:path2:...
Specify path where to find the RPMs for the build system
--arch arch1:arch2:...
Specify what architectures to select from the RPMs
--useusedforbuild
Do not expand dependencies but search the specfile for
usedforbuild lines.
--verify Run verify when initializing the build root
--extra-packs pack
Also install package 'pack'
--root rootdir
Use 'rootdir' to setup chroot environment
--baselibs Create -32bit/-64bit/-x86 rpms for other architectures
--list-state
List rpms that would be used to create a fresh build root.
Does not create the build root or perform a build.
--with X
enable feature X for build
--without X
disable feature X for build
--define 'X Y'
define macro X with value Y
--ccache
use ccache to speed up rebuilds
--icecream N
use N parallel build jobs with icecream
Remember to have fun!
[*] Maximum RPM: http://www.rpm.org/max-rpm/
EOT
}
usage () {
echo "Usage: `basename $0` [--no-init|--clean|--rpms path|--verify|--help] [dir-to-build|spec-to-build]"
cleanup_and_exit 1
}
function clean_build_root () {
test -n "$BUILD_ROOT" && {
umount -n $BUILD_ROOT/proc 2> /dev/null
umount -n $BUILD_ROOT/dev/pts 2> /dev/null
umount -n $BUILD_ROOT/mnt 2> /dev/null
rm -rf $BUILD_ROOT/*
}
}
#
# cleanup_and_exit
#
cleanup_and_exit () {
test -z "$1" && set 0
if test -n "$RUNNING_IN_XEN" ; then
cd /
if test -n "$XENSWAP" -a -e "$XENSWAP" ; then
swapoff "$XENSWAP"
echo -n "BUILDSTATUS$1" >"$XENSWAP"
fi
exec >&0 2>&0 # so that the logging tee finishes
sleep 1 # wait till tee terminates
kill -9 -1 # goodbye cruel world
exec /bin/bash -c 'mount -n -o remount,ro / ; halt -f'
halt -f
fi
exit $1
}
shellquote()
{
for arg; do
arg=${arg/\$/\\\$}
arg=${arg/\"/\\\"}
arg=${arg/\`/\\\`}
arg=${arg/\\/\\\\}
echo -n " \"$arg\""
done
}
# create a shell script from command line. Used for preserving arguments
# through /bin/su -c
toshellscript()
{
echo "#!/bin/sh -x"
echo -n exec
shellquote "$@"
echo
}
setupccache()
{
if [ "$ccache" = 1 ]; then
if mkdir -p $BUILD_ROOT/var/lib/build/ccache/bin; then
for i in gcc g++ cc c++; do
# ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
rm -f $BUILD_ROOT/var/lib/build/ccache/bin/$i
test -e $BUILD_ROOT/usr/bin/$i || continue
echo '#! /bin/sh' > $BUILD_ROOT/var/lib/build/ccache/bin/$i
echo "test -e /usr/bin/$i || exit 1" > $BUILD_ROOT/var/lib/build/ccache/bin/$i
echo 'export PATH=/opt/icecream/bin:/usr/bin:$PATH' >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
echo "ccache $i \"\$@\"" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
chmod 755 $BUILD_ROOT/var/lib/build/ccache/bin/$i
echo "Installed ccache wrapper as $BUILD_ROOT/var/lib/build/ccache/bin/$i"
done
fi
mkdir -p "$BUILD_ROOT"/.ccache
chroot "$BUILD_ROOT" chown -R "$BUILD_USER" "/.ccache"
echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
else
rm -f "$BUILD_ROOT$builduserhome"/bin/{gcc,g++,cc,c++}
rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
fi
}
setupicecream()
{
if [ "$icecream" -eq 0 ]; then
rm -rf "$BUILD_ROOT"/var/run/icecream
rm -f "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
return
fi
if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then
echo "*** icecream package not installed ***"
false
return
fi
echo "using icecream with $icecream jobs"
if [ "$ccache" -ne 1 ]; then
echo 'export PATH=/opt/icecream/bin:$PATH' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
else
echo 'export CCACHE_PATH=/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
fi
local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
icecc_vers=${icecc_vers//$BUILD_ROOT/}
# XXX use changelog like autobuild does instead?
# only run create-env if compiler or glibc changed
if [ -z "$icecc_vers" \
-o ! -e "$BUILD_ROOT/$icecc_vers" \
-o "$BUILD_ROOT/usr/bin/gcc" -nt "$BUILD_ROOT/$icecc_vers" \
-o "$BUILD_ROOT/usr/bin/g++" -nt "$BUILD_ROOT/$icecc_vers" \
-o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
-o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers" ]
then
rm -rf $BUILD_ROOT/var/run/icecream
mkdir -p $BUILD_ROOT/var/run/icecream
if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
createenv=/usr/bin/create-env
elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
else
echo "create-env not found"
false
return
fi
chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv"
icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
icecc_vers=${icecc_vers//$BUILD_ROOT/}
else
echo "reusing existing icecream environment $icecc_vers"
fi
if [ -n "$icecc_vers" ]; then
echo "export ICECC_VERSION=$icecc_vers" >> "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
fi
}
setmemorylimit()
{
if [ -n "$RUNNING_IN_XEN" ]; then
return
fi
local mem
while read mem; do
case "$mem" in
MemTotal:*)
set -- $mem
eval "mem=\$(($2/3*2))"
ulimit -v $mem
echo "Memory limit set to ${mem}KB"
break;
;;
esac
done < <(cat /proc/meminfo) # cat for proc stuff
}
function create_baselibs {
echo "... creating baselibs"
BRPMS=
for RPM in $BUILD_ROOT$TOPDIR/RPMS/*/*.rpm ; do
BRPMS="$BRPMS ${RPM#$BUILD_ROOT}"
done
BASELIBS_CFG=
if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
fi
if test -f $BUILD_ROOT/usr/lib/build/mkbaselibs ; then
if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
fi
chroot $BUILD_ROOT /usr/lib/build/mkbaselibs -c /usr/lib/build/baselibs_global.conf $BASELIBS_CFG $BRPMS || cleanup_and_exit 1
else
# use external version
rm -rf $BUILD_ROOT/.mkbaselibs
mkdir -p $BUILD_ROOT/.mkbaselibs
cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs
cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs
if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf ; then
cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf
BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf"
fi
chroot $BUILD_ROOT /.mkbaselibs/mkbaselibs -c /.mkbaselibs/baselibs_global.conf $BASELIBS_CFG $BRPMS || cleanup_and_exit 1
rm -rf $BUILD_ROOT/.mkbaselibs
fi
}
detect_xen_2nd_stage()
{
if ! test "$0" = "/.build/build" ; then
return 1
fi
echo "XEN 2nd stage started"
BUILD_ROOT=/
BUILD_DIR=/.build
. $BUILD_DIR/build.data
echo "machine type: `uname -m`"
if test "$PERSONALITY" != 0 -a -z "$PERSONALITY_SET" ; then
export PERSONALITY_SET=true
echo "switching personality to $PERSONALITY..."
# this is 32bit perl/glibc, thus the 32bit syscall number
exec perl -e 'syscall(136, '$PERSONALITY') == -1 && warn("personality: $!\n");exec "/.build/build" || die("/.build/build: $!\n")'
fi
PATH=$BUILD_DIR:$PATH
RUNNING_IN_XEN=true
mount -orw -n -tproc none /proc 2>/dev/null
mount -n -o remount,rw /
if test -n "$XENSWAP" ; then
for i in 1 2 3 4 5 6 7 8 9 10 ; do
test -e "$XENSWAP" && break
test $i = 1 && echo "waiting for $XENSWAP to appear"
echo -n .
sleep 1
done
test $i = 1 || echo
fi
umount -l /dev 2>/dev/null
if test -n "$XENSWAP" ; then
rm -f "$XENSWAP"
umask 027
mknod "$XENSWAP" b 3 2
umask 022
swapon -v "$XENSWAP" || exit 1
fi
HOST="$MYHOSTNAME"
return 0
}
set_build_arch()
{
if [ -z "$BUILD_ARCH" ]; then
BUILD_ARCH=`uname -m`
test i686 = "$BUILD_ARCH" && BUILD_ARCH=i586 # XXX: why?
fi
case $BUILD_ARCH in
i686) BUILD_ARCH="i686:i586:i486:i386" ;;
i586) BUILD_ARCH="i586:i486:i386" ;;
i486) BUILD_ARCH="i486:i386" ;;
x86_64) BUILD_ARCH="x86_64:i686:i586:i486:i386" ;;
esac
if test "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
cpuflags=`grep ^flags /proc/cpuinfo`
cpuflags="$cpuflags "
test "$cpuflags" = "${cpuflags/ cx8 /}" -o "$cpuflags" = "${cpuflags/ cmov /}" && {
echo "Your cpu doesn't support i686 rpms. Exit."
exit 1
}
fi
}
find_spec_files()
{
local spec files
if [ -z "$SPECFILES" ]; then
set -- "`pwd`"
else
set -- "${SPECFILES[@]}"
fi
SPECFILES=()
for spec in "$@"; do
if [ "$spec" = "${spec#/}" ]; then
spec="`pwd`/$spec"
fi
if [ -d "$spec" ]; then
specs=("$spec"/*.spec)
if [ -n "$specs" ]; then
SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
else
specs=("$spec"/*.spec)
if [ -n "$specs" ]; then
SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
fi
fi
else
SPECFILES[${#SPECFILES[@]}]="$spec";
fi
done
if test -z "$SPECFILES"; then
echo no spec files or src rpms found in $@. exit...
cleanup_and_exit 1
fi
}
shopt -s nullglob
if detect_xen_2nd_stage; then
set "/.build-srcdir/$SPECFILE"
else
export HOST
fi
while test -n "$1"; do
PARAM="$1"
ARG="$2"
shift
case $PARAM in
*-*=*)
ARG=${PARAM#*=}
PARAM=${PARAM%%=*}
set -- "----noarg=$PARAM" "$@"
esac
case $PARAM in
*-help|-h)
echo_help
cleanup_and_exit
;;
*-no*init)
DO_INIT=false
;;
*-clean)
CLEAN_BUILD=true
;;
*-kill)
KILL=true
;;
*-rpms)
BUILD_RPMS="$ARG"
if [ -z "$BUILD_RPMS" ] ; then
echo_help
cleanup_and_exit
fi
shift
;;
*-arch)
BUILD_ARCH="$ARG"
shift
;;
*-verify)
export VERIFY_BUILD_SYSTEM=true
;;
*-target)
ABUILD_TARGET_ARCH="$ARG"
shift
;;
*-jobs)
BUILD_JOBS="$ARG"
shift
;;
*-extra*packs|-X)
BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
shift
;;
*-baselibs)
CREATE_BASELIBS=true
;;
*-root)
BUILD_ROOT="$ARG"
shift
;;
*-dist)
BUILD_DIST="$ARG"
export BUILD_DIST
shift
;;
*-xen)
XENIMAGE="$ARG"
shift
;;
*-xenswap)
XENSWAP="$ARG"
shift
;;
*-xenmemory)
XENMEMORY="memory=$ARG"
shift
;;
*-rpmlist)
RPMLIST="--rpmlist $ARG"
BUILD_RPMS=
shift
;;
*-release)
RELEASE="--release $ARG"
shift
;;
*-logfile)
LOGFILE="$ARG"
shift
;;
*-reason)
REASON="$ARG"
shift
;;
*-norootforbuild)
NOROOTFORBUILD=true
;;
*-stage)
BUILD_RPM_BUILD_STAGE="$ARG"
shift
;;
*-useusedforbuild)
USEUSEDFORBUILD="--useusedforbuild"
;;
*-list*state)
LIST_STATE=true
;;
--define|--with|--without)
definesnstuff[${#definesnstuff[@]}]="$PARAM";
definesnstuff[${#definesnstuff[@]}]="$ARG";
shift
;;
--repository)
if [ -z "$ARG" ] ; then
echo_help
cleanup_and_exit
fi
repos[${#repos[@]}]="$PARAM";
repos[${#repos[@]}]="$ARG";
shift
;;
--icecream)
if [ -z "$ARG" ] ; then
echo "--icecream needs an argument" >&2
echo_help
cleanup_and_exit 1
fi
icecream="$ARG"
BUILD_JOBS="$ARG"
shift
;;
--ccache)
ccache=1
;;
----noarg)
echo "$ARG does not take an argument"
cleanup_and_exit
;;
*-changelog)
CHANGELOG=true
;;
-*)
echo Unknown Option "$PARAM". Exit.
cleanup_and_exit 1
;;
*)
SPECFILES[${#SPECFILES[@]}]="$PARAM";
;;
esac
done
test -z "$LIST_STATE" -a "$UID" != 0 && {
echo You have to be root to use $0. Exit.
cleanup_and_exit 1
}
if [ -z "$RPMLIST" ]; then
for i in ${BUILD_RPMS//:/ /}; do
repos[${#repos[@]}]='--repository';
repos[${#repos[@]}]="$i";
done
if [ -z "$repos" ]; then
repos=("--repository" "/media/dvd/suse")
fi
else
repos=()
fi
set_build_arch
if test -n "$KILL" ; then
test -z "$SRCDIR" || usage
if test -z "$XENIMAGE" ; then
if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
echo "could not kill build in $BUILD_ROOT"
exit 1
fi
else
XENID="${XENIMAGE%/root}"
XENID="${XENID##*/}"
if xm list "build:$XENID" >/dev/null 2>&1 ; then
if ! xm destroy "build:$XENID" ; then
echo "could not kill xen build $XENID"
exit 1
fi
fi
fi
exit 0
fi
find_spec_files
if test -n "$LIST_STATE" ; then
BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
test -d "$BUILD_ROOT" || exit 1
SPECFILE=$SPECFILES # only one specified anyways
if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
rm -rf $BUILD_ROOT/usr/src/packages
mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES $BUILD_ROOT/usr/src/packages/SPECS
rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
echo "could not install $SPECFILE." 2>&1
rm -rf $BUILD_ROOT
cleanup_and_exit 1
}
for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
fi
init_buildsystem --list-state "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
ERR=$?
rm -rf $BUILD_ROOT
cleanup_and_exit $ERR
fi
if test -d "$BUILD_ROOT" ; then
# check if it is owned by root
test -O "$BUILD_ROOT" || {
echo "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
cleanup_and_exit 1
}
else
test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
mkdir $BUILD_ROOT || {
echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
cleanup_and_exit 1
}
fi
if test -n "$XENIMAGE" ; then
umount -n $BUILD_ROOT/proc 2> /dev/null
umount -n $BUILD_ROOT/dev/pts 2> /dev/null
umount -t loop $BUILD_ROOT 2>/dev/null
if test "$CLEAN_BUILD" = true ; then
echo "Creating filesystem on $XENIMAGE"
if ! echo y | mkfs -t reiserfs -f $XENIMAGE >/dev/null 2>&1 ; then
if ! echo y | mkfs -t reiserfs -f $XENIMAGE ; then
cleanup_and_exit 1
fi
fi
fi
mount -oloop $XENIMAGE $BUILD_ROOT || cleanup_and_exit 1
if test -n "$XENSWAP" ; then
dd if=/dev/zero of="$XENSWAP" bs=12 count=1 conv=notrunc 2>/dev/null
mkswap "$XENSWAP"
fi
fi
rm -f $BUILD_ROOT/exit
if test -z "$XENIMAGE" -a -z "$LOGFILE"; then
LOGFILE="$BUILD_ROOT/.build.log"
fi
if test -n "$LOGFILE" ; then
echo logging output to $LOGFILE...
rm -f $LOGFILE
touch $LOGFILE
if test -n "$XENIMAGE" ; then
exec 1> >(exec -a 'build logging tee' perl -e 'open(F,">>",$ARGV[0])||die("$ARGV[0]: $!\n");$|=1;select(F);$|=1;while(<STDIN>){print STDOUT;s/^\r//s;s/\r\n/\n/gs;print F}' $LOGFILE) 2>&1
else
exec 1> >(exec -a 'build logging tee' tee -a $LOGFILE) 2>&1
fi
fi
setmemorylimit
#
# say hello
#
test -z "$HOST" && HOST=`hostname`
echo Using BUILD_ROOT=$BUILD_ROOT
test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
echo Using BUILD_ARCH=$BUILD_ARCH
test -n "$XENIMAGE" && echo "Doing XEN build in $XENIMAGE"
echo
test "$BUILD_ARCH" = all && BUILD_ARCH=
for SPECFILE in "${SPECFILES[@]}" ; do
SRCDIR="${SPECFILE%/*}"
SPECFILE="${SPECFILE##*/}"
cd "$SRCDIR"
echo
echo "$HOST started \"build $SPECFILE\" at `date`."
echo
test -n "$REASON" && echo "$REASON"
echo
#
# first setup building directory...
#
test -s "$SPECFILE" || {
echo "$SPECFILE" is empty. This should not happen...
cleanup_and_exit 1
}
if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
echo processing src rpm `pwd`/$SPECFILE...
TOPDIR=`rpm --eval '%_topdir'`
rm -rf $BUILD_ROOT$TOPDIR
mkdir -p $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SPECS
rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
echo "could not install $SPECFILE."
cleanup_and_exit 1
}
rm -rf $BUILD_ROOT/.build-srcdir
mkdir -p $BUILD_ROOT/.build-srcdir
mv $BUILD_ROOT$TOPDIR/SOURCES/* $BUILD_ROOT/.build-srcdir
mv $BUILD_ROOT$TOPDIR/SPECS/* $BUILD_ROOT/.build-srcdir
MYSRCDIR=$BUILD_ROOT/.build-srcdir
cd $MYSRCDIR || cleanup_and_exit 1
for SPECFILE in *.spec ; do : ; done
else
echo processing specfile `pwd`/$SPECFILE...
MYSRCDIR="$SRCDIR"
fi
ADDITIONAL_PACKS=""
test -n "$BUILD_EXTRA_PACKS" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
test -n "$CREATE_BASELIBS" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
test "$ccache" = '1' && ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
test "$icecream" -gt 1 && ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
if test "$CLEAN_BUILD" = true ; then
clean_build_root
DO_INIT=true
fi
if test -n "$CHANGELOG" -a -z "$RUNNING_IN_XEN" ; then
rm -f $BUILD_ROOT/.build-changelog
case $SPECFILE in
*.dsc) CFFORMAT=debian ;;
*) CFFORMAT=rpm ;;
esac
echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
rm -f $BUILD_ROOT/.build-changelog
fi
fi
if test -n "$XENIMAGE" ; then
# do fist stage of init_buildsystem
echo init_buildsystem --prepare "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $RPMLIST $SPECFILE $ADDITIONAL_PACKS ...
init_buildsystem --prepare "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS || cleanup_and_exit 1
# start up xen, rerun ourself
mkdir -p $BUILD_ROOT/.build
cp -a $BUILD_DIR/. $BUILD_ROOT/.build
if ! test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
rm -rf $BUILD_ROOT/.build-srcdir
mkdir $BUILD_ROOT/.build-srcdir
cp -p "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
MYSRCDIR=$BUILD_ROOT/.build-srcdir
fi
Q="'\''"
echo "SPECFILE='${SPECFILE//\'/$Q}'" > $BUILD_ROOT/.build/build.data
echo "BUILD_JOBS='${BUILD_JOBS//\'/$Q}'" >> $BUILD_ROOT/.build/build.data
echo "BUILD_ARCH='${BUILD_ARCH//\'/$Q}'" >> $BUILD_ROOT/.build/build.data
case $BUILD_DIST in
*/*)
cp $BUILD_DIST $BUILD_ROOT/.build/build.dist
BUILD_DIST=/.build/build.dist
;;
esac
echo "BUILD_DIST='${BUILD_DIST//\'/$Q}'" >> $BUILD_ROOT/.build/build.data
echo "RELEASE='${RELEASE//\'/$Q}'" >> $BUILD_ROOT/.build/build.data
echo "NOROOTFORBUILD='${NOROOTFORBUILD//\'/$Q}'" >> $BUILD_ROOT/.build/build.data
echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
echo "REASON='${REASON//\'/$Q}'" >> $BUILD_ROOT/.build/build.data
echo "CHANGELOG='${CHANGELOG//\'/$Q}'" >> $BUILD_ROOT/.build/build.data
test -n "$XENSWAP" && echo "XENSWAP='/dev/hda2'" >> $BUILD_ROOT/.build/build.data
PERSONALITY_SYSCALL=
PERSONALITY=0
case `perl -V:archname` in
*x86_64*) PERSONALITY_SYSCALL=135 ;;
*i?86*) PERSONALITY_SYSCALL=136 ;;
esac
test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
echo ")" >> $BUILD_ROOT/.build/build.data
echo -n "repos=(" >> $BUILD_ROOT/.build/build.data
shellquote "${repos[@]}" >> $BUILD_ROOT/.build/build.data
echo ")" >> $BUILD_ROOT/.build/build.data
umount $BUILD_ROOT
XMROOT=file:$XENIMAGE
XMROOT=${XMROOT/#file:\/dev/phy:}
XMROOT="disk=$XMROOT,hda1,w"
XMSWAP=
if test -n "$XENSWAP" ; then
XMSWAP=file:$XENSWAP
XMSWAP=${XMSWAP/#file:\/dev/phy:}
XMSWAP="disk=$XMSWAP,hda2,w"
fi
XENID="${XENIMAGE%/root}"
XENID="${XENID##*/}"
echo "starting xen virtual machine"
if test "$PERSONALITY" != 0 ; then
# have to switch back to PER_LINUX to make xm work
perl -e 'syscall('$PERSONALITY_SYSCALL', 0); exec(@ARGV) || die("$ARGV[0]: $!\n")' xm create -c $BUILD_DIR/xen.conf name="build:$XENID" $XENMEMORY $XMROOT $XMSWAP extra="init=/.build/build panic=1 console=ttyS0"
else
xm create -c $BUILD_DIR/xen.conf name="build:$XENID" $XENMEMORY $XMROOT $XMSWAP extra="init=/.build/build panic=1 console=ttyS0"
fi
if test -n "$XENSWAP" ; then
BUILDSTATUS=`dd if="$XENSWAP" bs=12 count=1 2>/dev/null`
case $BUILDSTATUS in
BUILDSTATUS[0-9])
exit ${BUILDSTATUS#BUILDSTATUS}
;;
esac
exit 1
fi
exit 0
fi
if test "$DO_INIT" = true ; then
echo init_buildsystem "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $RPMLIST $SPECFILE $ADDITIONAL_PACKS ...
init_buildsystem "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS || cleanup_and_exit 1
fi
if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
BUILD_DIST=`cat $BUILD_ROOT/.guessed_dist`
fi
if test "$SPECFILE" = "${SPECFILE%.dsc}" ; then
TOPDIR=`chroot $BUILD_ROOT rpm --eval '%_topdir'`
else
TOPDIR=/usr/src/packages
mkdir -p $BUILD_ROOT$TOPDIR
fi
rm -f $BUILD_ROOT/.build.packages
ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
#
# fix rpmrc if we are compiling for i686
#
test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
sed -e 's/^buildarchtranslate: athlon.*/buildarchtranslate: athlon: i686/' -e 's/^buildarchtranslate: i686.*/buildarchtranslate: i686: i686/' < $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 > $BUILD_ROOT/usr/lib/rpm/rpmrc
fi
#
# check if we want to build with the abuild user
#
BUILD_USER=root
if test "$BUILD_USER" = abuild ; then
egrep '^#[ ]*needsrootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=root
else
egrep '^#[ ]*norootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=abuild
fi
test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
if test $BUILD_USER = abuild ; then
if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
echo 'abuild::99:99:Autobuild:/home/abuild:/bin/bash' >>$BUILD_ROOT/etc/passwd
echo 'abuild::99:' >>$BUILD_ROOT/etc/group
mkdir -p $BUILD_ROOT/home/abuild
chown 99:99 $BUILD_ROOT/home/abuild
fi
if test -f $BUILD_ROOT/etc/shadow ; then
sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
fi
else
if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd
egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new
mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group
rm -rf $BUILD_ROOT/home/abuild
fi
fi
mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
setupicecream
setupccache
#
# now clean up RPM building directories
#
rm -rf $BUILD_ROOT$TOPDIR
for i in BUILD RPMS/`arch` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS ; do
mkdir -p $BUILD_ROOT$TOPDIR/$i
test BUILD_USER = abuild && chown 99:99 $BUILD_ROOT$TOPDIR/$i
done
test -e $BUILD_ROOT/exit && cleanup_and_exit
mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
CHANGELOGARGS=
test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
if test "$SPECFILE" = "${SPECFILE%.dsc}" ; then
# do buildrequires/release substitution
substitutedeps $RELEASE --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" $CHANGELOGARGS "$BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1
# extract macros from configuration
getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
# extract optflags from configuration
getoptflags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" > $BUILD_ROOT/root/.rpmrc
test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
fi
if test -f $BUILD_ROOT/.spec.new ; then
if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
echo -----------------------------------------------------------------
echo I have the following modifications for $SPECFILE:
diff $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new
mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE
else
rm -f $BUILD_ROOT/.spec.new
fi
fi
if test "$SPECFILE" != "${SPECFILE%.dsc}" ; then
rm -rf $BUILD_ROOT$TOPDIR/BUILD
test $BUILD_USER = abuild && chown 99:99 $BUILD_ROOT$TOPDIR
DEB_TRANSFORM=
for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
test -f $f && DEB_TRANSFORM=true
done
if test -n "$DEB_TRANSFORM" ; then
echo "running debian transformer..."
mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
if ! debtransform $CHANGELOGARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
echo "debian transforming failed."
cleanup_and_exit 1
fi
chroot $BUILD_ROOT su -c "dpkg-source -x $TOPDIR/SOURCES.DEB/*.dsc $TOPDIR/BUILD" - $BUILD_USER
else
chroot $BUILD_ROOT su -c "dpkg-source -x $TOPDIR/SOURCES/$SPECFILE $TOPDIR/BUILD" - $BUILD_USER
fi
fi
if test $BUILD_USER = abuild ; then
chown -R 99:99 $BUILD_ROOT$TOPDIR/*
else
chown -R root:root $BUILD_ROOT$TOPDIR/*
fi
cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
echo -----------------------------------------------------------------
if test "$BUILD_USER" = root ; then
echo ----- building $SPECFILE
else
echo ----- building $SPECFILE "(user $BUILD_USER)"
fi
echo -----------------------------------------------------------------
echo -----------------------------------------------------------------
test -n "$RUNNING_IN_XEN" && ifconfig lo 127.0.0.1 up
test -n "$RUNNING_IN_XEN" -a -n "$MYHOSTNAME" && hostname "$MYHOSTNAME"
BUILD_SUCCEDED=false
if test "$SPECFILE" = "${SPECFILE%.dsc}" ; then
test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
# XXX: move _srcdefattr to macro file?
rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--eval" "%define _srcdefattr (-,root,root)")
if [ -n "$ABUILD_TARGET_ARCH" ]; then
rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET_ARCH"
fi
if [ -n "$BUILD_JOBS" ]; then
rpmbopts[${#rpmbopts[@]}]='--eval'
rpmbopts[${#rpmbopts[@]}]="%define jobs $BUILD_JOBS"
fi
rpmbuild=rpmbuild
test -x $BUILD_ROOT/usr/lib/rpm/rpmi || rpmbuild=rpm
# su involves a shell which would require even more
# complicated quoting to bypass than this