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=__default
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 --kill Instead of starting a build kill the one currently
148 --shell Instead of starting a build start a root shell in
151 --clean Delete old build root before initializing it
153 --no-init Skip initialization of build root and start with build
156 --no-checks Do not run post-build checks
158 --lint Run rpmlint after build.
161 Capture build output to logfile. Defaults to
162 .build.log in the build root for non-VM builds.
165 Use package repository at PATH. Supported formats are
167 Alternatively zypp://NAME specifies the zypp
168 repository NAME. The repo must be refreshed with zypp
169 so package meta data is available locally. With emtpy
170 NAME all enabled repositories are used.
171 a url can specify a remote repo.
173 --rpms path1:path2:...
174 Specify path where to find the RPMs for the build system
176 --arch arch1:arch2:...
177 Specify what architectures to select from the RPMs
179 --verify Run verify when initializing the build root
183 Also install package 'pack'
186 Use 'rootdir' to setup chroot environment
189 Use 'cachedir' to cache remote repo's packages, the
190 default cache dir is /var/cache/build, every repo
191 given by --repository corresponds to a subdir named
192 as md5sum of its repo url, for example:
193 /var/cache/build/3e8ea9b47808629414a0cebc33ea285e
195 --oldpackages oldpackagesdir
196 Define a directory with a former build
198 --baselibs Create -32bit/-64bit/-x86 rpms for other architectures
201 List rpms that would be used to create a fresh build root.
202 Does not create the build root or perform a build.
208 Enable feature X for build
211 Disable feature X for build
214 Define macro X with value Y
217 Override Release in spec file
220 Set stage for rpmbuild. Defaults to -ba.
223 Set target platform for rpmbuild
225 --jobs N Use N parallel processes during build.
226 Sets %jobs and %_smp_mflags macros and
227 defines the number of CPUs to use for
231 Use ccache to speed up rebuilds
234 Use N parallel build jobs with icecream
237 Copy overlay filesystem to buildroot after installing
238 all RPMs. This must be a valid directory.
241 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
242 inside the buildroot using rsync.
243 It will "%define RSYNCDONE 1" for handling %setup in your
247 %setup -n aaa_base -T -D -b 5 -b 7
249 %setup -n aaa_base -b 5 -b 7
252 --rsync-dest RSYNCDEST
253 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
254 inside the buildroot using rsync.
257 Specify the uid and gid to use for the abuild user.
258 This is useful if you are hacking in the buildroot.
259 This must be set to the same value if the buildroot is re-used.
262 Use virtual machine instead of chroot
263 TYPE is one of xen|kvm|uml|qemu|lxc
266 Use FILE as disk for virtual machine.
267 Defaults to \$BUILD_ROOT.img if unset
270 Use FILE as swap space for virtual machine. The swap space is
271 also used for retrieving packages from the VM so its size must
272 be sufficiently large
274 --vm-disk-size SIZEINMB
275 --vm-swap-size SIZEINMB
276 --vm-disk-filesystem TYPE
277 Defaults for automatic setup of VM root/swap files
280 Set amount of RAM for VMs
284 Kernel and initrd to use for VM (kvm and qemu only)
287 Enable creation of a debuginfo package
289 Remember to have fun!
291 [*] Maximum RPM: http://www.rpm.org/max-rpm/
295 echo "Usage: `basename $0` [--no-init|--clean|--rpms path|--verify|--help] [dir-to-build|spec-to-build]"
301 # return values: 0 -> success, new packages built
302 # 1 -> error, build failed
303 # 2 -> successfull build, but no changes to former built packages
304 # 3 -> something wrong with build host
306 cleanup_and_exit () {
308 test -z "$1" && set 0
309 rm -f $BUILD_ROOT/exit
310 if test "$1" -eq 1 -a -x /bin/df ; then
311 # okay, it failed, but maybe because disk space?
312 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
316 if test -n "$RUNNING_IN_VM" ; then
317 chown $browner $BUILD_ROOT
319 if test -n "$VM_SWAP" -a -e "$VM_SWAP" ; then
320 swapoff "$VM_SWAP" 2>/dev/null
321 echo -n "BUILDSTATUS$1" >"$VM_SWAP"
323 exec >&0 2>&0 # so that the logging tee finishes
324 sleep 1 # wait till tee terminates
325 if test "$VM_TYPE" != lxc; then
326 kill -9 -1 # goodbye cruel world
327 if ! test -x /sbin/halt ; then
328 test -e /proc/sysrq-trigger || mount -n -tproc none /proc
330 sleep 2 # like halt does
331 if test -e /proc/sysrq-trigger; then
332 echo o > /proc/sysrq-trigger
333 sleep 5 # wait for sysrq to take effect
335 echo "Warning: VM doesn't support sysrq and /sbin/halt not installed"
340 echo "Warning: clean shut down of the VM didn't work"
343 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
344 umount -n $BUILD_ROOT/proc 2>/dev/null || true
345 umount -n $BUILD_ROOT/dev/pts 2>/dev/null || true
346 test "$VM_IMAGE" = 1 && VM_IMAGE=
347 [ -n "$VM_IMAGE" ] && umount $BUILD_ROOT 2>/dev/null || true
349 # echo "pid $$ exit $1"
369 # create a shell script from command line. Used for preserving arguments
381 if [ "$ccache" = 1 ]; then
382 if mkdir -p $BUILD_ROOT/var/lib/build/ccache/bin; then
383 for i in $(ls $BUILD_ROOT/usr/bin | grep -E '^(cc|gcc|[cg][+][+])([-]?[234][.]?[0-9])*$'); do
384 # ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
385 rm -f $BUILD_ROOT/var/lib/build/ccache/bin/$i
386 test -e $BUILD_ROOT/usr/bin/$i || continue
387 echo '#! /bin/sh' > $BUILD_ROOT/var/lib/build/ccache/bin/$i
388 echo "test -e /usr/bin/$i || exit 1" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
389 echo 'export PATH=/opt/icecream/bin:/usr/bin:$PATH' >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
390 echo "ccache $i \"\$@\"" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
391 chmod 755 $BUILD_ROOT/var/lib/build/ccache/bin/$i
392 echo "Installed ccache wrapper as $BUILD_ROOT/var/lib/build/ccache/bin/$i"
395 mkdir -p "$BUILD_ROOT"/.ccache
396 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/.ccache"
397 echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
398 echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
400 rm -f "$BUILD_ROOT$builduserhome"/bin/{gcc,g++,cc,c++}
401 rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
407 if [ "$icecream" -eq 0 ]; then
408 rm -rf "$BUILD_ROOT"/var/run/icecream
409 rm -f "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
413 if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then
414 echo "*** icecream package not installed ***"
419 echo "using icecream with $icecream jobs"
421 if [ "$ccache" -ne 1 ]; then
422 echo 'export PATH=/opt/icecream/bin:$PATH' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
424 echo 'export CCACHE_PATH=/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
427 local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
428 icecc_vers=${icecc_vers//$BUILD_ROOT/}
430 # XXX use changelog like autobuild does instead?
431 # only run create-env if compiler or glibc changed
432 if [ -z "$icecc_vers" \
433 -o ! -e "$BUILD_ROOT/$icecc_vers" \
434 -o "$BUILD_ROOT/usr/bin/gcc" -nt "$BUILD_ROOT/$icecc_vers" \
435 -o "$BUILD_ROOT/usr/bin/g++" -nt "$BUILD_ROOT/$icecc_vers" \
436 -o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
437 -o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers" ]
439 rm -rf $BUILD_ROOT/var/run/icecream
440 mkdir -p $BUILD_ROOT/var/run/icecream
441 if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
442 createenv=/usr/bin/create-env
443 elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
444 createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
445 elif [ -e "$BUILD_ROOT"/usr/lib64/icecc/icecc-create-env ]; then
446 createenv="/usr/lib64/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
448 echo "create-env not found"
452 chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv" || cleanup_and_exit 1
453 icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
454 icecc_vers=${icecc_vers//$BUILD_ROOT/}
456 echo "reusing existing icecream environment $icecc_vers"
458 if [ -n "$icecc_vers" ]; then
459 echo "export ICECC_VERSION=$icecc_vers" >> "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
465 if [ -n "$VM_IMAGE" -o -n "$RUNNING_IN_VM" ]; then
474 eval "limit=\$(($2/3*4))"
478 eval "limit=\$(($2/3*4+$limit))"
481 done < <(cat /proc/meminfo) # cat for proc stuff
484 echo "Memory limit set to ${limit}KB"
493 if test "$BUILDTYPE" == "arch" ; then
496 if test "$BUILDTYPE" == "dsc" ; then
499 if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
500 BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
502 if test -e $BUILD_ROOT/usr/lib/build/baselibs_global.conf; then
503 BASELIBS_GLOBAL="-c /usr/lib/build/baselibs_global.conf"
508 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
509 # don't use -R as extracted sources, build root etc might be below $TOPDIR
510 chown "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"/* "$BUILD_ROOT$TOPDIR"/RPMS/* || true
512 local mkbaselibs="/usr/lib/build/mkbaselibs"
514 # $BUILD_DIR is set to /.build when using a vm. So we need to
515 # hardcode /usr/lib/build instead of $BUILD_DIR to prefer
516 # mkbaselibs from the distro.
517 if test -f $BUILD_ROOT$mkbaselibs; then
518 if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
519 BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
522 if test "$CREATE_BASELIBS" = 'internal'; then
523 echo "Warning: mkbaselibs missing in build root, skipping baselibs"
526 # use external version
527 whichone=" (external)"
528 mkbaselibs="/.mkbaselibs/mkbaselibs"
529 rm -rf $BUILD_ROOT/.mkbaselibs
530 mkdir -p $BUILD_ROOT/.mkbaselibs
531 cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs/
532 if test "$BUILDTYPE" == "dsc" ; then
533 cp -f $BUILD_DIR/baselibs_global-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
534 cp -f $BUILD_ROOT$TOPDIR/SOURCES/baselibs-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs-deb.conf
535 BASELIBS_CFG="-c /.mkbaselibs/baselibs-deb.conf"
537 cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
538 if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf; then
539 cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf
540 BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf"
543 if test -e $BUILD_ROOT/.mkbaselibs/baselibs_g.conf; then
544 BASELIBS_GLOBAL="-c /.mkbaselibs/baselibs_g.conf"
547 echo "... creating baselibs$whichone"
548 chroot $BUILD_ROOT su -c "$mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG ${pkgs[*]#$BUILD_ROOT}" - $BUILD_USER || cleanup_and_exit 1
549 rm -rf $BUILD_ROOT/.mkbaselibs
557 [ -z "$RUNNING_IN_VM" ] || return 0
558 if [ -z "$old_packages" ]; then
559 rm -rf "$BUILD_ROOT"/.build.oldpackages*
562 for d in "${old_packages[@]}"; do
563 dest="$BUILD_ROOT/.build.oldpackages"
564 test "$i" = 0 || dest="$dest$i"
565 if [ -d "$d" -a "$d" != "$dest" ] ; then
579 eval "mkfs=\"\$vm_img_mkfs_${fs}\""
580 eval "tunefs=\"\$vm_img_tunefs_${fs}\""
582 if test -z "$mkfs"; then
583 echo "filesystem \"$fs\" isn't supported"
588 echo "Creating $fs filesystem on $img"
590 if test -n "$tunefs" ; then
591 $tunefs "$img" || cleanup_and_exit 3
596 detect_vm_2nd_stage()
598 if ! test "$0" = "/.build/build" ; then
601 if test $$ -eq 1 ; then
602 # ignore special init signals if we're init
603 # we're using ' ' instead of '' so that the signal handlers
604 # are reset in the child processes
609 echo "2nd stage started in virtual machine"
612 . $BUILD_DIR/build.data
613 echo "machine type: `uname -m`"
614 if test "$PERSONALITY" != 0 -a -z "$PERSONALITY_SET" ; then
615 export PERSONALITY_SET=true
616 echo "switching personality to $PERSONALITY..."
617 # this is 32bit perl/glibc, thus the 32bit syscall number
618 exec perl -e 'syscall(136, '$PERSONALITY') == -1 && warn("personality: $!\n");exec "/.build/build" || die("/.build/build: $!\n")'
621 mount -orw -n -tproc none /proc
622 if test "$VM_TYPE" != 'lxc'; then
623 mount -n ${VMDISK_MOUNT_OPTIONS},remount,rw /
625 # qemu inside of xen does not work, check again with kvm later before enabling this
626 # if [ -e /dev/kqemu ]; then
627 # # allow abuild user to run qemu
628 # chmod 0666 /dev/kqemu
630 if test -n "$VM_SWAP" ; then
631 for i in 1 2 3 4 5 6 7 8 9 10 ; do
632 test -e "$VM_SWAP" && break
633 test $i = 1 && echo "waiting for $VM_SWAP to appear"
638 # recreate the swap device manually if it didn't exist for some
639 # reason, hardcoded to hda2 atm
640 if ! test -b "$VM_SWAP" ; then
643 mknod "$VM_SWAP" b 3 2
646 swapon -v "$VM_SWAP" || exit 1
656 if [ -z "$SPECFILES" ]; then
659 set -- "${SPECFILES[@]}"
663 if [ "$spec" = "${spec#/}" ]; then
667 if [ -d "$spec" ]; then
668 specs=("$spec"/*.spec)
669 if [ -n "$specs" ]; then
670 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
672 specs=("$spec"/*.spec)
673 if [ -n "$specs" ]; then
674 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
678 SPECFILES[${#SPECFILES[@]}]="$spec";
682 if test -z "$SPECFILES"; then
683 echo no spec files or src rpms found in $@. exit...
688 become_root_or_fail()
690 if [ ! -w /root ]; then
691 echo "You have to be root to use $0" >&2
699 if [ -d "$BUILD_ROOT" ]; then
700 # check if it is owned by root
701 if [ -z "$RUNNING_IN_VM" -a \! -O "$BUILD_ROOT" -a "`stat -c %u $BUILD_ROOT`" -ne 0 ]; then
702 echo "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
706 test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
707 if ! mkdir $BUILD_ROOT; then
708 echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
713 if [ ! -w "$BUILD_ROOT" ]; then
714 echo "Error: BUILD_ROOT=$BUILD_ROOT not writeable, try --clean."
718 rm -rf "$BUILD_ROOT"/.build.packages
719 if [ -z "$VM_TYPE" -a -z "$RUNNING_IN_VM" ]; then
720 # don't touch this in VM
721 rm -rf "$BUILD_ROOT"/.build
722 mkdir -p "$BUILD_ROOT"/.build
728 perl -e 'syscall('$PERSONALITY_SYSCALL', 0); exec(@ARGV) || die("$ARGV[0]: $!\n")' "$@"
737 if [ "$uname" != "ppc" -a "$uname" != "ppc64" ]; then
743 # XXX is this ok for ppc32 hosts? do we care?
744 export kvm_bin="/usr/bin/qemu-system-ppc64"
746 # XXX check host CPU and adjust guest CPU accordingly
747 export KVM_OPTIONS="-enable-kvm -M pseries -mem-path /hugetlbfs"
748 export VM_KERNEL=/boot/vmlinux
749 export VM_INITRD=/boot/initrd
750 if [ -z "$RUNNING_IN_VM" -a "$VM_TYPE" = "kvm" ];then
751 cat /proc/mounts | grep "/hugetlbfs" &>/dev/null
752 if [ "$?" != "0" ];then
753 echo "hugetlbfs is not mounted"
756 PAGES_FREE=$(cat /sys/kernel/mm/hugepages/hugepages-16384kB/free_hugepages)
757 PAGES_REQ=$(( $MEMSIZE / 16 ))
758 if [ "$PAGES_FREE" -lt "$PAGES_REQ" ];then
759 echo "please adjust nr_hugepages"
762 grep kvm_rma_count /proc/cmdline &>/dev/null
763 if [ "$?" != "0" ];then
764 echo "put kvm_rma_count=<VM number> to your boot options"
767 grep kvm_hpt_count /proc/cmdline &>/dev/null
768 if [ "$?" != "0" ];then
769 echo "put kvm_hpt_count=<VM number> to your boot options"
779 archname=`perl -V:archname`
780 archname="${archname#archname=?}"
782 x86_64*) PERSONALITY_SYSCALL=135 ;;
783 alpha*) PERSONALITY_SYSCALL=324 ;;
784 sparc*) PERSONALITY_SYSCALL=191 ;;
785 i?86*|ppc*|arm*|sh4|cris|m68k|s390*|unicore32|microblaze) PERSONALITY_SYSCALL=136 ;;
786 *) echo "ARCHITECTURE PERSONALITY IS UNKNOWN"; exit 1;;
791 if detect_vm_2nd_stage ; then
792 set "/.build-srcdir/$SPECFILE"
796 export PATH=$BUILD_DIR:/sbin:/usr/sbin:$PATH
798 . $BUILD_DIR/common_functions || exit 1
804 if [ -z "$ARG" ]; then
805 echo "$PARAM needs an agrument" >&2
810 while test -n "$1"; do
813 [ "$ARG" = "${ARG#-}" ] || ARG=""
819 set -- "----noarg=$PARAM" "$@"
833 CLEAN_BUILD='--clean'
849 export VERIFY_BUILD_SYSTEM=true
863 BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
873 CREATE_BASELIBS=internal
887 old_packages=("${old_packages[@]}" "$ARG")
895 *-xen|*-kvm|--uml|--qemu)
897 if [ -n "$ARG" ]; then
911 xen|kvm|uml|qemu|lxc)
912 test -z "$VM_IMAGE" && VM_IMAGE=1
914 none|chroot) VM_TYPE='' ;;
916 echo "VM $VM_TYPE not supported"
932 *-xenmemory|*-memory)
947 *-vmdisk-rootsize|--vm-disk-size)
949 VMDISK_ROOTSIZE="$ARG"
952 *-vmdisk-swapsize|--vm-swap-size)
954 VMDISK_SWAPSIZE="$ARG"
957 *-vmdisk-filesystem|--vm-disk-filesystem)
959 VMDISK_FILESYSTEM="$ARG"
962 *-vmdisk-mount-options|--vm-disk-mount-options)
964 # options needs to be quoted to handle argument which might start with "-o ..."
965 VMDISK_MOUNT_OPTIONS=$(echo $ARG | sed 's/^\"\(.*\)\"$/\1/g')
970 RPMLIST="--rpmlist $ARG"
994 BUILD_RPM_BUILD_STAGE="$ARG"
998 USEUSEDFORBUILD="--useusedforbuild"
1003 --define|--with|--without)
1005 definesnstuff[${#definesnstuff[@]}]="$PARAM";
1006 definesnstuff[${#definesnstuff[@]}]="$ARG";
1009 --repository|--repo)
1011 repos[${#repos[@]}]="$PARAM";
1012 repos[${#repos[@]}]="$ARG";
1018 if [ "$icecream" -gt 0 ]; then
1043 echo "$ARG does not take an argument"
1067 if test -n "${ABUILD_ID//[0-9:]/}"; then
1068 echo "--uid argument must be uid:gid"
1071 ABUILD_UID=${ABUILD_ID%:*}
1072 ABUILD_GID=${ABUILD_ID#*:}
1083 echo Unknown Option "$PARAM". Exit.
1087 SPECFILES[${#SPECFILES[@]}]="$PARAM";
1094 if test "$VM_TYPE" = "lxc"; then
1099 if test "$VMDISK_MOUNT_OPTIONS" = __default; then
1100 if test "$VMDISK_FILESYSTEM" = reiserfs ; then
1101 VMDISK_MOUNT_OPTIONS='-o data=writeback,commit=150,noatime'
1103 VMDISK_MOUNT_OPTIONS='-o data=writeback,nobarrier,commit=150,noatime'
1107 if test -n "$KILL" ; then
1108 test -z "$SRCDIR" || usage
1109 if test -n "$VM_IMAGE" -a -n "$VM_SWAP" -a -n "$VM_TYPE"; then
1110 # mark job as failed so that we don't extract packages
1111 echo -n "BUILDSTATUS1" >"$VM_SWAP"
1113 (set -C; > "$BUILD_ROOT/exit" 2>/dev/null || true)
1114 if test "$VM_TYPE" = 'lxc'; then
1115 LXCID=${BUILD_ROOT##*/}
1116 lxc-stop -n "$LXCID" || true
1117 lxc-destroy -n "$LXCID"
1118 elif test -z "$VM_IMAGE" ; then
1119 if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
1120 echo "could not kill build in $BUILD_ROOT"
1123 elif test "$VM_TYPE" = 'xen'; then
1124 XENID="${VM_IMAGE%/root}"
1125 XENID="${XENID%/tmpfs}"
1126 XENID="${XENID##*/}"
1127 XENID="${XENID#root_}"
1128 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1129 if ! xm destroy "build_$XENID" ; then
1130 echo "could not kill xen build $XENID"
1134 elif test -n "$VM_TYPE"; then
1135 if ! fuser -k -TERM "$VM_IMAGE"; then
1136 echo "could not kill build in $VM_IMAGE"
1140 echo "don't know how to kill this build job"
1146 if [ "$VM_TYPE" = 'xen' -a -z "$RUNNING_IN_VM" ]; then
1147 # XXX: merge with kvm path?
1148 if [ -n "$VM_KERNEL" ]; then
1149 vm_kernel="$VM_KERNEL"
1150 elif [ -e "/boot/vmlinuz-xen" ]; then
1151 vm_kernel="/boot/vmlinuz-xen"
1153 if [ -n "$VM_INITRD" ]; then
1154 vm_initrd="$VM_INITRD"
1155 elif [ -e "/boot/initrd-xen" ]; then
1156 vm_initrd="/boot/initrd-xen"
1160 if [ "$VM_TYPE" = 'kvm' -a -z "$RUNNING_IN_VM" ]; then
1161 if [ ! -r /dev/kvm -o ! -x "$kvm_bin" ]; then
1162 echo "host doesn't support kvm"
1163 echo "either the kvm kernel-module is not loaded or kvm is not installed or hardware virtualization is deactivated in the BIOS."
1167 if [ -n "$VM_KERNEL" ]; then
1168 vm_kernel="$VM_KERNEL"
1171 # check if a SUSE system with virtio initrd is running
1172 if [ -z "$VM_INITRD" -a -e /etc/sysconfig/kernel ]; then
1173 a=$( source /etc/sysconfig/kernel; echo $INITRD_MODULES )
1177 [ "$i" == "virtio_pci" ] && have_virtio_pci="1"
1178 [ "$i" == "virtio_blk" ] && have_virtio_blk="1"
1180 [ -n "$have_virtio_pci" -a -n "$have_virtio_blk" ] && VM_INITRD="/boot/initrd"
1183 if [ -n "$VM_INITRD" ]; then
1184 vm_initrd="$VM_INITRD"
1186 elif [ -e "${vm_initrd}-build" ]; then
1187 vm_initrd="${vm_initrd}-build"
1190 if [ -L "$vm_initrd" ]; then
1191 vm_initrd=`readlink -f "$vm_initrd"` || cleanup_and_exit 3
1193 vm_initrd_virtio="${vm_initrd}-virtio"
1195 if [ ! -e ${vm_initrd_virtio} -o $vm_kernel -nt ${vm_initrd_virtio} ]; then
1196 mkinitrd_virtio_cmd=(env rootfstype="$VMDISK_FILESYSTEM" \
1197 mkinitrd -d /dev/null \
1198 -m "ext3 ext4 btrfs reiserfs binfmt_misc virtio_pci virtio_blk" \
1200 -i ${vm_initrd_virtio})
1201 if [ ! -w /root -o -n "$RPMLIST" ]; then
1202 echo "No initrd that provides virtio support found. virtio accelleration disabled."
1203 echo "Run the following command as root to enable virtio:"
1204 shellquote "${mkinitrd_virtio_cmd[@]}"
1206 elif /sbin/modinfo virtio_pci >/dev/null 2>&1; then
1207 echo "creating $vm_initrd_virtio"
1208 "${mkinitrd_virtio_cmd[@]}" || cleanup_and_exit 1
1210 vm_initrd="${vm_initrd_virtio}"
1214 vm_initrd="${vm_initrd_virtio}"
1218 if [ "$HOST_ARCH" = ppc ]; then
1219 # KVM on PPC can not run virtio yet, so we need to use the default vio
1223 if [ "$kvm_virtio" = 1 ]; then
1225 qemu_rootdev=/dev/vda
1228 qemu_rootdev=/dev/sda
1232 if [ "$VM_TYPE" = 'qemu' ]; then
1234 qemu_rootdev=/dev/sda
1237 if [ -z "$RPMLIST" -a -z "$RUNNING_IN_VM" ]; then
1238 if [ -z "$repos" -a -z "$BUILD_RPMS" ]; then
1239 repos=(--repository 'zypp://')
1247 if [ -n "$CLEAN_BUILD" ]; then
1253 if test -n "$LIST_STATE" ; then
1254 BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
1255 test -d "$BUILD_ROOT" || cleanup_and_exit 3
1256 SPECFILE=$SPECFILES # only one specified anyways
1257 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1258 rm -rf $BUILD_ROOT/usr/src/packages
1259 mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES $BUILD_ROOT/usr/src/packages/SPECS
1260 rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
1261 echo "could not install $SPECFILE." 2>&1
1265 for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
1267 init_buildsystem --cachedir "$CACHE_DIR" --list-state "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
1270 cleanup_and_exit $ERR
1273 if test -z "$RUNNING_IN_VM" ; then
1274 if test -n "$VM_IMAGE" ; then
1275 if test "$VM_IMAGE" = 1 ; then
1276 VM_IMAGE="$BUILD_ROOT.img"
1277 echo "using $VM_IMAGE as vm image"
1278 if test -z "$VM_SWAP"; then
1279 VM_SWAP="$BUILD_ROOT.swap"
1280 echo "using $VM_SWAP as vm swap"
1283 if [ "$VM_TYPE" = 'xen' ]; then
1284 # this should not be needed, but sometimes a xen instance got lost
1285 XENID="${VM_IMAGE%/root}"
1286 XENID="${XENID%/tmpfs}"
1287 XENID="${XENID##*/}"
1288 XENID="${XENID#root_}"
1289 xm destroy "build_$XENID" >/dev/null 2>&1
1291 if test ! -e "$VM_IMAGE"; then
1292 echo "Creating $VM_IMAGE (${VMDISK_ROOTSIZE}M)"
1293 mkdir -p "${VM_IMAGE%/*}"
1294 dd if=/dev/zero of="$VM_IMAGE" bs=1M count=0 seek="$VMDISK_ROOTSIZE" || cleanup_and_exit 3
1295 if test -z "$CLEAN_BUILD" ; then
1296 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1299 if test -n "$VM_SWAP" -a ! -e "$VM_SWAP"; then
1301 echo "Creating $VM_SWAP (${VMDISK_SWAPSIZE}M)"
1302 mkdir -p "${VM_SWAP%/*}"
1303 dd if=/dev/zero of="$VM_SWAP" bs=1M count=0 seek="$VMDISK_SWAPSIZE" || cleanup_and_exit 3
1305 if test ! -e "$VM_IMAGE" ; then
1306 echo "you need to create $VM_IMAGE first"
1309 if test -n "$CLEAN_BUILD" ; then
1310 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1313 if [ -w /root ]; then
1314 if [ -b $VM_IMAGE ]; then
1315 # mount device directly
1316 mount $VMDISK_MOUNT_OPTIONS $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1318 mount ${VMDISK_MOUNT_OPTIONS},loop $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1321 if ! mount $BUILD_ROOT; then
1322 echo "mounting the build root failed. An fstab entry is probably missing or incorrect."
1323 echo "/etc/fstab should contain an entry like this:"
1324 echo "$VM_IMAGE $BUILD_ROOT auto noauto,user,loop 0 0"
1329 test -w /root || become_root_or_fail
1331 if test -n "$VM_SWAP" ; then
1332 dd if=/dev/zero of="$VM_SWAP" bs=12 count=1 conv=notrunc 2>/dev/null
1333 echo "mkswap $VM_SWAP"
1340 if [ "$BUILD_ROOT" = / ]; then
1341 read dummy dummy browner dummy < <(ls -ld /)
1344 rm -f $BUILD_ROOT/exit
1346 if [ -w /root ]; then
1347 mkdir -p $BUILD_ROOT/proc
1348 mkdir -p $BUILD_ROOT/dev/pts
1349 mount -n -tproc none $BUILD_ROOT/proc || true
1350 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1353 if test -z "$VM_IMAGE" -a -z "$LOGFILE"; then
1354 LOGFILE="$BUILD_ROOT/.build.log"
1357 if test -n "$LOGFILE" -a -z "$shell" ; then
1358 echo logging output to $LOGFILE...
1361 if test -n "$VM_IMAGE" ; then
1362 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
1364 exec 1> >(exec -a 'build logging tee' tee -a $LOGFILE) 2>&1
1373 test -z "$HOST" && HOST=`hostname`
1375 if [ -z "$RUNNING_IN_VM" ]; then
1376 echo Using BUILD_ROOT=$BUILD_ROOT
1377 test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
1378 echo Using BUILD_ARCH=$BUILD_ARCH
1379 test -n "$VM_TYPE" && echo "Doing $VM_TYPE build${VM_IMAGE:+ in $VM_IMAGE}"
1383 test "$BUILD_ARCH" = all && BUILD_ARCH=
1384 BUILD_USER_ABUILD_USED=
1386 for SPECFILE in "${SPECFILES[@]}" ; do
1388 SRCDIR="${SPECFILE%/*}"
1389 SPECFILE="${SPECFILE##*/}"
1393 *.spec|*.src.rpm) BUILDTYPE=spec ;;
1394 *.dsc) BUILDTYPE=dsc ;;
1395 *.kiwi) BUILDTYPE=kiwi ;;
1396 PKGBUILD) BUILDTYPE=arch ;;
1398 if test -z "$BUILDTYPE" ; then
1399 echo "don't know how to build $SPECFILE"
1405 if [ -z "$RUNNING_IN_VM" ]; then
1407 echo "$HOST started \"build $SPECFILE\" at `date --utc`."
1409 test -n "$REASON" && echo "$REASON"
1414 # first setup building directory...
1416 test -s "$SPECFILE" || {
1417 echo "$SPECFILE" is empty. This should not happen...
1421 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1422 echo processing src rpm $SRCDIR/$SPECFILE ...
1423 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1426 cd $MYSRCDIR || cleanup_and_exit 1
1427 $BUILD_DIR/unrpm -q $SRCDIR/$SPECFILE || {
1428 echo "could not install $SPECFILE."
1431 for SPECFILE in *.spec ; do : ; done
1436 # FIX to work with baselibs_$PROJ etc
1437 if test "$BUILDTYPE" == "dsc" -a -e ${SRCDIR}/baselibs-deb.conf ; then
1438 # Set CREATE_BASELIBS if not set
1439 echo "dsc build and baselibs-deb.conf present: forcing --baselibs to true"
1440 CREATE_BASELIBS=true
1443 # Currently local osc build does not allow extra .deb packages to be
1444 # specified on the command line. Both init_buildsystem and expanddeps
1445 # need to handle .deb dependencies first
1446 # if test -n "$CREATE_BASELIBS" ; then
1447 # case $BUILDTYPE in
1449 # dsc) BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS libparse-debcontrol-perl" ;;
1453 echo processing specfile $MYSRCDIR/$SPECFILE ...
1456 test -z "$BUILD_EXTRA_PACKS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
1457 test -z "$CREATE_BASELIBS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
1458 test "$ccache" = '0' || ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
1459 test "$icecream" = 0 || ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
1460 test -z "$DO_LINT" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
1462 if test -n "$CHANGELOG" -a -z "$RUNNING_IN_VM" ; then
1463 rm -f $BUILD_ROOT/.build-changelog
1465 *.dsc) CFFORMAT=debian ;;
1468 echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
1469 if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
1470 rm -f $BUILD_ROOT/.build-changelog
1474 if test -n "$VM_TYPE" -a -z "$RUNNING_IN_VM"; then
1475 rm -rf $BUILD_ROOT/.build
1476 mkdir -p $BUILD_ROOT/.build
1477 if test "$DO_INIT" = true ; then
1478 # do fist stage of init_buildsystem
1479 rm -f $BUILD_ROOT/.build.success
1480 set -- init_buildsystem --cachedir "$CACHE_DIR" --prepare "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1482 "$@" || cleanup_and_exit 1
1484 if [ ! -w /root ]; then
1485 # remove setuid bit if files belong to user to make e.g. mount work
1486 find $BUILD_ROOT/{bin,sbin,usr/bin,usr/sbin} -type f -uid $UID -perm +4000 -print0 | xargs -0 --no-run-if-empty chmod -s
1490 # start up xen, rerun ourself
1491 cp -a $BUILD_DIR/. $BUILD_ROOT/.build
1492 if ! test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1493 rm -rf $BUILD_ROOT/.build-srcdir
1494 mkdir $BUILD_ROOT/.build-srcdir
1495 if test "$BUILDTYPE" = kiwi ; then
1496 cp -pRL "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1498 cp -p "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1500 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1502 # cwd is at $BUILD_ROOT/.build-srcdir which we want to
1503 # umount later so step aside
1507 echo "SPECFILE='${SPECFILE//"'"/$Q}'" > $BUILD_ROOT/.build/build.data
1508 echo "BUILD_JOBS='${BUILD_JOBS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1509 echo "BUILD_ARCH='${BUILD_ARCH//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1510 echo "BUILD_RPMS='${BUILD_RPMS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1513 cp $BUILD_DIST $BUILD_ROOT/.build/build.dist
1514 BUILD_DIST=/.build/build.dist
1517 echo "BUILD_DIST='${BUILD_DIST//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1518 echo "RELEASE='${RELEASE//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1519 echo "BUILD_DEBUG='${BUILD_DEBUG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1520 echo "SIGNDUMMY='${SIGNDUMMY//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1521 echo "DO_LINT='${DO_LINT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1522 echo "DO_CHECKS='${DO_CHECKS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1523 echo "NOROOTFORBUILD='${NOROOTFORBUILD//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1524 echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
1525 echo "REASON='${REASON//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1526 echo "CHANGELOG='${CHANGELOG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1527 echo "INCARNATION='${INCARNATION//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1528 echo "DISTURL='${DISTURL//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1529 echo "DO_INIT='${DO_INIT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1530 # FIXME: this depends on the kernel and vm.
1531 # could be hda2, sda2 for xen or hdb/sdb for qemu
1532 test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV:-/dev/hda2}'" >> $BUILD_ROOT/.build/build.data
1533 test -n "$VMDISK_MOUNT_OPTIONS" && echo "VMDISK_MOUNT_OPTIONS='${VMDISK_MOUNT_OPTIONS}'" >> $BUILD_ROOT/.build/build.data
1535 if test "$VM_TYPE" != 'lxc'; then
1536 test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
1538 if test "$(uname -m)" = 'ppc'; then
1539 # ppc kernel never tells us if a 32bit personality is active
1542 echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
1543 echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
1544 echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
1545 shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
1546 echo ")" >> $BUILD_ROOT/.build/build.data
1547 echo -n "repos=(" >> $BUILD_ROOT/.build/build.data
1548 shellquote "${repos[@]}" >> $BUILD_ROOT/.build/build.data
1549 echo ")" >> $BUILD_ROOT/.build/build.data
1550 echo "VM_TYPE='$VM_TYPE'" >> $BUILD_ROOT/.build/build.data
1551 echo "shell='$shell'" >> $BUILD_ROOT/.build/build.data
1552 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
1553 umount -n $BUILD_ROOT/proc 2> /dev/null || true
1554 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
1555 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
1557 if [ -n "$VM_IMAGE" ]; then
1559 # needs to work otherwise we have a corrupted file system
1560 umount $BUILD_ROOT || cleanup_and_exit 1
1563 if check_use_emulator; then
1564 if [ -x "$BUILD_DIR/initvm" -a -e "$BUILD_DIR/qemu-reg" ]; then
1565 vm_init_script="/.build/initvm"
1566 elif [ -e $BUILD_DIR/initscript_qemu_vm ]; then
1567 vm_init_script="/.build/initscript_qemu_vm"
1569 echo "Warning: can't find initscript to register binfmts"
1572 vm_init_script="/.build/build"
1575 if [ "$VM_TYPE" = 'xen' ]; then
1576 XMROOT="file:$(readlink -f $VM_IMAGE)"
1577 XMROOT=${XMROOT/#file:\/dev/phy:/dev}
1578 XMROOT="disk=$XMROOT,hda1,w"
1580 if test -n "$VM_SWAP" ; then
1581 XMSWAP="file:$(readlink -f $VM_SWAP)"
1582 XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
1583 XMSWAP="disk=$XMSWAP,hda2,w"
1585 XENID="${VM_IMAGE%/root}"
1586 XENID="${XENID%/tmpfs}"
1587 XENID="${XENID##*/}"
1588 XENID="${XENID#root_}"
1590 echo "booting XEN kernel ..."
1591 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1592 echo "Instance already exist, something really went wrong..."
1593 echo "Please report to your server admin, there might be multiple services running for same domain"
1596 XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
1597 echo "kernel = \"$vm_kernel\"" > $XEN_CONF_FILE
1598 echo "ramdisk = \"$vm_initrd\"" >> $XEN_CONF_FILE
1599 echo "memory = ${MEMSIZE:-64}" >> $XEN_CONF_FILE
1600 echo "vcpus = $BUILD_JOBS" >> $XEN_CONF_FILE
1601 echo "root = \"/dev/hda1 ro\"" >> $XEN_CONF_FILE
1602 echo "extra = \"init=/bin/bash console=ttyS0 panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
1603 echo "on_poweroff = 'destroy'" >> $XEN_CONF_FILE
1604 echo "on_reboot = 'destroy'" >> $XEN_CONF_FILE
1605 echo "on_crash = 'destroy'" >> $XEN_CONF_FILE
1606 set -- xm create -c $XEN_CONF_FILE name="build_$XENID" $XMROOT $XMSWAP extra="quiet init="$vm_init_script" elevator=noop panic=1 console=ttyS0"
1607 if test "$PERSONALITY" != 0 ; then
1608 # have to switch back to PER_LINUX to make xm work
1612 "$@" || cleanup_and_exit 3
1614 elif [ "$VM_TYPE" = 'uml' ]; then
1615 echo "booting UML kernel ..."
1616 set -- $uml_kernel initrd=$uml_initrd root=/ubda init="$vm_init_script" panic=1 elevator=noop quiet ubd0=$VM_IMAGE ${MEMSIZE:+mem=$MEMSIZE}
1619 elif [ "$VM_TYPE" = 'qemu' -o "$VM_TYPE" = 'kvm' ]; then
1620 echo "booting $VM_TYPE ..."
1621 if [ "$VM_TYPE" = 'kvm' -a -b "$VM_IMAGE" ]; then
1622 # speed optimization when using kvm with raw devices
1625 # speed optimization when using kvm with raw files
1626 CACHE=",cache=unsafe"
1628 if [ "$kvm_virtio" = 1 ]; then
1629 qemu_args=(-drive file="$VM_IMAGE",if=virtio$CACHE -drive file="$VM_IMAGE",if=ide,index=0$CACHE)
1630 if [ -n "$VM_SWAP" ]; then
1631 qemu_args=("${qemu_args[@]}" "-drive")
1632 qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=virtio$CACHE")
1635 if [ "$HOST_ARCH" = "ppc" ];then
1636 qemu_args=( "-drive" )
1637 qemu_args=("${qemu_args[@]}" "file=$VM_IMAGE,if=scsi,cache=unsafe")
1639 qemu_args=(-hda "$VM_IMAGE")
1641 if [ -n "$VM_SWAP" ]; then
1642 qemu_args=("${qemu_args[@]}" "-drive")
1643 if [ "$HOST_ARCH" = "ppc" ];then
1648 qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=$DISK_IF,index=1$CACHE")
1651 if [ -n "$BUILD_JOBS" -a "$icecream" = 0 ]; then
1652 qemu_args=("${qemu_args[@]}" "-smp" "$BUILD_JOBS")
1654 # cpuid is not set correctly in kvm without this
1655 if [ "$HOST_ARCH" != "ppc" ]; then
1658 if [ "$VM_TYPE" = 'kvm' ]; then
1659 KVM_OPTIONS="$KVM_OPTIONS -cpu host"
1662 set -- $qemu_bin -no-reboot -nographic -net none $KVM_OPTIONS \
1663 -kernel $vm_kernel \
1664 -initrd $vm_initrd \
1665 -append "root=$qemu_rootdev panic=1 quiet no-kvmclock nmi_watchdog=0 rw elevator=noop console=$console init=$vm_init_script" \
1666 ${MEMSIZE:+-m $MEMSIZE} \
1669 if test "$PERSONALITY" != 0 ; then
1670 # have to switch back to PER_LINUX to make qemu work
1675 elif [ "$VM_TYPE" = 'lxc' ]; then
1676 echo "booting $VM_TYPE ..."
1677 LXCCONF="$BUILD_ROOT/.build.lxc.conf"
1679 cat $BUILD_DIR/lxc.conf > "$LXCCONF"
1680 cat >> "$LXCCONF" <<-EOF
1681 lxc.rootfs = $BUILD_ROOT
1683 # XXX: do this always instead of leaking the hosts' one?
1684 echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
1685 LXCID=${BUILD_ROOT##*/}
1686 lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
1687 lxc-create -n "$LXCID" -f "$LXCCONF" || cleanup_and_exit 1
1688 lxc-start -n "$LXCID" "$vm_init_script"
1690 test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
1691 cleanup_and_exit "$BUILDSTATUS"
1693 if test -n "$VM_SWAP" ; then
1694 BUILDSTATUS=`dd if="$VM_SWAP" bs=12 count=1 2>/dev/null`
1695 case $BUILDSTATUS in
1697 mkdir -p $BUILD_ROOT/.build.packages
1698 cd $BUILD_ROOT/.build.packages || cleanup_and_exit 1
1699 echo "build_ extracting built packages..."
1700 extractbuild --disk "$VM_IMAGE" --input "$VM_SWAP" --skip 512 -v || cleanup_and_exit 3
1701 # create same layout as with plain chroot
1702 if test "$BUILDTYPE" = spec ; then
1704 for i in *src.rpm *.desktopfiles ; do
1705 test -e "$i" || continue
1709 test -e "$i" || continue
1716 elif test "$BUILDTYPE" = dsc ; then
1718 find . -type f | while read i; do mv "$i" DEBS/; done
1719 elif test "$BUILDTYPE" = arch ; then
1721 find . -type f | while read i; do mv "$i" ARCHPKGS/; done
1724 find . -type f | while read i; do mv "$i" KIWI/; done
1727 test -f "$i" || continue
1730 *) mkdir -p OTHER ; mv $i OTHER/ ;;
1733 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1736 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1739 echo "No buildstatus set, either the base system is broken (glibc/bash/perl)"
1740 echo "or the build host has a kernel or hardware problem..."
1749 if test "$DO_INIT" = true ; then
1751 # create legacy .buildenv file
1753 test -z "$INCARNATION" && INCARNATION=0
1754 echo "BUILD_INCARNATION=$INCARNATION" > $BUILD_ROOT/.buildenv
1755 CREATE_BUILD_BINARIES=
1756 egrep '^#[ ]*needsbinariesforbuild[ ]*$' >/dev/null <$MYSRCDIR/$SPECFILE && CREATE_BUILD_BINARIES=--create-build-binaries
1757 set -- init_buildsystem --cachedir "$CACHE_DIR" "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1759 "$@" || cleanup_and_exit 1
1761 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
1763 echo "build does not work on a completely full filesystem"
1766 mount -n -tproc none $BUILD_ROOT/proc || true
1767 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1772 if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
1773 read BUILD_DIST < $BUILD_ROOT/.guessed_dist
1777 # fix rpmrc if we are compiling for i686
1779 test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
1780 if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
1781 mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
1782 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
1786 # install dummy sign program if needed
1788 test -f $BUILD_ROOT/usr/bin/sign_installed && mv $BUILD_ROOT/usr/bin/sign_installed $BUILD_ROOT/usr/bin/sign
1789 if test -n "$SIGNDUMMY" ; then
1790 test -f $BUILD_ROOT/usr/bin/sign && mv $BUILD_ROOT/usr/bin/sign $BUILD_ROOT/usr/bin/sign_installed
1791 cp $BUILD_DIR/signdummy $BUILD_ROOT/usr/bin/sign
1792 chmod 755 $BUILD_ROOT/usr/bin/sign
1796 # check if we want to build with the abuild user
1799 if test -x $BUILD_ROOT/bin/rpm ; then
1800 SUSE_VERSION=`chroot $BUILD_ROOT /bin/rpm --eval '%{?suse_version}' 2>/dev/null`
1801 if test -n "$SUSE_VERSION" && test "$SUSE_VERSION" -le 1020 ; then
1805 if test "$BUILD_USER" = abuild ; then
1806 egrep '^#[ ]*needsrootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=root
1808 egrep '^#[ ]*norootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=abuild
1810 test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
1812 if test $BUILD_USER = abuild ; then
1813 if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1814 echo "abuild:x:${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_ROOT/etc/passwd
1815 echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed on Mandriva 2009
1816 echo 'abuild:*::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu
1817 echo "abuild:x:${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
1818 mkdir -p $BUILD_ROOT/home/abuild
1819 chown "$ABUILD_UID:$ABUILD_GID" $BUILD_ROOT/home/abuild
1821 if ! egrep "^abuild:x?:${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_ROOT/etc/passwd ; then
1822 echo "abuild user present in the buildroot ($BUILD_ROOT) but uid:gid does not match"
1823 echo "buildroot currently using:"
1824 egrep "^abuild:" <$BUILD_ROOT/etc/passwd
1825 echo "build script attempting to use:"
1826 echo "abuild::${ABUILD_UID}:${ABUILD_GID}:..."
1827 echo "build aborting"
1831 if test -f $BUILD_ROOT/etc/shadow ; then
1832 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
1834 if test -f $BUILD_ROOT/etc/gshadow ; then
1835 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/gshadow > $BUILD_ROOT/etc/gshadow.t && mv $BUILD_ROOT/etc/gshadow.t $BUILD_ROOT/etc/gshadow
1837 BUILD_USER_ABUILD_USED=true
1842 if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1843 rm -rf $BUILD_ROOT/home/abuild
1844 egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
1845 mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd
1846 egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new
1847 mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group
1848 if test -f $BUILD_ROOT/etc/shadow ; then
1849 egrep -v '^abuild:' <$BUILD_ROOT/etc/shadow >$BUILD_ROOT/etc/shadow.new
1850 mv $BUILD_ROOT/etc/shadow.new $BUILD_ROOT/etc/shadow
1852 if test -f $BUILD_ROOT/etc/gshadow ; then
1853 egrep -v '^abuild:' <$BUILD_ROOT/etc/gshadow >$BUILD_ROOT/etc/gshadow.new
1854 mv $BUILD_ROOT/etc/gshadow.new $BUILD_ROOT/etc/gshadow
1859 if test "$BUILDTYPE" = spec ; then
1860 TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER`
1861 if test -z "$TOPDIR"; then
1862 echo "Error: TOPDIR empty"
1866 TOPDIR=/usr/src/packages
1867 mkdir -p $BUILD_ROOT$TOPDIR
1870 rm -f $BUILD_ROOT/.build.packages
1871 ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
1873 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1874 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
1880 # nasty hack to prevent rpath on known paths
1881 # FIXME: do this only for suse
1882 if test -d "$BUILD_ROOT/etc/profile.d" ; then
1883 echo "export SUSE_IGNORED_RPATHS=/etc/ld.so.conf" > "$BUILD_ROOT/etc/profile.d/buildsystem.sh"
1887 # now clean up RPM building directories
1889 rm -rf $BUILD_ROOT$TOPDIR
1890 for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT OTHER ; do
1891 mkdir -p $BUILD_ROOT$TOPDIR/$i
1893 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1896 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
1897 if test "$BUILDTYPE" = kiwi ; then
1898 mkdir -p $BUILD_ROOT$TOPDIR/KIWI
1899 if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1900 mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1902 if test -z "$LINKSOURCES" ; then
1903 cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1905 cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1907 if test "$?" != 0 ; then
1908 echo "source copy failed"
1913 cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1915 # strip prefix from autogenerated files of source services.
1916 for i in $BUILD_ROOT$TOPDIR/SOURCES/_service\:*; do
1917 mv "$i" "${i%/*}/${i##*:}"
1919 SPECFILE="${SPECFILE##*:}"
1921 test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
1923 test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
1925 if test "$BUILDTYPE" = spec ; then
1926 # do buildrequires/release substitution
1928 if test -n "$RELEASE"; then
1929 args=(--release "$RELEASE")
1931 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
1932 # extract macros from configuration
1933 getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
1934 if test -n "$BUILD_DEBUG" ; then
1936 %prep %{?!_suse_insert_debug_package_seen:%?_suse_insert_debug_package}%%prep
1937 %package %{?!_suse_insert_debug_package_seen:%?_suse_insert_debug_package}%%package
1938 %suse_insert_debug_package \
1939 %global _suse_insert_debug_package \\\
1940 %%global _suse_insert_debug_package_seen 1 \\\
1943 ' >> $BUILD_ROOT/root/.rpmmacros
1946 if [ -n "$BUILD_JOBS" ]; then
1947 cat >> $BUILD_ROOT/root/.rpmmacros <<-EOF
1949 %_smp_mflags -j$BUILD_JOBS
1952 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
1953 # extract optflags from configuration
1954 getoptflags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_ROOT/root/.rpmrc
1955 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
1956 if test -z "$ABUILD_TARGET"; then
1957 ABUILD_TARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" )
1958 test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
1961 if test -f $BUILD_ROOT/.spec.new ; then
1962 if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
1963 echo -----------------------------------------------------------------
1964 echo I have the following modifications for $SPECFILE:
1965 sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE > $BUILD_ROOT/.spec.t1
1966 sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2
1967 diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
1968 rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
1969 mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE
1971 rm -f $BUILD_ROOT/.spec.new
1975 if test "$BUILDTYPE" = dsc ; then
1976 rm -rf $BUILD_ROOT$TOPDIR/BUILD
1977 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
1978 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1980 DEB_SOURCEDIR=$TOPDIR/SOURCES
1981 DEB_DSCFILE=$SPECFILE
1982 for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
1983 test -f $f && DEB_TRANSFORM=true
1985 if test -n "$DEB_TRANSFORM" ; then
1986 echo "running debian transformer..."
1987 if ! debtransform $CHANGELOGARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
1988 echo "debian transforming failed."
1991 DEB_SOURCEDIR=$TOPDIR/SOURCES.DEB
1992 for DEB_DSCFILE in $BUILD_ROOT/$DEB_SOURCEDIR/*.dsc ; do : ; done
1993 DEB_DSCFILE="${DEB_DSCFILE##*/}"
1995 chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
1998 if test "$BUILDTYPE" = arch ; then
1999 echo "Preparing sources..."
2000 chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES && makepkg -s -o 2>&1 >/dev/null" - $BUILD_USER
2001 mv $BUILD_ROOT/$TOPDIR/SOURCES/* -t $BUILD_ROOT/$TOPDIR/BUILD
2004 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
2005 cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
2007 echo -----------------------------------------------------------------
2008 if test "$BUILD_USER" = root ; then
2009 echo ----- building $SPECFILE
2011 echo ----- building $SPECFILE "(user $BUILD_USER)"
2013 echo -----------------------------------------------------------------
2014 echo -----------------------------------------------------------------
2015 if [ -n "$RUNNING_IN_VM" ]; then
2016 if [ -x /sbin/ip ]; then
2017 ip addr add 127.0.0.1/8 dev lo
2020 ifconfig lo 127.0.0.1 up
2022 if [ -n "$MYHOSTNAME" ]; then
2023 hostname "$MYHOSTNAME"
2027 BUILD_SUCCEEDED=false
2029 if test -n "$OVERLAY" ; then
2030 if test -d "$OVERLAY"; then
2032 echo "Copying overlay to BUILD_ROOT"
2033 tar -cpf - . | (cd $BUILD_ROOT ; tar -xvf -)
2036 echo "OVERLAY ($OVERLAY) is no directory - skipping"
2040 if test -n "$RSYNCSRC" ; then
2041 if test -n "$RSYNCDEST"; then
2042 if test -d "$RSYNCSRC"; then
2043 if ! test -d "$BUILD_ROOT/$RSYNCDEST"; then
2044 echo "ATTENTION! Creating target directory ($BUILD_ROOT/$RSYNCDEST) as its not there."
2045 mkdir -p $BUILD_ROOT/$RSYNCDEST
2047 echo "Running rsync ..."
2048 rsync -av $RSYNCSRC/* $BUILD_ROOT/$RSYNCDEST/
2049 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/$RSYNCDEST"
2053 echo "RSYNCSRC is no directory - skipping"
2056 echo "RSYNCSRC given, but not RSYNCDEST - skipping"
2060 if test "$BUILDTYPE" = spec ; then
2061 test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
2064 test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
2066 # XXX: move _srcdefattr to macro file?
2067 rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--define" "_srcdefattr (-,root,root)")
2068 if [ "$rpmbuild" == "rpmbuild" ]; then
2069 # use only --nosignature for rpm v4
2070 rpmbopts[${#rpmbopts[@]}]="--nosignature"
2072 if [ -n "$ABUILD_TARGET" ]; then
2073 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
2075 if [ -n "$DISTURL" ]; then
2076 rpmbopts[${#rpmbopts[@]}]='--define'
2077 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
2079 if test -s "$BUILD_ROOT/usr/lib/rpm/mandriva/macros" ; then
2080 rpmbopts[${#rpmbopts[@]}]='--eval'
2081 rpmbopts[${#rpmbopts[@]}]="%undefine _enable_debug_packages"
2083 if [ -n "$BUILD_DEBUG" ]; then
2084 rpmbopts[${#rpmbopts[@]}]='--eval'
2085 rpmbopts[${#rpmbopts[@]}]="%suse_insert_debug_package"
2087 if [ -n "$RSYNCDONE" ] ; then
2088 rpmbopts[${#rpmbopts[@]}]='--define'
2089 rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
2092 # su involves a shell which would require even more
2093 # complicated quoting to bypass than this
2094 toshellscript $rpmbuild \
2095 "${definesnstuff[@]}" \
2097 "$TOPDIR/SOURCES/$SPECFILE" \
2098 > $BUILD_ROOT/.build.command
2099 chmod 755 $BUILD_ROOT/.build.command
2101 if test -n "$shell"; then
2102 chroot $BUILD_ROOT su -
2104 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2108 if test "$BUILDTYPE" = dsc ; then
2109 # Checks to see if a build script should be used
2110 # this allows the build environment to be manipulated
2111 # and alternate build commands can be used
2112 # Debian policy requires to build with single CPU by default
2113 # if [ -n "$BUILD_JOBS" ]; then
2114 # DSC_BUILD_JOBS="-j$BUILD_JOBS"
2116 DSC_BUILD_CMD="dpkg-buildpackage -us -uc -rfakeroot-tcp $DSC_BUILD_JOBS"
2117 if test -e $BUILD_ROOT/$TOPDIR/SOURCES/build.script ; then
2118 echo "Sourcing build.script to build - it should normally run 'dpkg-buildpackage -us -uc -rfakeroot-tcp'"
2119 DSC_BUILD_CMD="source $TOPDIR/SOURCES/build.script"
2120 chmod +x $BUILD_ROOT/$TOPDIR/SOURCES/build.script
2123 if test -n "$shell"; then
2124 chroot $BUILD_ROOT su -
2126 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && $DSC_BUILD_CMD" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2129 mkdir -p $BUILD_ROOT/$TOPDIR/DEBS
2130 for DEB in $BUILD_ROOT/$TOPDIR/*.deb ; do
2131 test -e "$DEB" && mv "$DEB" "$BUILD_ROOT/$TOPDIR/DEBS"
2134 ln $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE $BUILD_ROOT/$TOPDIR/DEBS/
2136 ln $BUILD_ROOT/$DEB_SOURCEDIR/$f $BUILD_ROOT/$TOPDIR/DEBS/
2137 done < <(sed -ne '/^Files:/,$s/^ ................................ [0-9][0-9]* //p' < $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE)
2140 if test "$BUILDTYPE" = arch ; then
2141 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && makepkg -f" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2142 mkdir -p $BUILD_ROOT/$TOPDIR/ARCHPKGS
2143 for PKG in $BUILD_ROOT/$TOPDIR/BUILD/*.pkg.tar.?z ; do
2144 test -e "$PKG" && mv "$PKG" "$BUILD_ROOT/$TOPDIR/ARCHPKGS"
2148 if test "$BUILDTYPE" = kiwi ; then
2149 . $BUILD_DIR/build_kiwi.sh
2153 test "$BUILD_SUCCEEDED" = true || cleanup_and_exit 1
2154 test -d "$SRCDIR" && cd "$SRCDIR"
2157 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
2158 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
2160 if test -n "$RPMS" -a -n "$BUILD_USER_ABUILD_USED" ; then
2161 echo "... checking for files with abuild user/group"
2163 while read un gn fn ; do
2164 if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
2168 done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
2169 if test -n "$BADFILE" ; then
2170 echo "please fix your filelist (e.g. add defattr)"
2175 if test -n "$RPMS" -a -d "$BUILD_ROOT/usr/lib/build/checks" ; then
2177 export DO_RPM_REMOVE=true
2178 for SRPM in $BUILD_ROOT/$TOPDIR/SRPMS/*src.rpm ; do
2179 test -f "$SRPM" && PNAME=`rpm --nodigest --nosignature -qp --qf "%{NAME}" $SRPM`
2181 for CHECKSCRIPT in $BUILD_ROOT/usr/lib/build/checks/* ; do
2182 echo "... running `basename $CHECKSCRIPT`"
2183 $CHECKSCRIPT || cleanup_and_exit 1
2187 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
2188 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
2190 if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_ROOT/opt/testing/bin/rpmlint" ; then
2191 LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
2192 \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
2193 -o -name "*-32bit-*" -o -name "*-64bit-*" \
2194 -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
2195 -o -type f -name '*.rpm' -print))
2196 SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
2198 echo "RPMLINT report:"
2199 echo "==============="
2200 rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log
2201 rm -f "$BUILD_ROOT$rpmlint_logfile"
2203 chroot $BUILD_ROOT su -s /opt/testing/bin/rpmlint "$BUILD_USER" -- \
2204 --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} \
2205 ${SRPM_FILE_LIST[*]#$BUILD_ROOT} > "$BUILD_ROOT$rpmlint_logfile" || ret=1
2206 cat "$BUILD_ROOT$rpmlint_logfile"
2208 if test "$ret" = 1; then
2213 if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS"; then
2218 # post build scripts
2219 # TODO: don't hardcode. instead run scripts in a directory as it's done for the checks
2220 if test -n "$RPMS" \
2221 -a -d "$BUILD_ROOT/$TOPDIR/RPMS" \
2222 -a -d "$BUILD_ROOT/.build.oldpackages" \
2224 if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
2225 echo "... comparing built packages with the former built"
2226 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
2227 if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
2228 chroot $BUILD_ROOT touch /.build/.same_result_marker
2229 # XXX: dirty build service hack. fix bs_worker. Search for
2230 # 'same_result_marker' for traces of a first try to get rid of this
2231 if test -n "$REASON" -a -n "$DISTURL"; then
2236 if test ! -e $BUILD_ROOT/.build/.same_result_marker \
2237 -a -x "$BUILD_ROOT/usr/bin/makedeltarpm" \
2238 -a -x $BUILD_ROOT/usr/lib/build/mkdrpms; then
2239 echo "... creating delta rpms"
2240 ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS")
2241 chroot $BUILD_ROOT /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}"
2245 if test -n "$RUNNING_IN_VM" -a -n "$VM_SWAP"; then
2246 echo "... saving built packages"
2248 args="--padstart 512 --padend 512 -v"
2249 case "$BUILDTYPE" in
2251 computeblocklists $args $TOPDIR/RPMS/*/*.{d,}rpm $TOPDIR/SRPMS/* $TOPDIR/OTHER/* > "$VM_SWAP"
2254 computeblocklists $args $TOPDIR/DEBS/*.deb $TOPDIR/SOURCES.DEB/* $TOPDIR/OTHER/* > "$VM_SWAP"
2257 computeblocklists $args $TOPDIR/KIWI/* $TOPDIR/OTHER/* > "$VM_SWAP"
2260 computeblocklists $args $TOPDIR/ARCHPKGS/* $TOPDIR/OTHER/* > "$VM_SWAP"
2262 esac || cleanup_and_exit 1
2266 echo "$HOST finished \"build $SPECFILE\" at `date --utc`."
2269 cleanup_and_exit "$exitcode"