2 # Script to build a package. It uses init_buildsystem to setup a chroot
3 # building tree. This script needs a directory as parameter. This directory
4 # has to include sources and a spec file.
6 # BUILD_ROOT here the packages will be built
8 # (c) 1997-2008 SuSE GmbH Nuernberg, Germany
10 test -z "$BUILD_DIR" && BUILD_DIR=/usr/lib/build
11 test -z "$BUILD_ROOT" && BUILD_ROOT=/var/tmp/build-root
13 export BUILD_ARCH BUILD_HOST_ARCH BUILD_ROOT BUILD_RPMS BUILD_DIR BUILD_DEBUG
23 # defaults for vm_img_mkfs
24 vm_img_mkfs_ext4='mkfs.ext4 -m 0 -q -F'
25 vm_img_tunefs_ext4='tune2fs -c 0 -O ^has_journal'
26 vm_img_mkfs_ext3='mkfs.ext3 -m 0 -q -F'
27 vm_img_tunefs_ext3='tune2fs -c 0 -o journal_data_writeback'
28 vm_img_mkfs_ext2='mkfs.ext2 -m 0 -q -F'
29 vm_img_tunefs_ext2='tune2fs -c 0'
30 vm_img_mkfs_reiserfs='mkreiserfs -q -f'
31 vm_img_mkfs_btrfs='mkfs.btrfs'
33 vm_kernel=/boot/vmlinuz
34 vm_initrd=/boot/initrd
35 qemu_bin=/usr/bin/qemu
36 uml_kernel=/boot/vmlinux-um
37 uml_initrd=/boot/initrd-um
39 kvm_bin=/usr/bin/qemu-kvm
40 # whether we have virtio support
43 # guest visible console device name
46 # need to restore build root owner for non-root builds
49 # Default uid:gid for the build user
70 VMDISK_FILESYSTEM=ext3
71 # settings are for speed and not data safety, we format anyway on next run
72 VMDISK_MOUNT_OPTIONS='-o data=writeback,nobarrier,commit=150,noatime'
94 # list of archs which need emulator initialization
95 : ${EMULATOR_ARCHS:="armv4l armv5l armv6l armv7l armv5el armv6el armv7el armv7hl armv8el mips mipsel mips64 mips64el ppc ppc64 sh4 sparc sparc64 s390 s390x"}
98 # list of devices registered by binfmt handlers in /proc/sys/fs/binfmt_misc
99 : ${EMULATOR_DEVS:="arm armeb mips mipsel mips64 mips64el ppc sh4 sh4eb sparc s390x"}
102 # This is for insserv
103 export YAST_IS_RUNNING=instsys
113 Some comments for build
114 -----------------------
116 With build you can create rpm packages. They will be built in a chroot
117 system. This chroot system will be setup automatically. Normally you can
118 simply call build with a spec file as parameter - nothing else has to be
121 If you want to set the directory were the chroot system will be setup
122 (at the moment it uses $BUILD_ROOT),
123 simply set the the environment variable BUILD_ROOT.
127 export BUILD_ROOT=/var/tmp/mybuildroot
130 Normally build builds the complete package including src.rpm (rpmbuild -ba).
131 If you want let build only make the binary package, simply set
133 export BUILD_RPM_BUILD_STAGE=-bb
135 (or -bc, -bp, -bi, ... see "Maximum RPM" for more details [*]).
137 When the build command succeeds, the rpm files can be found under
138 $BUILD_ROOT/usr/src/packages/RPMS/
143 --help You already got it :)
145 --clean Delete old build root before initializing it
147 --no-init Skip initialization of build root and start with build
150 --no-checks Do not run post-build checks
153 Use package repository at PATH. Supported formats are
155 Alternatively zypp://NAME specifies the zypp
156 repository NAME. The repo must be refreshed with zypp
157 so package meta data is available locally. With emtpy
158 NAME all enabled repositories are used.
159 a url can specify a remote repo.
161 --rpms path1:path2:...
162 Specify path where to find the RPMs for the build system
164 --arch arch1:arch2:...
165 Specify what architectures to select from the RPMs
167 --verify Run verify when initializing the build root
170 Also install package 'pack'
173 Use 'rootdir' to setup chroot environment
176 Use 'cachedir' to cache remote repo's packages, the
177 default cache dir is /var/cache/build, every repo
178 given by --repository corresponds to a subdir named
179 as md5sum of its repo url, forx eaxmple:
180 /var/cache/build/3e8ea9b47808629414a0cebc33ea285e
182 --oldpackages oldpackagesdir
183 Define a directory with a former build
185 --baselibs Create -32bit/-64bit/-x86 rpms for other architectures
188 List rpms that would be used to create a fresh build root.
189 Does not create the build root or perform a build.
192 enable feature X for build
195 disable feature X for build
198 define macro X with value Y
201 use ccache to speed up rebuilds
204 use N parallel build jobs with icecream
206 Copy overlay filesystem to buildroot after installing
207 all RPMs. This must be a valid directory.
210 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
211 inside the buildroot using rsync.
212 It will "%define RSYNCDONE 1" for handling %setup in your
216 %setup -n aaa_base -T -D -b 5 -b 7
218 %setup -n aaa_base -b 5 -b 7
221 --rsync-dest RSYNCDEST
222 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
223 inside the buildroot using rsync.
226 Specify the uid and gid to use for the abuild user.
227 This is useful if you are hacking in the buildroot.
228 This must be set to the same value if the buildroot is re-used.
231 Use virtual machine instead of chroot
232 TYPE is one of xen|kvm|uml|qemu|lxc
235 Use FILE as disk for virtual machine.
236 Defaults to \$BUILD_ROOT.img if unset
239 Use FILE as swap space for virtual machine. The swap space is
240 also used for retrieving packages from the VM so it's size must be
243 --vm-disk-size SIZEINMB
244 --vm-swap-size SIZEINMB
245 --vm-disk-filesystem TYPE
246 Defaults for automatic setup of VM root/swap files
250 Kernel and initrd to use for VM (kvm and qemu only)
253 enable creation of a debuginfo package
255 Remember to have fun!
257 [*] Maximum RPM: http://www.rpm.org/max-rpm/
261 echo "Usage: `basename $0` [--no-init|--clean|--rpms path|--verify|--help] [dir-to-build|spec-to-build]"
267 # return values: 0 -> success, new packages built
268 # 1 -> error, build failed
269 # 2 -> successfull build, but no changes to former built packages
270 # 3 -> something wrong with build host
272 cleanup_and_exit () {
274 test -z "$1" && set 0
275 rm -f $BUILD_ROOT/exit
276 if test "$1" -eq 1 -a -x /bin/df ; then
277 # okay, it failed, but maybe because disk space?
278 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
282 if test -n "$RUNNING_IN_VM" ; then
283 chown $browner $BUILD_ROOT
285 if test -n "$VM_SWAP" -a -e "$VM_SWAP" ; then
286 swapoff "$VM_SWAP" 2>/dev/null
287 echo -n "BUILDSTATUS$1" >"$VM_SWAP"
289 exec >&0 2>&0 # so that the logging tee finishes
290 sleep 1 # wait till tee terminates
291 if test "$VM_TYPE" != lxc; then
292 kill -9 -1 # goodbye cruel world
293 if ! test -x /sbin/halt ; then
294 test -e /proc/sysrq-trigger || mount -n -tproc none /proc
296 sleep 2 # like halt does
297 if test -e /proc/sysrq-trigger; then
298 echo o > /proc/sysrq-trigger
299 sleep 5 # wait for sysrq to take effect
301 echo "Warning: VM doesn't support sysrq and /sbin/halt not installed"
306 echo "Warning: clean shut down of the VM didn't work"
309 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
310 umount -n $BUILD_ROOT/proc 2>/dev/null || true
311 umount -n $BUILD_ROOT/dev/pts 2>/dev/null || true
312 test "$VM_IMAGE" = 1 && VM_IMAGE=
313 [ -n "$VM_IMAGE" ] && umount $BUILD_ROOT 2>/dev/null || true
315 # echo "pid $$ exit $1"
335 # create a shell script from command line. Used for preserving arguments
347 if [ "$ccache" = 1 ]; then
348 if mkdir -p $BUILD_ROOT/var/lib/build/ccache/bin; then
349 for i in $(ls $BUILD_ROOT/usr/bin | grep -E '^(cc|gcc|[cg][+][+])([-]?[234][.]?[0-9])*$'); do
350 # ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
351 rm -f $BUILD_ROOT/var/lib/build/ccache/bin/$i
352 test -e $BUILD_ROOT/usr/bin/$i || continue
353 echo '#! /bin/sh' > $BUILD_ROOT/var/lib/build/ccache/bin/$i
354 echo "test -e /usr/bin/$i || exit 1" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
355 echo 'export PATH=/opt/icecream/bin:/usr/bin:$PATH' >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
356 echo "ccache $i \"\$@\"" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
357 chmod 755 $BUILD_ROOT/var/lib/build/ccache/bin/$i
358 echo "Installed ccache wrapper as $BUILD_ROOT/var/lib/build/ccache/bin/$i"
361 mkdir -p "$BUILD_ROOT"/.ccache
362 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/.ccache"
363 echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
364 echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
366 rm -f "$BUILD_ROOT$builduserhome"/bin/{gcc,g++,cc,c++}
367 rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
373 if [ "$icecream" -eq 0 ]; then
374 rm -rf "$BUILD_ROOT"/var/run/icecream
375 rm -f "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
379 if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then
380 echo "*** icecream package not installed ***"
385 echo "using icecream with $icecream jobs"
387 if [ "$ccache" -ne 1 ]; then
388 echo 'export PATH=/opt/icecream/bin:$PATH' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
390 echo 'export CCACHE_PATH=/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
393 local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
394 icecc_vers=${icecc_vers//$BUILD_ROOT/}
396 # XXX use changelog like autobuild does instead?
397 # only run create-env if compiler or glibc changed
398 if [ -z "$icecc_vers" \
399 -o ! -e "$BUILD_ROOT/$icecc_vers" \
400 -o "$BUILD_ROOT/usr/bin/gcc" -nt "$BUILD_ROOT/$icecc_vers" \
401 -o "$BUILD_ROOT/usr/bin/g++" -nt "$BUILD_ROOT/$icecc_vers" \
402 -o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
403 -o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers" ]
405 rm -rf $BUILD_ROOT/var/run/icecream
406 mkdir -p $BUILD_ROOT/var/run/icecream
407 if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
408 createenv=/usr/bin/create-env
409 elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
410 createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
411 elif [ -e "$BUILD_ROOT"/usr/lib64/icecc/icecc-create-env ]; then
412 createenv="/usr/lib64/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
414 echo "create-env not found"
418 chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv" || cleanup_and_exit 1
419 icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
420 icecc_vers=${icecc_vers//$BUILD_ROOT/}
422 echo "reusing existing icecream environment $icecc_vers"
424 if [ -n "$icecc_vers" ]; then
425 echo "export ICECC_VERSION=$icecc_vers" >> "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
431 if [ -n "$VM_IMAGE" -o -n "$RUNNING_IN_VM" ]; then
439 eval "mem=\$(($2/3*4))"
441 echo "Memory limit set to ${mem}KB"
445 done < <(cat /proc/meminfo) # cat for proc stuff
454 if test "$BUILDTYPE" == "dsc" ; then
457 if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
458 BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
460 if test -e $BUILD_ROOT/usr/lib/build/baselibs_global.conf; then
461 BASELIBS_GLOBAL="-c /usr/lib/build/baselibs_global.conf"
466 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
467 # don't use -R as extracted sources, build root etc might be below $TOPDIR
468 chown "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"/* "$BUILD_ROOT$TOPDIR"/RPMS/* || true
470 local mkbaselibs="/usr/lib/build/mkbaselibs"
472 # $BUILD_DIR is set to /.build when using a vm. So we need to
473 # hardcode /usr/lib/build instead of $BUILD_DIR to prefer
474 # mkbaselibs from the distro.
475 if test -f $BUILD_ROOT$mkbaselibs; then
476 if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
477 BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
480 if test "$CREATE_BASELIBS" = 'internal'; then
481 echo "Warning: mkbaselibs missing in build root, skipping baselibs"
484 # use external version
485 whichone=" (external)"
486 mkbaselibs="/.mkbaselibs/mkbaselibs"
487 rm -rf $BUILD_ROOT/.mkbaselibs
488 mkdir -p $BUILD_ROOT/.mkbaselibs
489 cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs/
490 if test "$BUILDTYPE" == "dsc" ; then
491 cp -f $BUILD_DIR/baselibs_global-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
492 cp -f $BUILD_ROOT$TOPDIR/SOURCES/baselibs-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs-deb.conf
493 BASELIBS_CFG="-c /.mkbaselibs/baselibs-deb.conf"
495 cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
496 if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf; then
497 cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf
498 BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf"
501 if test -e $BUILD_ROOT/.mkbaselibs/baselibs_g.conf; then
502 BASELIBS_GLOBAL="-c /.mkbaselibs/baselibs_g.conf"
505 echo "... creating baselibs$whichone"
506 chroot $BUILD_ROOT su -c "$mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG ${pkgs[*]#$BUILD_ROOT}" - $BUILD_USER || cleanup_and_exit 1
507 rm -rf $BUILD_ROOT/.mkbaselibs
515 [ -z "$RUNNING_IN_VM" ] || return 0
516 if [ -z "$old_packages" ]; then
517 rm -rf "$BUILD_ROOT"/.build.oldpackages*
520 for d in "${old_packages[@]}"; do
521 dest="$BUILD_ROOT/.build.oldpackages"
522 test "$i" = 0 || dest="$dest$i"
523 if [ -d "$d" -a "$d" != "$dest" ] ; then
537 eval "mkfs=\"\$vm_img_mkfs_${fs}\""
538 eval "tunefs=\"\$vm_img_tunefs_${fs}\""
540 if test -z "$mkfs"; then
541 echo "filesystem \"$fs\" isn't supported"
546 echo "Creating $fs filesystem on $img"
548 if test -n "$tunefs" ; then
549 $tunefs "$img" || cleanup_and_exit 3
554 detect_vm_2nd_stage()
556 if ! test "$0" = "/.build/build" ; then
559 if test $$ -eq 1 ; then
560 # ignore special init signals if we're init
561 # we're using ' ' instead of '' so that the signal handlers
562 # are reset in the child processes
567 echo "2nd stage started in virtual machine"
570 . $BUILD_DIR/build.data
571 echo "machine type: `uname -m`"
572 if test "$PERSONALITY" != 0 -a -z "$PERSONALITY_SET" ; then
573 export PERSONALITY_SET=true
574 echo "switching personality to $PERSONALITY..."
575 # this is 32bit perl/glibc, thus the 32bit syscall number
576 exec perl -e 'syscall(136, '$PERSONALITY') == -1 && warn("personality: $!\n");exec "/.build/build" || die("/.build/build: $!\n")'
579 mount -orw -n -tproc none /proc
580 if test "$VM_TYPE" != 'lxc'; then
581 mount -n ${VMDISK_MOUNT_OPTIONS},remount,rw /
583 # qemu inside of xen does not work, check again with kvm later before enabling this
584 # if [ -e /dev/kqemu ]; then
585 # # allow abuild user to run qemu
586 # chmod 0666 /dev/kqemu
588 if test -n "$VM_SWAP" ; then
589 for i in 1 2 3 4 5 6 7 8 9 10 ; do
590 test -e "$VM_SWAP" && break
591 test $i = 1 && echo "waiting for $VM_SWAP to appear"
596 # recreate the swap device manually if it didn't exist for some
597 # reason, hardcoded to hda2 atm
598 if ! test -b "$VM_SWAP" ; then
601 mknod "$VM_SWAP" b 3 2
604 swapon -v "$VM_SWAP" || exit 1
614 if [ -z "$SPECFILES" ]; then
617 set -- "${SPECFILES[@]}"
621 if [ "$spec" = "${spec#/}" ]; then
625 if [ -d "$spec" ]; then
626 specs=("$spec"/*.spec)
627 if [ -n "$specs" ]; then
628 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
630 specs=("$spec"/*.spec)
631 if [ -n "$specs" ]; then
632 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
636 SPECFILES[${#SPECFILES[@]}]="$spec";
640 if test -z "$SPECFILES"; then
641 echo no spec files or src rpms found in $@. exit...
646 become_root_or_fail()
648 if [ ! -w /root ]; then
649 echo "You have to be root to use $0" >&2
657 if [ -d "$BUILD_ROOT" ]; then
658 # check if it is owned by root
659 if [ -z "$RUNNING_IN_VM" -a \! -O "$BUILD_ROOT" -a "`stat -c %u $BUILD_ROOT`" -ne 0 ]; then
660 echo "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
664 test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
665 if ! mkdir $BUILD_ROOT; then
666 echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
671 if [ ! -w "$BUILD_ROOT" ]; then
672 echo "Error: BUILD_ROOT=$BUILD_ROOT not writeable, try --clean."
676 rm -rf "$BUILD_ROOT"/.build.packages
677 if [ -z "$VM_TYPE" -a -z "$RUNNING_IN_VM" ]; then
678 # don't touch this in VM
679 rm -rf "$BUILD_ROOT"/.build
680 mkdir -p "$BUILD_ROOT"/.build
686 perl -e 'syscall('$PERSONALITY_SYSCALL', 0); exec(@ARGV) || die("$ARGV[0]: $!\n")' "$@"
695 if [ "$uname" != "ppc" -a "$uname" != "ppc64" ]; then
701 # XXX is this ok for ppc32 hosts? do we care?
702 export kvm_bin="/usr/bin/qemu-system-ppc64"
704 # XXX check host CPU and adjust guest CPU accordingly
705 export KVM_OPTIONS="-enable-kvm -M pseries -cpu 970mp -m 512 -mem-path /hugetlbfs"
706 export VM_KERNEL=/root/obs_kernel/vmlinux
707 export VM_INITRD=/root/obs_kernel/initrd
709 # XXX complain when hugetlbfs is not mounted
716 case `perl -V:archname` in
717 *x86_64*) PERSONALITY_SYSCALL=135 ;;
718 *i?86*) PERSONALITY_SYSCALL=136 ;;
725 if detect_vm_2nd_stage ; then
726 set "/.build-srcdir/$SPECFILE"
730 export PATH=$BUILD_DIR:/sbin:/usr/sbin:$PATH
732 . $BUILD_DIR/common_functions || exit 1
738 if [ -z "$ARG" ]; then
739 echo "$PARAM needs an agrument" >&2
744 while test -n "$1"; do
747 [ "$ARG" = "${ARG#-}" ] || ARG=""
753 set -- "----noarg=$PARAM" "$@"
767 CLEAN_BUILD='--clean'
783 export VERIFY_BUILD_SYSTEM=true
797 BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
807 CREATE_BASELIBS=internal
821 old_packages=("${old_packages[@]}" "$ARG")
829 *-xen|*-kvm|--uml|--qemu)
831 if [ -n "$ARG" ]; then
845 xen|kvm|uml|qemu|lxc) ;;
846 none|chroot) VM_TYPE='' ;;
848 echo "VM $VM_TYPE not supported"
864 *-xenmemory|*-memory)
879 *-vmdisk-rootsize|--vm-disk-size)
881 VMDISK_ROOTSIZE="$ARG"
884 *-vmdisk-swapsize|--vm-swap-size)
886 VMDISK_SWAPSIZE="$ARG"
889 *-vmdisk-filesystem|--vm-disk-filesystem)
891 VMDISK_FILESYSTEM="$ARG"
896 RPMLIST="--rpmlist $ARG"
920 BUILD_RPM_BUILD_STAGE="$ARG"
924 USEUSEDFORBUILD="--useusedforbuild"
929 --define|--with|--without)
931 definesnstuff[${#definesnstuff[@]}]="$PARAM";
932 definesnstuff[${#definesnstuff[@]}]="$ARG";
937 repos[${#repos[@]}]="$PARAM";
938 repos[${#repos[@]}]="$ARG";
944 if [ "$icecream" -gt 0 ]; then
969 echo "$ARG does not take an argument"
993 if test -n "${ABUILD_ID//[0-9:]/}"; then
994 echo "--uid argument must be uid:gid"
997 ABUILD_UID=${ABUILD_ID%:*}
998 ABUILD_GID=${ABUILD_ID#*:}
1009 echo Unknown Option "$PARAM". Exit.
1013 SPECFILES[${#SPECFILES[@]}]="$PARAM";
1018 if test "$VM_TYPE" = "lxc"; then
1023 if test -n "$KILL" ; then
1024 test -z "$SRCDIR" || usage
1025 if test -n "$VM_IMAGE" -a -n "$VM_SWAP" -a -n "$VM_TYPE"; then
1026 # mark job as failed so that we don't extract packages
1027 echo -n "BUILDSTATUS1" >"$VM_SWAP"
1029 (set -C; > "$BUILD_ROOT/exit" 2>/dev/null || true)
1030 if test "$VM_TYPE" = 'lxc'; then
1031 LXCID=${BUILD_ROOT##*/}
1032 lxc-stop -n "$LXCID" || true
1033 lxc-destroy -n "$LXCID"
1034 elif test -z "$VM_IMAGE" ; then
1035 if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
1036 echo "could not kill build in $BUILD_ROOT"
1039 elif test "$VM_TYPE" = 'xen'; then
1040 XENID="${VM_IMAGE%/root}"
1041 XENID="${XENID%/tmpfs}"
1042 XENID="${XENID##*/}"
1043 XENID="${XENID#root_}"
1044 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1045 if ! xm destroy "build_$XENID" ; then
1046 echo "could not kill xen build $XENID"
1050 elif test -n "$VM_TYPE"; then
1051 if ! fuser -k -TERM "$VM_IMAGE"; then
1052 echo "could not kill build in $VM_IMAGE"
1056 echo "don't know how to kill this build job"
1062 if [ "$VM_TYPE" = 'xen' -a -z "$RUNNING_IN_VM" ]; then
1063 # XXX: merge with kvm path?
1064 if [ -n "$VM_KERNEL" ]; then
1065 vm_kernel="$VM_KERNEL"
1066 elif [ -e "/boot/vmlinuz-xen" ]; then
1067 vm_kernel="/boot/vmlinuz-xen"
1069 if [ -n "$VM_INITRD" ]; then
1070 vm_initrd="$VM_INITRD"
1071 elif [ -e "/boot/initrd-xen" ]; then
1072 vm_initrd="/boot/initrd-xen"
1076 if [ "$VM_TYPE" = 'kvm' -a -z "$RUNNING_IN_VM" ]; then
1077 if [ ! -r /dev/kvm -o ! -x "$kvm_bin" ]; then
1078 echo "host doesn't support kvm"
1079 echo "either the kvm kernel-module is not loaded or kvm is not installed or hardware virtualization is deactivated in the BIOS."
1083 if [ -n "$VM_KERNEL" ]; then
1084 vm_kernel="$VM_KERNEL"
1087 # check if a SUSE system with virtio initrd is running
1088 if [ -z "$VM_INITRD" -a -e /etc/sysconfig/kernel ]; then
1089 a=$( source /etc/sysconfig/kernel; echo $INITRD_MODULES )
1093 [ "$i" == "virtio_pci" ] && have_virtio_pci="1"
1094 [ "$i" == "virtio_blk" ] && have_virtio_blk="1"
1096 [ -n "$have_virtio_pci" -a -n "$have_virtio_blk" ] && VM_INITRD="/boot/initrd"
1099 if [ -n "$VM_INITRD" ]; then
1100 vm_initrd="$VM_INITRD"
1102 elif [ -e "${vm_initrd}-build" ]; then
1103 vm_initrd="${vm_initrd}-build"
1106 if [ -L "$vm_initrd" ]; then
1107 vm_initrd=`readlink -f "$vm_initrd"` || cleanup_and_exit 3
1109 vm_initrd_virtio="${vm_initrd}-virtio"
1111 if [ ! -e ${vm_initrd_virtio} -o $vm_kernel -nt ${vm_initrd_virtio} ]; then
1112 mkinitrd_virtio_cmd=(env rootfstype="$VMDISK_FILESYSTEM" \
1113 mkinitrd -d /dev/null \
1114 -m "ext3 ext4 btrfs reiserfs binfmt_misc virtio_pci virtio_blk" \
1116 -i ${vm_initrd_virtio})
1117 if [ ! -w /root -o -n "$RPMLIST" ]; then
1118 echo "No initrd that provides virtio support found. virtio accelleration disabled."
1119 echo "Run the following command as root to enable virtio:"
1120 shellquote "${mkinitrd_virtio_cmd[@]}"
1122 elif /sbin/modinfo virtio_pci >/dev/null 2>&1; then
1123 echo "creating $vm_initrd_virtio"
1124 "${mkinitrd_virtio_cmd[@]}" || cleanup_and_exit 1
1126 vm_initrd="${vm_initrd_virtio}"
1130 vm_initrd="${vm_initrd_virtio}"
1134 if [ "$HOST_ARCH" = ppc ]; then
1135 # KVM on PPC can not run virtio yet, so we need to use the default vio
1139 if [ "$kvm_virtio" = 1 ]; then
1141 qemu_rootdev=/dev/vda
1144 qemu_rootdev=/dev/sda
1148 if [ "$VM_TYPE" = 'qemu' ]; then
1150 qemu_rootdev=/dev/sda
1153 if [ -z "$RPMLIST" -a -z "$RUNNING_IN_VM" ]; then
1154 if [ -z "$repos" -a -z "$BUILD_RPMS" ]; then
1155 repos=(--repository 'zypp://')
1163 if [ -n "$CLEAN_BUILD" ]; then
1169 if test -n "$LIST_STATE" ; then
1170 BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
1171 test -d "$BUILD_ROOT" || cleanup_and_exit 3
1172 SPECFILE=$SPECFILES # only one specified anyways
1173 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1174 rm -rf $BUILD_ROOT/usr/src/packages
1175 mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES $BUILD_ROOT/usr/src/packages/SPECS
1176 rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
1177 echo "could not install $SPECFILE." 2>&1
1181 for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
1183 init_buildsystem --cachedir "$CACHE_DIR" --list-state "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
1186 cleanup_and_exit $ERR
1189 if test -z "$RUNNING_IN_VM" ; then
1190 if test -n "$VM_IMAGE" ; then
1191 if test "$VM_IMAGE" = 1 ; then
1192 VM_IMAGE="$BUILD_ROOT.img"
1193 echo "using $VM_IMAGE as vm image"
1194 if test -z "$VM_SWAP"; then
1195 VM_SWAP="$BUILD_ROOT.swap"
1196 echo "using $VM_SWAP as vm swap"
1199 if [ "$VM_TYPE" = 'xen' ]; then
1200 # this should not be needed, but sometimes a xen instance got lost
1201 XENID="${VM_IMAGE%/root}"
1202 XENID="${XENID%/tmpfs}"
1203 XENID="${XENID##*/}"
1204 XENID="${XENID#root_}"
1205 xm destroy "build_$XENID" >/dev/null 2>&1
1207 if test ! -e "$VM_IMAGE"; then
1208 echo "Creating $VM_IMAGE (${VMDISK_ROOTSIZE}M)"
1209 mkdir -p "${VM_IMAGE%/*}"
1210 dd if=/dev/zero of="$VM_IMAGE" bs=1M count=0 seek="$VMDISK_ROOTSIZE" || cleanup_and_exit 3
1211 if test -z "$CLEAN_BUILD" ; then
1212 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1215 if test -n "$VM_SWAP" -a ! -e "$VM_SWAP"; then
1217 echo "Creating $VM_SWAP (${VMDISK_SWAPSIZE}M)"
1218 mkdir -p "${VM_SWAP%/*}"
1219 dd if=/dev/zero of="$VM_SWAP" bs=1M count=0 seek="$VMDISK_SWAPSIZE" || cleanup_and_exit 3
1221 if test ! -e "$VM_IMAGE" ; then
1222 echo "you need to create $VM_IMAGE first"
1225 if test -n "$CLEAN_BUILD" ; then
1226 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1229 if [ -w /root ]; then
1230 if [ -b $VM_IMAGE ]; then
1231 # mount device directly
1232 mount $VMDISK_MOUNT_OPTIONS $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1234 mount ${VMDISK_MOUNT_OPTIONS},loop $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1237 if ! mount $BUILD_ROOT; then
1238 echo "mounting the build root failed. An fstab entry is probably missing or incorrect."
1239 echo "/etc/fstab should contain an entry like this:"
1240 echo "$VM_IMAGE $BUILD_ROOT auto noauto,user,loop 0 0"
1245 test -w /root || become_root_or_fail
1247 if test -n "$VM_SWAP" ; then
1248 dd if=/dev/zero of="$VM_SWAP" bs=12 count=1 conv=notrunc 2>/dev/null
1249 echo "mkswap $VM_SWAP"
1256 if [ "$BUILD_ROOT" = / ]; then
1257 read dummy dummy browner dummy < <(ls -ld /)
1260 rm -f $BUILD_ROOT/exit
1262 if [ -w /root ]; then
1263 mkdir -p $BUILD_ROOT/proc
1264 mkdir -p $BUILD_ROOT/dev/pts
1265 mount -n -tproc none $BUILD_ROOT/proc || true
1266 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1269 if test -z "$VM_IMAGE" -a -z "$LOGFILE"; then
1270 LOGFILE="$BUILD_ROOT/.build.log"
1273 if test -n "$LOGFILE" -a -z "$shell" ; then
1274 echo logging output to $LOGFILE...
1277 if test -n "$VM_IMAGE" ; then
1278 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
1280 exec 1> >(exec -a 'build logging tee' tee -a $LOGFILE) 2>&1
1289 test -z "$HOST" && HOST=`hostname`
1291 if [ -z "$RUNNING_IN_VM" ]; then
1292 echo Using BUILD_ROOT=$BUILD_ROOT
1293 test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
1294 echo Using BUILD_ARCH=$BUILD_ARCH
1295 test -n "$VM_TYPE" && echo "Doing $VM_TYPE build${VM_IMAGE:+ in $VM_IMAGE}"
1299 test "$BUILD_ARCH" = all && BUILD_ARCH=
1300 BUILD_USER_ABUILD_USED=
1302 for SPECFILE in "${SPECFILES[@]}" ; do
1304 SRCDIR="${SPECFILE%/*}"
1305 SPECFILE="${SPECFILE##*/}"
1309 *.spec|*.src.rpm) BUILDTYPE=spec ;;
1310 *.dsc) BUILDTYPE=dsc ;;
1311 *.kiwi) BUILDTYPE=kiwi ;;
1313 if test -z "$BUILDTYPE" ; then
1314 echo "don't know how to build $SPECFILE"
1320 if [ -z "$RUNNING_IN_VM" ]; then
1322 echo "$HOST started \"build $SPECFILE\" at `date --utc`."
1324 test -n "$REASON" && echo "$REASON"
1329 # first setup building directory...
1331 test -s "$SPECFILE" || {
1332 echo "$SPECFILE" is empty. This should not happen...
1336 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1337 echo processing src rpm $SRCDIR/$SPECFILE ...
1338 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1341 cd $MYSRCDIR || cleanup_and_exit 1
1342 $BUILD_DIR/unrpm -q $SRCDIR/$SPECFILE || {
1343 echo "could not install $SPECFILE."
1346 for SPECFILE in *.spec ; do : ; done
1351 # FIX to work with baselibs_$PROJ etc
1352 if test "$BUILDTYPE" == "dsc" -a -e ${SRCDIR}/baselibs-deb.conf ; then
1353 # Set CREATE_BASELIBS if not set
1354 echo "dsc build and baselibs-deb.conf present: forcing --baselibs to true"
1355 CREATE_BASELIBS=true
1358 # Currently local osc build does not allow extra .deb packages to be
1359 # specified on the command line. Both init_buildsystem and expanddeps
1360 # need to handle .deb dependencies first
1361 # if test -n "$CREATE_BASELIBS" ; then
1362 # case $BUILDTYPE in
1364 # dsc) BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS libparse-debcontrol-perl" ;;
1368 echo processing specfile $MYSRCDIR/$SPECFILE ...
1371 test -z "$BUILD_EXTRA_PACKS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
1372 test -z "$CREATE_BASELIBS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
1373 test "$ccache" = '0' || ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
1374 test "$icecream" = 0 || ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
1375 test -z "$DO_LINT" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
1377 if test -n "$CHANGELOG" -a -z "$RUNNING_IN_VM" ; then
1378 rm -f $BUILD_ROOT/.build-changelog
1380 *.dsc) CFFORMAT=debian ;;
1383 echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
1384 if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
1385 rm -f $BUILD_ROOT/.build-changelog
1389 if test -n "$VM_TYPE" -a -z "$RUNNING_IN_VM"; then
1390 rm -rf $BUILD_ROOT/.build
1391 mkdir -p $BUILD_ROOT/.build
1392 if test "$DO_INIT" = true ; then
1393 # do fist stage of init_buildsystem
1394 rm -f $BUILD_ROOT/.build.success
1395 set -- init_buildsystem --cachedir "$CACHE_DIR" --prepare "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1397 "$@" || cleanup_and_exit 1
1399 if [ ! -w /root ]; then
1400 # remove setuid bit if files belong to user to make e.g. mount work
1401 find $BUILD_ROOT/{bin,sbin,usr/bin,usr/sbin} -type f -uid $UID -perm +4000 -print0 | xargs -0 --no-run-if-empty chmod -s
1405 # start up xen, rerun ourself
1406 cp -a $BUILD_DIR/. $BUILD_ROOT/.build
1407 if ! test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1408 rm -rf $BUILD_ROOT/.build-srcdir
1409 mkdir $BUILD_ROOT/.build-srcdir
1410 if test "$BUILDTYPE" = kiwi ; then
1411 cp -pRL "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1413 cp -p "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1415 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1417 # cwd is at $BUILD_ROOT/.build-srcdir which we want to
1418 # umount later so step aside
1422 echo "SPECFILE='${SPECFILE//"'"/$Q}'" > $BUILD_ROOT/.build/build.data
1423 echo "BUILD_JOBS='${BUILD_JOBS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1424 echo "BUILD_ARCH='${BUILD_ARCH//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1425 echo "BUILD_RPMS='${BUILD_RPMS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1428 cp $BUILD_DIST $BUILD_ROOT/.build/build.dist
1429 BUILD_DIST=/.build/build.dist
1432 echo "BUILD_DIST='${BUILD_DIST//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1433 echo "RELEASE='${RELEASE//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1434 echo "BUILD_DEBUG='${BUILD_DEBUG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1435 echo "SIGNDUMMY='${SIGNDUMMY//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1436 echo "DO_LINT='${DO_LINT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1437 echo "DO_CHECKS='${DO_CHECKS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1438 echo "NOROOTFORBUILD='${NOROOTFORBUILD//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1439 echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
1440 echo "REASON='${REASON//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1441 echo "CHANGELOG='${CHANGELOG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1442 echo "INCARNATION='${INCARNATION//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1443 echo "DISTURL='${DISTURL//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1444 echo "DO_INIT='${DO_INIT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1445 # FIXME: this depends on the kernel and vm.
1446 # could be hda2, sda2 for xen or hdb/sdb for qemu
1447 test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV:-/dev/hda2}'" >> $BUILD_ROOT/.build/build.data
1449 if test "$VM_TYPE" != 'lxc'; then
1450 test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
1452 echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
1453 echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
1454 echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
1455 shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
1456 echo ")" >> $BUILD_ROOT/.build/build.data
1457 echo -n "repos=(" >> $BUILD_ROOT/.build/build.data
1458 shellquote "${repos[@]}" >> $BUILD_ROOT/.build/build.data
1459 echo ")" >> $BUILD_ROOT/.build/build.data
1460 echo "VM_TYPE='$VM_TYPE'" >> $BUILD_ROOT/.build/build.data
1461 echo "shell='$shell'" >> $BUILD_ROOT/.build/build.data
1462 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
1463 umount -n $BUILD_ROOT/proc 2> /dev/null || true
1464 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
1465 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
1467 if [ -n "$VM_IMAGE" ]; then
1469 # needs to work otherwise we have a corrupted file system
1470 umount $BUILD_ROOT || cleanup_and_exit 1
1473 if check_use_emulator; then
1474 if [ -x "$BUILD_DIR/initvm" -a -e "$BUILD_DIR/qemu-reg" ]; then
1475 vm_init_script="/.build/initvm"
1476 elif [ -e $BUILD_DIR/initscript_qemu_vm ]; then
1477 vm_init_script="/.build/initscript_qemu_vm"
1479 echo "Warning: can't find initscript to register binfmts"
1482 vm_init_script="/.build/build"
1485 if [ "$VM_TYPE" = 'xen' ]; then
1486 XMROOT="file:$(readlink -f $VM_IMAGE)"
1487 XMROOT=${XMROOT/#file:\/dev/phy:/dev}
1488 XMROOT="disk=$XMROOT,hda1,w"
1490 if test -n "$VM_SWAP" ; then
1491 XMSWAP="file:$(readlink -f $VM_SWAP)"
1492 XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
1493 XMSWAP="disk=$XMSWAP,hda2,w"
1495 XENID="${VM_IMAGE%/root}"
1496 XENID="${XENID%/tmpfs}"
1497 XENID="${XENID##*/}"
1498 XENID="${XENID#root_}"
1500 echo "booting XEN kernel ..."
1501 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1502 echo "Instance already exist, something really went wrong..."
1503 echo "Please report to your server admin, there might be multiple services running for same domain"
1506 XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
1507 echo "kernel = \"$vm_kernel\"" > $XEN_CONF_FILE
1508 echo "ramdisk = \"$vm_initrd\"" >> $XEN_CONF_FILE
1509 echo "memory = ${MEMSIZE:-64}" >> $XEN_CONF_FILE
1510 echo "vcpus = $BUILD_JOBS" >> $XEN_CONF_FILE
1511 echo "root = \"/dev/hda1 ro\"" >> $XEN_CONF_FILE
1512 echo "extra = \"init=/bin/bash console=ttyS0 panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
1513 echo "on_poweroff = 'destroy'" >> $XEN_CONF_FILE
1514 echo "on_reboot = 'destroy'" >> $XEN_CONF_FILE
1515 echo "on_crash = 'destroy'" >> $XEN_CONF_FILE
1516 set -- xm create -c $XEN_CONF_FILE name="build_$XENID" $XMROOT $XMSWAP extra="quiet init="$vm_init_script" elevator=noop panic=1 console=ttyS0"
1517 if test "$PERSONALITY" != 0 ; then
1518 # have to switch back to PER_LINUX to make xm work
1522 "$@" || cleanup_and_exit 3
1524 elif [ "$VM_TYPE" = 'uml' ]; then
1525 echo "booting UML kernel ..."
1526 set -- $uml_kernel initrd=$uml_initrd root=/ubda init="$vm_init_script" panic=1 elevator=noop quiet ubd0=$VM_IMAGE ${MEMSIZE:+mem=$MEMSIZE}
1529 elif [ "$VM_TYPE" = 'qemu' -o "$VM_TYPE" = 'kvm' ]; then
1530 echo "booting $VM_TYPE ..."
1531 if [ "$VM_TYPE" = 'kvm' -a -b "$VM_IMAGE" ]; then
1532 # speed optimization when using kvm with raw devices
1535 # speed optimization when using kvm with raw files
1536 CACHE=",cache=unsafe"
1538 if [ "$kvm_virtio" = 1 ]; then
1539 qemu_args=(-drive file="$VM_IMAGE",if=virtio$CACHE -drive file="$VM_IMAGE",if=ide,index=0$CACHE)
1540 if [ -n "$VM_SWAP" ]; then
1541 qemu_args=("${qemu_args[@]}" "-drive")
1542 qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=virtio$CACHE")
1545 qemu_args=(-hda "$VM_IMAGE")
1546 if [ -n "$VM_SWAP" ]; then
1547 qemu_args=("${qemu_args[@]}" "-drive")
1548 qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=ide,index=1$CACHE")
1551 if [ -n "$BUILD_JOBS" -a "$icecream" = 0 ]; then
1552 qemu_args=("${qemu_args[@]}" "-smp" "$BUILD_JOBS")
1554 # cpuid is not set correctly in kvm without this
1556 if [ "$VM_TYPE" = 'kvm' ]; then
1557 KVM_OPTIONS="-cpu host"
1560 set -- $qemu_bin -no-reboot -nographic -net none $KVM_OPTIONS \
1561 -kernel $vm_kernel \
1562 -initrd $vm_initrd \
1563 -append "root=$qemu_rootdev panic=1 quiet no-kvmclock nmi_watchdog=0 rw elevator=noop console=$console init=$vm_init_script" \
1564 ${MEMSIZE:+-m $MEMSIZE} \
1567 if test "$PERSONALITY" != 0 ; then
1568 # have to switch back to PER_LINUX to make qemu work
1573 elif [ "$VM_TYPE" = 'lxc' ]; then
1574 echo "booting $VM_TYPE ..."
1575 LXCCONF="$BUILD_ROOT/.build.lxc.conf"
1577 cat $BUILD_DIR/lxc.conf > "$LXCCONF"
1578 cat >> "$LXCCONF" <<-EOF
1579 lxc.rootfs = $BUILD_ROOT
1581 # XXX: do this always instead of leaking the hosts' one?
1582 echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
1583 LXCID=${BUILD_ROOT##*/}
1584 lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
1585 lxc-create -n "$LXCID" -f "$LXCCONF" || cleanup_and_exit 1
1586 lxc-start -n "$LXCID" "$vm_init_script"
1588 test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
1589 cleanup_and_exit "$BUILDSTATUS"
1591 if test -n "$VM_SWAP" ; then
1592 BUILDSTATUS=`dd if="$VM_SWAP" bs=12 count=1 2>/dev/null`
1593 case $BUILDSTATUS in
1595 mkdir -p $BUILD_ROOT/.build.packages
1596 cd $BUILD_ROOT/.build.packages || cleanup_and_exit 1
1597 echo "build_ extracting built packages..."
1598 extractbuild --disk "$VM_IMAGE" --input "$VM_SWAP" --skip 512 -v || cleanup_and_exit 3
1599 # create same layout as with plain chroot
1600 if test "$BUILDTYPE" = spec ; then
1602 for i in *src.rpm *.desktopfiles ; do
1603 test -e "$i" || continue
1607 test -e "$i" || continue
1614 elif test "$BUILDTYPE" = dsc ; then
1616 find . -type f | while read i; do mv "$i" DEBS/; done
1619 find . -type f | while read i; do mv "$i" KIWI/; done
1622 test -f "$i" || continue
1625 *) mkdir -p OTHER ; mv $i OTHER/ ;;
1628 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1631 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1634 echo "No buildstatus set, either the packager broke the base system (glibc/bash/perl) or the build host has a kernel or hardware problem, OBS server will retry..."
1643 if test "$DO_INIT" = true ; then
1645 # create legacy .buildenv file
1647 test -z "$INCARNATION" && INCARNATION=0
1648 echo "BUILD_INCARNATION=$INCARNATION" > $BUILD_ROOT/.buildenv
1649 CREATE_BUILD_BINARIES=
1650 egrep '^#[ ]*needsbinariesforbuild[ ]*$' >/dev/null <$MYSRCDIR/$SPECFILE && CREATE_BUILD_BINARIES=--create-build-binaries
1651 set -- init_buildsystem --cachedir "$CACHE_DIR" "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1653 "$@" || cleanup_and_exit 1
1655 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
1657 echo "build does not work on a completely full filesystem"
1660 mount -n -tproc none $BUILD_ROOT/proc || true
1661 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1666 if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
1667 read BUILD_DIST < $BUILD_ROOT/.guessed_dist
1671 # fix rpmrc if we are compiling for i686
1673 test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
1674 if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
1675 mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
1676 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
1680 # install dummy sign program if needed
1682 test -f $BUILD_ROOT/usr/bin/sign_installed && mv $BUILD_ROOT/usr/bin/sign_installed $BUILD_ROOT/usr/bin/sign
1683 if test -n "$SIGNDUMMY" ; then
1684 test -f $BUILD_ROOT/usr/bin/sign && mv $BUILD_ROOT/usr/bin/sign $BUILD_ROOT/usr/bin/sign_installed
1685 cp $BUILD_DIR/signdummy $BUILD_ROOT/usr/bin/sign
1686 chmod 755 $BUILD_ROOT/usr/bin/sign
1690 # check if we want to build with the abuild user
1693 if test -x $BUILD_ROOT/bin/rpm ; then
1694 SUSE_VERSION=`chroot $BUILD_ROOT /bin/rpm --eval '%{?suse_version}' 2>/dev/null`
1695 if test -n "$SUSE_VERSION" && test "$SUSE_VERSION" -le 1020 ; then
1699 if test "$BUILD_USER" = abuild ; then
1700 egrep '^#[ ]*needsrootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=root
1702 egrep '^#[ ]*norootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=abuild
1704 test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
1706 if test $BUILD_USER = abuild ; then
1707 if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1708 echo "abuild::${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_ROOT/etc/passwd
1709 echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed on Mandriva 2009
1710 echo 'abuild:*::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu
1711 echo "abuild::${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
1712 mkdir -p $BUILD_ROOT/home/abuild
1713 chown "$ABUILD_UID:$ABUILD_GID" $BUILD_ROOT/home/abuild
1715 if ! egrep "^abuild:x?:${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_ROOT/etc/passwd ; then
1716 echo "abuild user present in the buildroot ($BUILD_ROOT) but uid:gid does not match"
1717 echo "buildroot currently using:"
1718 egrep "^abuild:" <$BUILD_ROOT/etc/passwd
1719 echo "build script attempting to use:"
1720 echo "abuild::${ABUILD_UID}:${ABUILD_GID}:..."
1721 echo "build aborting"
1725 if test -f $BUILD_ROOT/etc/shadow ; then
1726 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
1728 if test -f $BUILD_ROOT/etc/gshadow ; then
1729 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/gshadow > $BUILD_ROOT/etc/gshadow.t && mv $BUILD_ROOT/etc/gshadow.t $BUILD_ROOT/etc/gshadow
1731 BUILD_USER_ABUILD_USED=true
1736 if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1737 rm -rf $BUILD_ROOT/home/abuild
1738 egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
1739 mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd
1740 egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new
1741 mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group
1742 if test -f $BUILD_ROOT/etc/shadow ; then
1743 egrep -v '^abuild:' <$BUILD_ROOT/etc/shadow >$BUILD_ROOT/etc/shadow.new
1744 mv $BUILD_ROOT/etc/shadow.new $BUILD_ROOT/etc/shadow
1746 if test -f $BUILD_ROOT/etc/gshadow ; then
1747 egrep -v '^abuild:' <$BUILD_ROOT/etc/gshadow >$BUILD_ROOT/etc/gshadow.new
1748 mv $BUILD_ROOT/etc/gshadow.new $BUILD_ROOT/etc/gshadow
1753 if test "$BUILDTYPE" = spec ; then
1754 TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER`
1755 if test -z "$TOPDIR"; then
1756 echo "Error: TOPDIR empty"
1760 TOPDIR=/usr/src/packages
1761 mkdir -p $BUILD_ROOT$TOPDIR
1764 rm -f $BUILD_ROOT/.build.packages
1765 ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
1767 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1768 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
1774 # nasty hack to prevent rpath on known paths
1775 # FIXME: do this only for suse
1776 if test -d "$BUILD_ROOT/etc/profile.d" ; then
1777 echo "export SUSE_IGNORED_RPATHS=/etc/ld.so.conf" > "$BUILD_ROOT/etc/profile.d/buildsystem.sh"
1781 # now clean up RPM building directories
1783 rm -rf $BUILD_ROOT$TOPDIR
1784 for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT OTHER ; do
1785 mkdir -p $BUILD_ROOT$TOPDIR/$i
1787 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1790 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
1791 if test "$BUILDTYPE" = kiwi ; then
1792 mkdir -p $BUILD_ROOT$TOPDIR/KIWI
1793 if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1794 mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1796 if test -z "$LINKSOURCES" ; then
1797 cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1799 cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1801 if test "$?" != 0 ; then
1802 echo "source copy failed"
1807 cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1809 # strip prefix from autogenerated files of source services.
1810 for i in $BUILD_ROOT$TOPDIR/SOURCES/_service\:*; do
1811 mv "$i" "${i%/*}/${i##*:}"
1813 SPECFILE="${SPECFILE##*:}"
1815 test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
1817 test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
1819 if test "$BUILDTYPE" = spec ; then
1820 # do buildrequires/release substitution
1822 if test -n "$RELEASE"; then
1823 args=(--release "$RELEASE")
1825 substitutedeps "${args[@]}" --root "$BUILD_ROOT" --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" $CHANGELOGARGS "$BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1
1826 # extract macros from configuration
1827 getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
1828 if test -n "$BUILD_DEBUG" ; then
1830 %prep %{?!_suse_insert_debug_package_seen:%?_suse_insert_debug_package}%%prep
1831 %package %{?!_suse_insert_debug_package_seen:%?_suse_insert_debug_package}%%package
1832 %suse_insert_debug_package \
1833 %global _suse_insert_debug_package \\\
1834 %%global _suse_insert_debug_package_seen 1 \\\
1837 ' >> $BUILD_ROOT/root/.rpmmacros
1840 if [ -n "$BUILD_JOBS" ]; then
1841 cat >> $BUILD_ROOT/root/.rpmmacros <<-EOF
1843 %_smp_mflags -j$BUILD_JOBS
1846 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
1847 # extract optflags from configuration
1848 getoptflags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_ROOT/root/.rpmrc
1849 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
1850 if test -z "$ABUILD_TARGET"; then
1851 ABUILD_TARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" )
1852 test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
1855 if test -f $BUILD_ROOT/.spec.new ; then
1856 if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
1857 echo -----------------------------------------------------------------
1858 echo I have the following modifications for $SPECFILE:
1859 sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE > $BUILD_ROOT/.spec.t1
1860 sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2
1861 diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
1862 rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
1863 mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE
1865 rm -f $BUILD_ROOT/.spec.new
1869 if test "$BUILDTYPE" = dsc ; then
1870 rm -rf $BUILD_ROOT$TOPDIR/BUILD
1871 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
1872 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1874 DEB_SOURCEDIR=$TOPDIR/SOURCES
1875 DEB_DSCFILE=$SPECFILE
1876 for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
1877 test -f $f && DEB_TRANSFORM=true
1879 if test -n "$DEB_TRANSFORM" ; then
1880 echo "running debian transformer..."
1881 if ! debtransform $CHANGELOGARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
1882 echo "debian transforming failed."
1885 DEB_SOURCEDIR=$TOPDIR/SOURCES.DEB
1886 for DEB_DSCFILE in $BUILD_ROOT/$DEB_SOURCEDIR/*.dsc ; do : ; done
1887 DEB_DSCFILE="${DEB_DSCFILE##*/}"
1889 chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
1892 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1893 cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
1895 echo -----------------------------------------------------------------
1896 if test "$BUILD_USER" = root ; then
1897 echo ----- building $SPECFILE
1899 echo ----- building $SPECFILE "(user $BUILD_USER)"
1901 echo -----------------------------------------------------------------
1902 echo -----------------------------------------------------------------
1903 if [ -n "$RUNNING_IN_VM" ]; then
1904 if [ -x /sbin/ip ]; then
1905 ip addr add 127.0.0.1/8 dev lo
1908 ifconfig lo 127.0.0.1 up
1910 if [ -n "$MYHOSTNAME" ]; then
1911 hostname "$MYHOSTNAME"
1915 BUILD_SUCCEEDED=false
1917 if test -n "$OVERLAY" ; then
1918 if test -d "$OVERLAY"; then
1920 echo "Copying overlay to BUILD_ROOT"
1921 tar -cpf - . | (cd $BUILD_ROOT ; tar -xvf -)
1924 echo "OVERLAY ($OVERLAY) is no directory - skipping"
1928 if test -n "$RSYNCSRC" ; then
1929 if test -n "$RSYNCDEST"; then
1930 if test -d "$RSYNCSRC"; then
1931 if ! test -d "$BUILD_ROOT/$RSYNCDEST"; then
1932 echo "ATTENTION! Creating target directory ($BUILD_ROOT/$RSYNCDEST) as its not there."
1933 mkdir -p $BUILD_ROOT/$RSYNCDEST
1935 echo "Running rsync ..."
1936 rsync -av $RSYNCSRC/* $BUILD_ROOT/$RSYNCDEST/
1937 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/$RSYNCDEST"
1941 echo "RSYNCSRC is no directory - skipping"
1944 echo "RSYNCSRC given, but not RSYNCDEST - skipping"
1948 if test "$BUILDTYPE" = spec ; then
1949 test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
1951 # XXX: move _srcdefattr to macro file?
1952 rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--define" "_srcdefattr (-,root,root)")
1953 if [ -n "$ABUILD_TARGET" ]; then
1954 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
1956 if [ -n "$DISTURL" ]; then
1957 rpmbopts[${#rpmbopts[@]}]='--define'
1958 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
1960 if test -s "$BUILD_ROOT/usr/lib/rpm/mandriva/macros" ; then
1961 rpmbopts[${#rpmbopts[@]}]='--eval'
1962 rpmbopts[${#rpmbopts[@]}]="%undefine _enable_debug_packages"
1964 if [ -n "$BUILD_DEBUG" ]; then
1965 rpmbopts[${#rpmbopts[@]}]='--eval'
1966 rpmbopts[${#rpmbopts[@]}]="%suse_insert_debug_package"
1968 if [ -n "$RSYNCDONE" ] ; then
1969 rpmbopts[${#rpmbopts[@]}]='--define'
1970 rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
1975 test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
1976 # su involves a shell which would require even more
1977 # complicated quoting to bypass than this
1978 toshellscript $rpmbuild \
1979 "${definesnstuff[@]}" \
1981 "$TOPDIR/SOURCES/$SPECFILE" \
1982 > $BUILD_ROOT/.build.command
1983 chmod 755 $BUILD_ROOT/.build.command
1985 if test -n "$shell"; then
1986 chroot $BUILD_ROOT su -
1988 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
1992 if test "$BUILDTYPE" = dsc ; then
1993 # Checks to see if a build script should be used
1994 # this allows the build environment to be manipulated
1995 # and alternate build commands can be used
1996 # Debian policy requires to build with single CPU by default
1997 # if [ -n "$BUILD_JOBS" ]; then
1998 # DSC_BUILD_JOBS="-j$BUILD_JOBS"
2000 DSC_BUILD_CMD="dpkg-buildpackage -us -uc -rfakeroot-tcp $DSC_BUILD_JOBS"
2001 if test -e $BUILD_ROOT/$TOPDIR/SOURCES/build.script ; then
2002 echo "Sourcing build.script to build - it should normally run 'dpkg-buildpackage -us -uc -rfakeroot-tcp'"
2003 DSC_BUILD_CMD="source $TOPDIR/SOURCES/build.script"
2004 chmod +x $BUILD_ROOT/$TOPDIR/SOURCES/build.script
2007 if test -n "$shell"; then
2008 chroot $BUILD_ROOT su -
2010 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && $DSC_BUILD_CMD" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2013 mkdir -p $BUILD_ROOT/$TOPDIR/DEBS
2014 for DEB in $BUILD_ROOT/$TOPDIR/*.deb ; do
2015 test -e "$DEB" && mv "$DEB" "$BUILD_ROOT/$TOPDIR/DEBS"
2018 ln $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE $BUILD_ROOT/$TOPDIR/DEBS/
2020 ln $BUILD_ROOT/$DEB_SOURCEDIR/$f $BUILD_ROOT/$TOPDIR/DEBS/
2021 done < <(sed -ne '/^Files:/,$s/^ ................................ [0-9][0-9]* //p' < $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE)
2024 if test "$BUILDTYPE" = kiwi ; then
2025 . $BUILD_DIR/build_kiwi.sh
2029 test "$BUILD_SUCCEEDED" = true || cleanup_and_exit 1
2030 test -d "$SRCDIR" && cd "$SRCDIR"
2033 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
2034 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
2036 if test -n "$RPMS" -a -n "$BUILD_USER_ABUILD_USED" ; then
2037 echo "... checking for files with abuild user/group"
2039 while read un gn fn ; do
2040 if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
2044 done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
2045 if test -n "$BADFILE" ; then
2046 echo "please fix your filelist (e.g. add defattr)"
2051 if test -n "$RPMS" -a -d "$BUILD_ROOT/usr/lib/build/checks" ; then
2053 export DO_RPM_REMOVE=true
2054 for SRPM in $BUILD_ROOT/$TOPDIR/SRPMS/*src.rpm ; do
2055 test -f "$SRPM" && PNAME=`rpm --nodigest --nosignature -qp --qf "%{NAME}" $SRPM`
2057 for CHECKSCRIPT in $BUILD_ROOT/usr/lib/build/checks/* ; do
2058 echo "... running `basename $CHECKSCRIPT`"
2059 $CHECKSCRIPT || cleanup_and_exit 1
2063 if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_ROOT/opt/testing/bin/rpmlint" ; then
2064 LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
2065 \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
2066 -o -name "*-32bit-*" -o -name "*-64bit-*" \
2067 -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
2068 -o -type f -name '*.rpm' -print))
2069 SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
2071 echo "RPMLINT report:"
2072 echo "==============="
2073 rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log
2074 rm -f "$BUILD_ROOT$rpmlint_logfile"
2076 chroot $BUILD_ROOT su -s /opt/testing/bin/rpmlint "$BUILD_USER" -- \
2077 --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} \
2078 ${SRPM_FILE_LIST[*]#$BUILD_ROOT} > "$BUILD_ROOT$rpmlint_logfile" || ret=1
2079 cat "$BUILD_ROOT$rpmlint_logfile"
2081 if test "$ret" = 1; then
2086 if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS"; then
2091 # post build scripts
2092 # TODO: don't hardcode. instead run scripts in a directory as it's done for the checks
2093 if test -n "$RPMS" \
2094 -a -d "$BUILD_ROOT/$TOPDIR/RPMS" \
2095 -a -d "$BUILD_ROOT/.build.oldpackages" \
2097 if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
2098 echo "... comparing built packages with the former built"
2099 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
2100 if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
2101 chroot $BUILD_ROOT touch /.build/.same_result_marker
2102 # XXX: dirty build service hack. fix bs_worker. Search for
2103 # 'same_result_marker' for traces of a first try to get rid of this
2104 if test -n "$REASON" -a -n "$DISTURL"; then
2109 if test ! -e $BUILD_ROOT/.build/.same_result_marker \
2110 -a -x "$BUILD_ROOT/usr/bin/makedeltarpm" \
2111 -a -x $BUILD_ROOT/usr/lib/build/mkdrpms; then
2112 echo "... creating delta rpms"
2113 ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS")
2114 chroot $BUILD_ROOT /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}"
2118 if test -n "$RUNNING_IN_VM" -a -n "$VM_SWAP"; then
2119 echo "... saving built packages"
2121 args="--padstart 512 --padend 512 -v"
2122 case "$BUILDTYPE" in
2124 computeblocklists $args $TOPDIR/RPMS/*/*.{d,}rpm $TOPDIR/SRPMS/* $TOPDIR/OTHER/* > "$VM_SWAP"
2127 computeblocklists $args $TOPDIR/DEBS/*.deb $TOPDIR/SOURCES.DEB/* $TOPDIR/OTHER/* > "$VM_SWAP"
2130 computeblocklists $args $TOPDIR/KIWI/* $TOPDIR/OTHER/* > "$VM_SWAP"
2132 esac || cleanup_and_exit 1
2136 echo "$HOST finished \"build $SPECFILE\" at `date --utc`."
2139 cleanup_and_exit "$exitcode"