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
12 test -z "$CONFIG_DIR" && CONFIG_DIR="$BUILD_DIR/configs"
14 export BUILD_ARCH BUILD_HOST_ARCH BUILD_ROOT BUILD_RPMS BUILD_DIR BUILD_DEBUG
24 # defaults for vm_img_mkfs
25 vm_img_mkfs_ext4='mkfs.ext4 -m 0 -q -F'
26 vm_img_tunefs_ext4='tune2fs -c 0 -O ^has_journal -o nobarrier,discard'
27 vm_img_mkfs_ext3='mkfs.ext3 -m 0 -q -F'
28 vm_img_tunefs_ext3='tune2fs -c 0 -o journal_data_writeback'
29 vm_img_mkfs_ext2='mkfs.ext2 -m 0 -q -F'
30 vm_img_tunefs_ext2='tune2fs -c 0'
31 vm_img_mkfs_reiserfs='mkreiserfs -q -f'
32 vm_img_mkfs_btrfs='mkfs.btrfs'
34 vm_kernel=/boot/vmlinuz
35 vm_initrd=/boot/initrd
36 qemu_bin=/usr/bin/qemu
37 uml_kernel=/boot/vmlinux-um
38 uml_initrd=/boot/initrd-um
40 kvm_bin=/usr/bin/qemu-kvm
41 # whether we have virtio support
44 # guest visible console device name
47 # need to restore build root owner for non-root builds
50 # Default uid:gid for the build user
72 VMDISK_FILESYSTEM=ext4
73 # settings are for speed and not data safety, we format anyway on next run
74 VMDISK_MOUNT_OPTIONS=__default
98 # list of archs which need emulator initialization
99 : ${EMULATOR_ARCHS:="armv4l armv5l armv6l armv7l armv5el armv6el armv7el armv7hl armv8el mips mipsel mips64 mips64el ppc ppc64 sh4 sparc sparc64 s390 s390x"}
100 export EMULATOR_ARCHS
102 # list of devices registered by binfmt handlers in /proc/sys/fs/binfmt_misc
103 : ${EMULATOR_DEVS:="arm armeb mips mipsel mips64 mips64el ppc sh4 sh4eb sparc s390x"}
106 # This is for insserv
107 export YAST_IS_RUNNING=instsys
117 Some comments for build
118 -----------------------
120 With build you can create rpm packages. They will be built in a chroot
121 system. This chroot system will be setup automatically. Normally you can
122 simply call build with a spec file as parameter - nothing else has to be
125 If you want to set the directory were the chroot system will be setup
126 (at the moment it uses $BUILD_ROOT),
127 simply set the the environment variable BUILD_ROOT.
131 export BUILD_ROOT=/var/tmp/mybuildroot
134 Normally build builds the complete package including src.rpm (rpmbuild -ba).
135 If you want let build only make the binary package, simply set
137 export BUILD_RPM_BUILD_STAGE=-bb
139 (or -bc, -bp, -bi, ... see "Maximum RPM" for more details [*]).
141 When the build command succeeds, the rpm files can be found under
142 $BUILD_ROOT/usr/src/packages/RPMS/
147 --help You already got it :)
149 --kill Instead of starting a build kill the one currently
152 --shell Instead of starting a build start a root shell in
155 --clean Delete old build root before initializing it
157 --no-init Skip initialization of build root and start with build
160 --no-checks Do not run post-build checks
162 --lint Run rpmlint after build.
165 Capture build output to logfile. Defaults to
166 .build.log in the build root for non-VM builds.
169 Use package repository at PATH. Supported formats are
171 Alternatively zypp://NAME specifies the zypp
172 repository NAME. The repo must be refreshed with zypp
173 so package meta data is available locally. With emtpy
174 NAME all enabled repositories are used.
175 a url can specify a remote repo.
177 --rpms path1:path2:...
178 Specify path where to find the RPMs for the build system
180 --arch arch1:arch2:...
181 Specify what architectures to select from the RPMs
183 --verify Run verify when initializing the build root
187 Also install package 'pack'
190 Use 'rootdir' to setup chroot environment
193 Use 'cachedir' to cache remote repo's packages, the
194 default cache dir is /var/cache/build, every repo
195 given by --repository corresponds to a subdir named
196 as md5sum of its repo url, for example:
197 /var/cache/build/3e8ea9b47808629414a0cebc33ea285e
199 --oldpackages oldpackagesdir
200 Define a directory with a former build
202 --baselibs Create -32bit/-64bit/-x86 rpms for other architectures
205 List rpms that would be used to create a fresh build root.
206 Does not create the build root or perform a build.
212 Enable feature X for build
215 Disable feature X for build
218 Define macro X with value Y
221 Override Release in spec file
224 Set stage for rpmbuild. Defaults to -ba.
227 Set target platform for rpmbuild
229 --jobs N Use N parallel processes during build.
230 Sets %jobs and %_smp_mflags macros and
231 defines the number of CPUs to use for
235 Use ccache to speed up rebuilds
238 Use N parallel build jobs with icecream
241 Copy overlay filesystem to buildroot after installing
242 all RPMs. This must be a valid directory.
245 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
246 inside the buildroot using rsync.
247 It will "%define RSYNCDONE 1" for handling %setup in your
251 %setup -n aaa_base -T -D -b 5 -b 7
253 %setup -n aaa_base -b 5 -b 7
256 --rsync-dest RSYNCDEST
257 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
258 inside the buildroot using rsync.
261 Specify the uid and gid to use for the abuild user.
262 This is useful if you are hacking in the buildroot.
263 This must be set to the same value if the buildroot is re-used.
266 Use virtual machine instead of chroot
267 TYPE is one of xen|kvm|uml|qemu|lxc
270 Use FILE as disk for virtual machine.
271 Defaults to \$BUILD_ROOT.img if unset
274 Use FILE as swap space for virtual machine. The swap space is
275 also used for retrieving packages from the VM so its size must
276 be sufficiently large
278 --vm-disk-size SIZEINMB
279 --vm-swap-size SIZEINMB
280 --vm-disk-filesystem TYPE
281 Defaults for automatic setup of VM root/swap files
284 Set amount of RAM for VMs
286 --hugetlbfs HUGETLBFSPATH
287 Use hugetlb for memory management, path to mounted hugetlbfs.
291 Kernel and initrd to use for VM (kvm and qemu only)
294 Enable creation of a debuginfo package
296 Remember to have fun!
298 [*] Maximum RPM: http://www.rpm.org/max-rpm/
302 echo "Usage: `basename $0` [--no-init|--clean|--rpms path|--verify|--help] [dir-to-build|spec-to-build]"
308 # return values: 0 -> success, new packages built
309 # 1 -> error, build failed
310 # 2 -> successfull build, but no changes to former built packages
311 # 3 -> something wrong with build host
313 cleanup_and_exit () {
315 test -z "$1" && set 0
316 rm -f $BUILD_ROOT/exit
317 if test "$1" -eq 1 -a -x /bin/df ; then
318 # okay, it failed, but maybe because disk space?
319 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
323 if test -n "$RUNNING_IN_VM" ; then
324 test -n "$browner" && chown "$browner" $BUILD_ROOT
326 if test -n "$VM_SWAP" -a -e "$VM_SWAP" ; then
327 swapoff "$VM_SWAP" 2>/dev/null
328 echo -n "BUILDSTATUS$1" >"$VM_SWAP"
330 exec >&0 2>&0 # so that the logging tee finishes
331 sleep 1 # wait till tee terminates
332 if test "$VM_TYPE" != lxc; then
333 kill -9 -1 # goodbye cruel world
334 if ! test -x /sbin/halt ; then
335 test -e /proc/sysrq-trigger || mount -n -tproc none /proc
337 sleep 2 # like halt does
338 if test -e /proc/sysrq-trigger; then
339 echo o > /proc/sysrq-trigger
340 sleep 5 # wait for sysrq to take effect
342 echo "Warning: VM doesn't support sysrq and /sbin/halt not installed"
347 echo "Warning: clean shut down of the VM didn't work"
350 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
351 umount -n $BUILD_ROOT/proc 2>/dev/null || true
352 umount -n $BUILD_ROOT/dev/pts 2>/dev/null || true
353 test "$VM_IMAGE" = 1 && VM_IMAGE=
354 [ -n "$VM_IMAGE" ] && umount $BUILD_ROOT 2>/dev/null || true
356 # echo "pid $$ exit $1"
376 # create a shell script from command line. Used for preserving arguments
388 if [ "$ccache" = 1 ]; then
389 if mkdir -p $BUILD_ROOT/var/lib/build/ccache/bin; then
390 for i in $(ls $BUILD_ROOT/usr/bin | grep -E '^(cc|gcc|[cg][+][+])([-]?[234][.]?[0-9])*$'); do
391 # ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
392 rm -f $BUILD_ROOT/var/lib/build/ccache/bin/$i
393 test -e $BUILD_ROOT/usr/bin/$i || continue
394 echo '#! /bin/sh' > $BUILD_ROOT/var/lib/build/ccache/bin/$i
395 echo "test -e /usr/bin/$i || exit 1" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
396 echo 'export PATH=/opt/icecream/bin:/usr/bin:$PATH' >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
397 echo "ccache $i \"\$@\"" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
398 chmod 755 $BUILD_ROOT/var/lib/build/ccache/bin/$i
399 echo "Installed ccache wrapper as $BUILD_ROOT/var/lib/build/ccache/bin/$i"
402 mkdir -p "$BUILD_ROOT"/.ccache
403 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/.ccache"
404 echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
405 echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
407 rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
413 if [ "$icecream" -eq 0 ]; then
414 rm -rf "$BUILD_ROOT/var/run/icecream"
415 rm -f "$BUILD_ROOT/etc/profile.d/build_icecream.sh"
419 if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then
420 echo "*** icecream package not installed ***"
425 echo "using icecream with $icecream jobs"
427 if [ "$ccache" -ne 1 ]; then
428 echo 'export PATH=/opt/icecream/bin:$PATH' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
430 echo 'export CCACHE_PATH=/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
433 local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
434 icecc_vers=${icecc_vers//$BUILD_ROOT/}
436 # XXX use changelog like autobuild does instead?
437 # only run create-env if compiler or glibc changed
438 if [ -z "$icecc_vers" \
439 -o ! -e "$BUILD_ROOT/$icecc_vers" \
440 -o "$BUILD_ROOT/usr/bin/gcc" -nt "$BUILD_ROOT/$icecc_vers" \
441 -o "$BUILD_ROOT/usr/bin/g++" -nt "$BUILD_ROOT/$icecc_vers" \
442 -o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
443 -o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers" ]
445 rm -rf "$BUILD_ROOT/var/run/icecream"
446 mkdir -p "$BUILD_ROOT/var/run/icecream"
447 if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
448 createenv=/usr/bin/create-env
449 elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
450 createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
451 elif [ -e "$BUILD_ROOT"/usr/lib64/icecc/icecc-create-env ]; then
452 createenv="/usr/lib64/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
454 echo "create-env not found"
458 chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv" || cleanup_and_exit 1
459 icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
460 icecc_vers=${icecc_vers//$BUILD_ROOT/}
462 echo "reusing existing icecream environment $icecc_vers"
464 if [ -n "$icecc_vers" ]; then
465 echo "export ICECC_VERSION=$icecc_vers" >> "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
471 if [ -n "$VM_IMAGE" -o -n "$RUNNING_IN_VM" ]; then
480 eval "limit=\$(($2/3*4))"
484 eval "limit=\$(($2/3*4+$limit))"
487 done < <(cat /proc/meminfo) # cat for proc stuff
490 echo "Memory limit set to ${limit}KB"
500 if test "$BUILDTYPE" == "arch" ; then
503 if test "$BUILDTYPE" == "dsc" ; then
506 if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
507 BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
509 if test -e $BUILD_ROOT/usr/lib/build/baselibs_global.conf; then
510 BASELIBS_GLOBAL="-c /usr/lib/build/baselibs_global.conf"
515 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
516 # don't use -R as extracted sources, build root etc might be below $TOPDIR
517 chown "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"/* "$BUILD_ROOT$TOPDIR"/RPMS/* || true
519 local mkbaselibs="/usr/lib/build/mkbaselibs"
521 # $BUILD_DIR is set to /.build when using a vm. So we need to
522 # hardcode /usr/lib/build instead of $BUILD_DIR to prefer
523 # mkbaselibs from the distro.
524 if test -f $BUILD_ROOT$mkbaselibs; then
525 if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
526 BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
529 if test "$CREATE_BASELIBS" = 'internal'; then
530 echo "Warning: mkbaselibs missing in build root, skipping baselibs"
533 # use external version
534 whichone=" (external)"
535 mkbaselibs="/.mkbaselibs/mkbaselibs"
536 rm -rf "$BUILD_ROOT/.mkbaselibs"
537 mkdir -p "$BUILD_ROOT/.mkbaselibs"
538 cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs/
539 if test "$BUILDTYPE" == "dsc" ; then
540 cp -f $BUILD_DIR/baselibs_global-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
541 cp -f $BUILD_ROOT$TOPDIR/SOURCES/baselibs-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs-deb.conf
542 BASELIBS_CFG="-c /.mkbaselibs/baselibs-deb.conf"
544 cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
545 if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf; then
546 cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf
547 BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf"
550 if test -e $BUILD_ROOT/.mkbaselibs/baselibs_g.conf; then
551 BASELIBS_GLOBAL="-c /.mkbaselibs/baselibs_g.conf"
554 echo "... creating baselibs$whichone"
557 chroot $BUILD_ROOT su -c "$mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG $line" - $BUILD_USER || cleanup_and_exit 1
558 done < <(IFS=$'\n'; echo "${pkgs[*]#$BUILD_ROOT}" | xargs -n 1024)
559 rm -rf "$BUILD_ROOT/.mkbaselibs"
567 [ -z "$RUNNING_IN_VM" ] || return 0
568 if [ -z "$old_packages" ]; then
569 rm -rf "$BUILD_ROOT"/.build.oldpackages*
572 for d in "${old_packages[@]}"; do
573 dest="$BUILD_ROOT/.build.oldpackages"
574 test "$i" = 0 || dest="$dest$i"
575 if [ -d "$d" -a "$d" != "$dest" ] ; then
589 eval "mkfs=\"\$vm_img_mkfs_${fs}\""
590 eval "tunefs=\"\$vm_img_tunefs_${fs}\""
592 if test -z "$mkfs"; then
593 echo "filesystem \"$fs\" isn't supported"
598 echo "Creating $fs filesystem on $img"
600 if test -n "$tunefs" ; then
601 $tunefs "$img" || cleanup_and_exit 3
606 detect_vm_2nd_stage()
608 if ! test "$0" = "/.build/build" ; then
611 if test $$ -eq 1 ; then
612 # ignore special init signals if we're init
613 # we're using ' ' instead of '' so that the signal handlers
614 # are reset in the child processes
619 echo "2nd stage started in virtual machine"
622 . $BUILD_DIR/build.data
623 echo "machine type: `uname -m`"
624 if test "$PERSONALITY" != 0 -a -z "$PERSONALITY_SET" ; then
625 export PERSONALITY_SET=true
626 echo "switching personality to $PERSONALITY..."
627 # this is 32bit perl/glibc, thus the 32bit syscall number
628 exec perl -e 'syscall(136, '$PERSONALITY') == -1 && warn("personality: $!\n");exec "/.build/build" || die("/.build/build: $!\n")'
631 test -e /proc/version || mount -orw -n -tproc none /proc
632 if test "$VM_TYPE" != 'lxc'; then
633 mount -n ${VMDISK_MOUNT_OPTIONS},remount,rw /
635 umount /run >/dev/null 2>&1
636 # qemu inside of xen does not work, check again with kvm later before enabling this
637 # if [ -e /dev/kqemu ]; then
638 # # allow abuild user to run qemu
639 # chmod 0666 /dev/kqemu
641 if test -n "$VM_SWAP" ; then
642 for i in 1 2 3 4 5 6 7 8 9 10 ; do
643 test -e "$VM_SWAP" && break
644 test $i = 1 && echo "waiting for $VM_SWAP to appear"
649 # recreate the swap device manually if it didn't exist for some
650 # reason, hardcoded to hda2 atm
651 if ! test -b "$VM_SWAP" ; then
654 mknod "$VM_SWAP" b 3 2
657 swapon -v "$VM_SWAP" || exit 1
667 if [ -z "$SPECFILES" ]; then
670 set -- "${SPECFILES[@]}"
674 if [ "$spec" = "${spec#/}" ]; then
678 if [ -d "$spec" ]; then
679 specs=("$spec"/*.spec)
680 if [ -n "$specs" ]; then
681 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
683 specs=("$spec"/*.spec)
684 if [ -n "$specs" ]; then
685 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
689 SPECFILES[${#SPECFILES[@]}]="$spec";
693 if test -z "$SPECFILES"; then
694 echo no spec files or src rpms found in $@. exit...
699 become_root_or_fail()
701 if [ ! -w /root ]; then
702 echo "You have to be root to use $0" >&2
710 if [ -d "$BUILD_ROOT" ]; then
711 # check if it is owned by root
712 if [ -z "$RUNNING_IN_VM" -a \! -O "$BUILD_ROOT" -a "`stat -c %u $BUILD_ROOT`" -ne 0 ]; then
713 echo "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
717 test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
718 if ! mkdir $BUILD_ROOT; then
719 echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
724 if [ ! -w "$BUILD_ROOT" ]; then
725 echo "Error: BUILD_ROOT=$BUILD_ROOT not writeable, try --clean."
729 rm -rf "$BUILD_ROOT/.build.packages"
730 if [ -z "$VM_TYPE" -a -z "$RUNNING_IN_VM" ]; then
731 # don't touch this in VM
732 rm -rf "$BUILD_ROOT/.build"
733 mkdir -p "$BUILD_ROOT/.build"
739 perl -e 'syscall('$PERSONALITY_SYSCALL', 0); exec(@ARGV) || die("$ARGV[0]: $!\n")' "$@"
748 if [ "$uname" != "ppc" -a "$uname" != "ppc64" ]; then
754 # XXX is this ok for ppc32 hosts? do we care?
755 export kvm_bin="/usr/bin/qemu-system-ppc64"
757 # XXX check host CPU and adjust guest CPU accordingly
758 export KVM_OPTIONS="-enable-kvm -M pseries -mem-path /hugetlbfs"
759 export VM_KERNEL=/boot/vmlinux
760 export VM_INITRD=/boot/initrd
761 if [ -z "$RUNNING_IN_VM" -a "$VM_TYPE" = "kvm" ];then
762 if ! grep "/hugetlbfs" /proc/mounts; then
763 echo "hugetlbfs is not mounted"
766 PAGES_FREE=$(cat /sys/kernel/mm/hugepages/hugepages-16384kB/free_hugepages)
767 PAGES_REQ=$(( ${MEMSIZE:-64} / 16 ))
768 if [ "$PAGES_FREE" -lt "$PAGES_REQ" ];then
769 echo "please adjust nr_hugepages"
772 if ! grep -q kvm_rma_count /proc/cmdline; then
773 echo "put kvm_rma_count=<VM number> to your boot options"
776 if ! grep -q kvm_hpt_count /proc/cmdline; then
777 echo "put kvm_hpt_count=<VM number> to your boot options"
787 archname=`perl -V:archname`
788 archname="${archname#archname=?}"
790 x86_64*) PERSONALITY_SYSCALL=135 ;;
791 alpha*) PERSONALITY_SYSCALL=324 ;;
792 sparc*) PERSONALITY_SYSCALL=191 ;;
793 ia64*) PERSONALITY_SYSCALL=1140 ;;
794 i?86*|ppc*|arm*|sh4|cris|m68k|s390*|unicore32|microblaze) PERSONALITY_SYSCALL=136 ;;
795 *) echo "ARCHITECTURE PERSONALITY IS UNKNOWN"; exit 1;;
800 if detect_vm_2nd_stage ; then
801 set "/.build-srcdir/$SPECFILE"
804 export PATH=$BUILD_DIR:/sbin:/usr/sbin:$PATH
806 . $BUILD_DIR/common_functions || exit 1
812 if [ -z "$ARG" ]; then
813 echo "$PARAM needs an agrument" >&2
818 while test -n "$1"; do
821 [ "$ARG" = "${ARG#-}" ] || ARG=""
827 set -- "----noarg=$PARAM" "$@"
841 CLEAN_BUILD='--clean'
857 export VERIFY_BUILD_SYSTEM=true
871 BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
881 CREATE_BASELIBS=internal
884 USE_SYSTEM_QEMU="--use-system-qemu"
898 old_packages=("${old_packages[@]}" "$ARG")
906 *-xen|*-kvm|--uml|--qemu)
908 if [ -n "$ARG" ]; then
922 xen|kvm|uml|qemu|lxc)
923 test -z "$VM_IMAGE" && VM_IMAGE=1
925 none|chroot) VM_TYPE='' ;;
927 echo "VM $VM_TYPE not supported"
943 *-xenmemory|*-memory)
958 *-vmdisk-rootsize|--vm-disk-size)
960 VMDISK_ROOTSIZE="$ARG"
963 *-vmdisk-swapsize|--vm-swap-size)
965 VMDISK_SWAPSIZE="$ARG"
968 *-vmdisk-filesystem|--vm-disk-filesystem)
970 VMDISK_FILESYSTEM="$ARG"
973 *-vmdisk-mount-options|--vm-disk-mount-options)
975 # options needs to be quoted to handle argument which might start with "-o ..."
976 VMDISK_MOUNT_OPTIONS=$(echo $ARG | sed 's/^\"\(.*\)\"$/\1/g')
980 # delete old root/swap to get rid of the old blocks
985 RPMLIST="--rpmlist $ARG"
1013 BUILD_RPM_BUILD_STAGE="$ARG"
1017 USEUSEDFORBUILD="--useusedforbuild"
1025 --define|--with|--without)
1027 definesnstuff[${#definesnstuff[@]}]="$PARAM";
1028 definesnstuff[${#definesnstuff[@]}]="$ARG";
1031 --repository|--repo)
1033 repos[${#repos[@]}]="$PARAM";
1034 repos[${#repos[@]}]="$ARG";
1040 if [ "$icecream" -gt 0 ]; then
1065 echo "$ARG does not take an argument"
1089 if test -n "${ABUILD_ID//[0-9:]/}"; then
1090 echo "--uid argument must be uid:gid"
1093 ABUILD_UID=${ABUILD_ID%:*}
1094 ABUILD_GID=${ABUILD_ID#*:}
1105 echo Unknown Option "$PARAM". Exit.
1109 SPECFILES[${#SPECFILES[@]}]="$PARAM";
1116 if test "$VM_TYPE" = "lxc"; then
1121 if test "$VMDISK_MOUNT_OPTIONS" = __default; then
1122 if test "$VMDISK_FILESYSTEM" = reiserfs ; then
1123 VMDISK_MOUNT_OPTIONS='-o data=writeback,commit=150,noatime'
1124 elif test "$VMDISK_FILESYSTEM" = btrfs ; then
1125 VMDISK_MOUNT_OPTIONS='-o nobarrier,noatime'
1127 VMDISK_MOUNT_OPTIONS='-o data=writeback,nobarrier,commit=150,noatime'
1131 if test -n "$KILL" ; then
1132 test -z "$SRCDIR" || usage
1133 if test -n "$VM_IMAGE" -a -n "$VM_SWAP" -a -n "$VM_TYPE"; then
1134 # mark job as failed so that we don't extract packages
1135 echo -n "BUILDSTATUS1" >"$VM_SWAP"
1137 (set -C; > "$BUILD_ROOT/exit" 2>/dev/null || true)
1138 if test "$VM_TYPE" = 'lxc'; then
1139 LXCID=${BUILD_ROOT##*/}
1140 lxc-stop -n "$LXCID" || true
1141 lxc-destroy -n "$LXCID"
1142 elif test -z "$VM_IMAGE" ; then
1143 if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
1144 echo "could not kill build in $BUILD_ROOT"
1147 elif test "$VM_TYPE" = 'xen'; then
1148 XENID="${VM_IMAGE%/root}"
1149 XENID="${XENID%/tmpfs}"
1150 XENID="${XENID##*/}"
1151 XENID="${XENID#root_}"
1152 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1153 if ! xm destroy "build_$XENID" ; then
1154 echo "could not kill xen build $XENID"
1158 elif test -n "$VM_TYPE"; then
1159 if ! fuser -k -TERM "$VM_IMAGE"; then
1160 echo "could not kill build in $VM_IMAGE"
1164 echo "don't know how to kill this build job"
1170 if [ "$VM_TYPE" = 'xen' -a -z "$RUNNING_IN_VM" ]; then
1171 # XXX: merge with kvm path?
1172 if [ -n "$VM_KERNEL" ]; then
1173 vm_kernel="$VM_KERNEL"
1174 elif [ -e "/boot/vmlinuz-xen" ]; then
1175 vm_kernel="/boot/vmlinuz-xen"
1177 if [ -n "$VM_INITRD" ]; then
1178 vm_initrd="$VM_INITRD"
1179 elif [ -e "/boot/initrd-xen" ]; then
1180 vm_initrd="/boot/initrd-xen"
1184 if [ "$VM_TYPE" = 'kvm' -a -z "$RUNNING_IN_VM" ]; then
1185 if [ ! -r /dev/kvm -o ! -x "$kvm_bin" ]; then
1186 echo "host doesn't support kvm"
1187 echo "either the kvm kernel-module is not loaded or kvm is not installed or hardware virtualization is deactivated in the BIOS."
1191 if [ -n "$VM_KERNEL" ]; then
1192 vm_kernel="$VM_KERNEL"
1195 # check if a SUSE system with virtio initrd is running
1196 if [ -z "$VM_INITRD" -a -e /etc/sysconfig/kernel ]; then
1197 a=$( source /etc/sysconfig/kernel; echo $INITRD_MODULES )
1201 [ "$i" == "virtio_pci" ] && have_virtio_pci="1"
1202 [ "$i" == "virtio_blk" ] && have_virtio_blk="1"
1204 [ -n "$have_virtio_pci" -a -n "$have_virtio_blk" ] && VM_INITRD="/boot/initrd"
1207 if [ -n "$VM_INITRD" ]; then
1208 vm_initrd="$VM_INITRD"
1210 elif [ -e "${vm_initrd}-build" ]; then
1211 vm_initrd="${vm_initrd}-build"
1214 if [ -L "$vm_initrd" ]; then
1215 vm_initrd=`readlink -f "$vm_initrd"` || cleanup_and_exit 3
1217 vm_initrd_virtio="${vm_initrd}-virtio"
1219 if [ ! -e ${vm_initrd_virtio} -o $vm_kernel -nt ${vm_initrd_virtio} ]; then
1220 mkinitrd_virtio_cmd=(env rootfstype="$VMDISK_FILESYSTEM" \
1221 mkinitrd -d /dev/null \
1222 -m "ext3 ext4 btrfs reiserfs binfmt_misc virtio_pci virtio_blk" \
1224 -i ${vm_initrd_virtio})
1225 if [ ! -w /root -o -n "$RPMLIST" ]; then
1226 echo "No initrd that provides virtio support found. virtio accelleration disabled."
1227 echo "Run the following command as root to enable virtio:"
1228 shellquote "${mkinitrd_virtio_cmd[@]}"
1230 elif /sbin/modinfo virtio_pci >/dev/null 2>&1; then
1231 echo "creating $vm_initrd_virtio"
1232 "${mkinitrd_virtio_cmd[@]}" || cleanup_and_exit 1
1234 vm_initrd="${vm_initrd_virtio}"
1238 vm_initrd="${vm_initrd_virtio}"
1242 if [ "$HOST_ARCH" = ppc ]; then
1243 # KVM on PPC can not run virtio yet, so we need to use the default vio
1247 if [ "$kvm_virtio" = 1 ]; then
1249 qemu_rootdev=/dev/vda
1252 qemu_rootdev=/dev/sda
1256 if [ "$VM_TYPE" = 'qemu' ]; then
1258 qemu_rootdev=/dev/sda
1261 if [ -z "$RPMLIST" -a -z "$RUNNING_IN_VM" ]; then
1262 if [ -z "$repos" -a -z "$BUILD_RPMS" ]; then
1263 repos=(--repository 'zypp://')
1271 if [ -n "$CLEAN_BUILD" ]; then
1277 if test -n "$LIST_STATE" ; then
1278 BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
1279 test -d "$BUILD_ROOT" || cleanup_and_exit 3
1280 SPECFILE=$SPECFILES # only one specified anyways
1281 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1282 rm -rf "$BUILD_ROOT/usr/src/packages"
1283 mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES $BUILD_ROOT/usr/src/packages/SPECS
1284 rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
1285 echo "could not install $SPECFILE." 2>&1
1286 rm -rf "$BUILD_ROOT"
1289 for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
1291 init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" --list-state "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
1293 rm -rf "$BUILD_ROOT"
1294 cleanup_and_exit $ERR
1297 if test -z "$RUNNING_IN_VM" ; then
1298 if test -n "$VM_IMAGE" ; then
1299 if test "$VM_IMAGE" = 1 ; then
1300 VM_IMAGE="$BUILD_ROOT.img"
1301 echo "using $VM_IMAGE as vm image"
1302 if test -z "$VM_SWAP"; then
1303 VM_SWAP="$BUILD_ROOT.swap"
1304 echo "using $VM_SWAP as vm swap"
1307 if [ "$VM_TYPE" = 'xen' ]; then
1308 # this should not be needed, but sometimes a xen instance got lost
1309 XENID="${VM_IMAGE%/root}"
1310 XENID="${XENID%/tmpfs}"
1311 XENID="${XENID##*/}"
1312 XENID="${XENID#root_}"
1313 xm destroy "build_$XENID" >/dev/null 2>&1
1315 if test -n "$VMDISK_CLEAN" ; then
1316 # delete old root/swap to get rid of the old blocks
1317 if test -f "$VM_IMAGE" ; then
1318 echo "Deleting old $VM_IMAGE"
1321 if test -n "$VM_SWAP" -a -f "$VM_SWAP" ; then
1322 echo "Deleting old $VM_SWAP"
1326 if test ! -e "$VM_IMAGE"; then
1327 echo "Creating $VM_IMAGE (${VMDISK_ROOTSIZE}M)"
1328 mkdir -p "${VM_IMAGE%/*}"
1329 dd if=/dev/zero of="$VM_IMAGE" bs=1M count=0 seek="$VMDISK_ROOTSIZE" || cleanup_and_exit 3
1330 if test -z "$CLEAN_BUILD" ; then
1331 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1334 if test -n "$VM_SWAP" -a ! -e "$VM_SWAP"; then
1336 echo "Creating $VM_SWAP (${VMDISK_SWAPSIZE}M)"
1337 mkdir -p "${VM_SWAP%/*}"
1338 dd if=/dev/zero of="$VM_SWAP" bs=1M count=0 seek="$VMDISK_SWAPSIZE" || cleanup_and_exit 3
1340 if test ! -e "$VM_IMAGE" ; then
1341 echo "you need to create $VM_IMAGE first"
1344 if test -n "$CLEAN_BUILD" ; then
1345 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1348 if [ -w /root ]; then
1349 if [ -b $VM_IMAGE ]; then
1350 # mount device directly
1351 mount $VMDISK_MOUNT_OPTIONS $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1353 mount ${VMDISK_MOUNT_OPTIONS},loop $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1356 if ! mount $BUILD_ROOT; then
1357 echo "mounting the build root failed. An fstab entry is probably missing or incorrect."
1358 echo "/etc/fstab should contain an entry like this:"
1359 echo "$VM_IMAGE $BUILD_ROOT auto noauto,user,loop 0 0"
1364 test -w /root || become_root_or_fail
1366 if test -n "$VM_SWAP" ; then
1367 dd if=/dev/zero of="$VM_SWAP" bs=12 count=1 conv=notrunc 2>/dev/null
1368 echo "mkswap $VM_SWAP"
1375 if [ "$BUILD_ROOT" = / ]; then
1376 read dummy dummy browner dummy < <(ls -ld /)
1379 rm -f $BUILD_ROOT/exit
1381 if [ -w /root ]; then
1382 mkdir -p $BUILD_ROOT/proc
1383 mkdir -p $BUILD_ROOT/dev/pts
1384 mount -n -tproc none $BUILD_ROOT/proc || true
1385 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1388 if test -z "$VM_IMAGE" -a -z "$LOGFILE"; then
1389 LOGFILE="$BUILD_ROOT/.build.log"
1392 if test -n "$LOGFILE" -a -z "$shell" ; then
1393 echo logging output to $LOGFILE...
1396 # set start time, to be substracted for build log timestamps
1397 STARTTIME=`perl -e 'print time()'`
1399 if [ -n "$RUNNING_IN_VM" ]; then
1400 # no additional timestamps in inner vm build system
1401 exec 1> >(exec -a 'build logging' tee -a $LOGFILE) 2>&1
1402 elif test -n "$VM_IMAGE" ; then
1403 # external run of virtualization build
1404 exec 1> >(exec -a 'build logging' perl -e 'open(F,">>",$ARGV[0])||die("$ARGV[0]: $!\n");$|=1;select(F);$|=1;while(<STDIN>){my $p=sprintf("[%5ds] ", time()-'$STARTTIME');print STDOUT $p.$_;s/^\r//s;s/\r\n/\n/gs;print F $p.$_}' $LOGFILE) 2>&1
1407 exec 1> >(exec -a 'build logging' perl -e 'open(F,">>",$ARGV[0])||die("$ARGV[0]: $!\n");$|=1;select(F);$|=1;while(<STDIN>){my $p=sprintf("[%5ds] ", time()-'$STARTTIME');print STDOUT $p.$_;print F $p.$_}' $LOGFILE) 2>&1
1416 test -z "$HOST" && HOST=`hostname`
1418 if [ -z "$RUNNING_IN_VM" ]; then
1419 echo Using BUILD_ROOT=$BUILD_ROOT
1420 test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
1421 echo Using BUILD_ARCH=$BUILD_ARCH
1422 test -n "$VM_TYPE" && echo "Doing $VM_TYPE build${VM_IMAGE:+ in $VM_IMAGE}"
1426 test "$BUILD_ARCH" = all && BUILD_ARCH=
1427 BUILD_USER_ABUILD_USED=
1429 for SPECFILE in "${SPECFILES[@]}" ; do
1431 SRCDIR="${SPECFILE%/*}"
1432 SPECFILE="${SPECFILE##*/}"
1436 *.spec|*.src.rpm) BUILDTYPE=spec ;;
1437 *.dsc) BUILDTYPE=dsc ;;
1438 *.kiwi) BUILDTYPE=kiwi ;;
1439 PKGBUILD) BUILDTYPE=arch ;;
1440 _preinstallimage) BUILDTYPE=preinstallimage ;;
1442 if test -z "$BUILDTYPE" ; then
1443 echo "don't know how to build $SPECFILE"
1449 if [ -z "$RUNNING_IN_VM" ]; then
1451 echo "$HOST started \"build $SPECFILE\" at `date --utc`."
1453 test -n "$REASON" && echo "$REASON"
1458 # first setup building directory...
1460 test -s "$SPECFILE" || {
1461 echo "$SPECFILE" is empty. This should not happen...
1465 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1466 echo processing src rpm $SRCDIR/$SPECFILE ...
1467 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1469 mkdir -p "$MYSRCDIR"
1470 cd $MYSRCDIR || cleanup_and_exit 1
1471 $BUILD_DIR/unrpm -q $SRCDIR/$SPECFILE || {
1472 echo "could not install $SPECFILE."
1475 for SPECFILE in *.spec ; do : ; done
1480 # FIX to work with baselibs_$PROJ etc
1481 if test "$BUILDTYPE" == "dsc" -a -e ${SRCDIR}/baselibs-deb.conf ; then
1482 # Set CREATE_BASELIBS if not set
1483 echo "dsc build and baselibs-deb.conf present: forcing --baselibs to true"
1484 CREATE_BASELIBS=true
1487 # Currently local osc build does not allow extra .deb packages to be
1488 # specified on the command line. Both init_buildsystem and expanddeps
1489 # need to handle .deb dependencies first
1490 # if test -n "$CREATE_BASELIBS" ; then
1491 # case $BUILDTYPE in
1493 # dsc) BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS libparse-debcontrol-perl" ;;
1497 echo processing specfile $MYSRCDIR/$SPECFILE ...
1500 test -z "$BUILD_EXTRA_PACKS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
1501 test -z "$CREATE_BASELIBS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
1502 test "$ccache" = '0' || ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
1503 test "$icecream" = 0 || ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
1504 test -z "$DO_LINT" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
1506 if test -n "$CHANGELOG" -a -z "$RUNNING_IN_VM" ; then
1507 rm -f $BUILD_ROOT/.build-changelog
1509 *.dsc) CFFORMAT=debian ;;
1512 echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
1513 if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
1514 rm -f $BUILD_ROOT/.build-changelog
1518 if test -n "$VM_TYPE" -a -z "$RUNNING_IN_VM"; then
1519 rm -rf "$BUILD_ROOT/.build"
1520 mkdir -p "$BUILD_ROOT/.build"
1521 if test "$DO_INIT" = true ; then
1522 # do fist stage of init_buildsystem
1523 rm -f $BUILD_ROOT/.build.success
1524 set -- init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" --prepare "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USE_SYSTEM_QEMU $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1526 "$@" || cleanup_and_exit 1
1528 if [ ! -w /root ]; then
1529 # remove setuid bit if files belong to user to make e.g. mount work
1530 find $BUILD_ROOT/{bin,sbin,usr/bin,usr/sbin} -type f -uid $UID -perm +4000 -print0 | xargs -0 --no-run-if-empty chmod -s
1534 # start up xen, rerun ourself
1535 cp -a $BUILD_DIR/. $BUILD_ROOT/.build
1536 if ! test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1537 rm -rf "$BUILD_ROOT/.build-srcdir"
1538 mkdir "$BUILD_ROOT/.build-srcdir"
1539 if test "$BUILDTYPE" = kiwi ; then
1540 cp -pRL "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1542 cp -p "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1544 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1546 # cwd is at $BUILD_ROOT/.build-srcdir which we want to
1547 # umount later so step aside
1551 echo "SPECFILE='${SPECFILE//"'"/$Q}'" > $BUILD_ROOT/.build/build.data
1552 echo "BUILD_JOBS='${BUILD_JOBS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1553 echo "BUILD_ARCH='${BUILD_ARCH//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1554 echo "BUILD_RPMS='${BUILD_RPMS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1557 cp $BUILD_DIST $BUILD_ROOT/.build/build.dist
1558 BUILD_DIST=/.build/build.dist
1561 echo "BUILD_DIST='${BUILD_DIST//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1562 echo "RELEASE='${RELEASE//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1563 echo "BUILD_DEBUG='${BUILD_DEBUG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1564 echo "SIGNDUMMY='${SIGNDUMMY//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1565 echo "DO_LINT='${DO_LINT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1566 echo "DO_CHECKS='${DO_CHECKS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1567 echo "NOROOTFORBUILD='${NOROOTFORBUILD//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1568 echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
1569 echo "REASON='${REASON//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1570 echo "CHANGELOG='${CHANGELOG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1571 echo "INCARNATION='${INCARNATION//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1572 echo "DISTURL='${DISTURL//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1573 echo "DO_INIT='${DO_INIT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1574 # FIXME: this depends on the kernel and vm.
1575 # could be hda2, sda2 for xen or hdb/sdb for qemu
1576 test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV:-/dev/hda2}'" >> $BUILD_ROOT/.build/build.data
1577 test -n "$VMDISK_MOUNT_OPTIONS" && echo "VMDISK_MOUNT_OPTIONS='${VMDISK_MOUNT_OPTIONS}'" >> $BUILD_ROOT/.build/build.data
1579 if test "$VM_TYPE" != 'lxc'; then
1580 test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
1582 if test "$(uname -m)" = 'ppc'; then
1583 # ppc kernel never tells us if a 32bit personality is active
1586 echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
1587 echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
1588 echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
1589 shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
1590 echo ")" >> $BUILD_ROOT/.build/build.data
1591 echo -n "repos=(" >> $BUILD_ROOT/.build/build.data
1592 shellquote "${repos[@]}" >> $BUILD_ROOT/.build/build.data
1593 echo ")" >> $BUILD_ROOT/.build/build.data
1594 echo "VM_TYPE='$VM_TYPE'" >> $BUILD_ROOT/.build/build.data
1595 echo "shell='$shell'" >> $BUILD_ROOT/.build/build.data
1596 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
1597 umount -n $BUILD_ROOT/proc 2> /dev/null || true
1598 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
1599 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
1601 if [ -n "$VM_IMAGE" ]; then
1603 # needs to work otherwise we have a corrupted file system
1604 umount $BUILD_ROOT || cleanup_and_exit 1
1607 if check_use_emulator; then
1608 if [ -x "$BUILD_DIR/initvm" -a -e "$BUILD_DIR/qemu-reg" ]; then
1609 vm_init_script="/.build/initvm"
1610 elif [ -e $BUILD_DIR/initscript_qemu_vm ]; then
1611 vm_init_script="/.build/initscript_qemu_vm"
1613 echo "Warning: can't find initscript to register binfmts"
1616 vm_init_script="/.build/build"
1619 if [ "$VM_TYPE" = 'xen' ]; then
1620 XMROOT="file:$(readlink -f $VM_IMAGE)"
1621 XMROOT=${XMROOT/#file:\/dev/phy:/dev}
1622 XMROOT="disk=$XMROOT,hda1,w"
1624 if test -n "$VM_SWAP" ; then
1625 XMSWAP="file:$(readlink -f $VM_SWAP)"
1626 XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
1627 XMSWAP="disk=$XMSWAP,hda2,w"
1629 XENID="${VM_IMAGE%/root}"
1630 XENID="${XENID%/tmpfs}"
1631 XENID="${XENID##*/}"
1632 XENID="${XENID#root_}"
1634 echo "booting XEN kernel ..."
1635 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1636 echo "Instance already exist, something really went wrong..."
1637 echo "Please report to your server admin, there might be multiple services running for same domain"
1640 XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
1641 echo "kernel = \"$vm_kernel\"" > $XEN_CONF_FILE
1642 echo "ramdisk = \"$vm_initrd\"" >> $XEN_CONF_FILE
1643 echo "memory = ${MEMSIZE:-64}" >> $XEN_CONF_FILE
1644 echo "vcpus = $BUILD_JOBS" >> $XEN_CONF_FILE
1645 echo "root = \"/dev/hda1 ro\"" >> $XEN_CONF_FILE
1646 echo "extra = \"init=/bin/bash console=ttyS0 panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
1647 echo "on_poweroff = 'destroy'" >> $XEN_CONF_FILE
1648 echo "on_reboot = 'destroy'" >> $XEN_CONF_FILE
1649 echo "on_crash = 'destroy'" >> $XEN_CONF_FILE
1650 set -- xm create -c $XEN_CONF_FILE name="build_$XENID" $XMROOT $XMSWAP extra="quiet init="$vm_init_script" elevator=noop panic=1 console=ttyS0"
1651 if test "$PERSONALITY" != 0 ; then
1652 # have to switch back to PER_LINUX to make xm work
1656 "$@" || cleanup_and_exit 3
1658 elif [ "$VM_TYPE" = 'uml' ]; then
1659 echo "booting UML kernel ..."
1660 set -- $uml_kernel initrd=$uml_initrd root=/ubda init="$vm_init_script" panic=1 elevator=noop quiet ubd0=$VM_IMAGE ${MEMSIZE:+mem=$MEMSIZE}
1663 elif [ "$VM_TYPE" = 'qemu' -o "$VM_TYPE" = 'kvm' ]; then
1664 echo "booting $VM_TYPE ..."
1665 if [ "$VM_TYPE" = 'kvm' -a -b "$VM_IMAGE" ]; then
1666 # speed optimization when using kvm with raw devices
1669 # speed optimization when using kvm with raw files
1670 CACHE=",cache=unsafe"
1672 if [ "$kvm_virtio" = 1 ]; then
1673 qemu_args=(-drive file="$VM_IMAGE",if=virtio$CACHE -drive file="$VM_IMAGE",if=ide,index=0$CACHE)
1674 if [ -n "$VM_SWAP" ]; then
1675 qemu_args=("${qemu_args[@]}" "-drive")
1676 qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=virtio$CACHE")
1679 if [ "$HOST_ARCH" = "ppc" ];then
1680 qemu_args=( "-drive" )
1681 qemu_args=("${qemu_args[@]}" "file=$VM_IMAGE,if=scsi,cache=unsafe")
1683 qemu_args=(-hda "$VM_IMAGE")
1685 if [ -n "$VM_SWAP" ]; then
1686 qemu_args=("${qemu_args[@]}" "-drive")
1687 if [ "$HOST_ARCH" = "ppc" ];then
1692 qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=$DISK_IF,index=1$CACHE")
1695 if [ -n "$BUILD_JOBS" -a "$icecream" = 0 ]; then
1696 qemu_args=("${qemu_args[@]}" "-smp" "$BUILD_JOBS")
1698 # cpuid is not set correctly in kvm without this
1699 if [ "$HOST_ARCH" != "ppc" ]; then
1702 if [ "$VM_TYPE" = 'kvm' ]; then
1703 KVM_OPTIONS="$KVM_OPTIONS -cpu host"
1704 if [ -n "$HUGETLBFSPATH" ]; then
1705 KVM_OPTIONS="$KVM_OPTIONS -mem-path $HUGETLBFSPATH"
1709 set -- $qemu_bin -no-reboot -nographic -net none $KVM_OPTIONS \
1710 -kernel $vm_kernel \
1711 -initrd $vm_initrd \
1712 -append "root=$qemu_rootdev panic=1 quiet no-kvmclock nmi_watchdog=0 rw elevator=noop console=$console init=$vm_init_script" \
1713 ${MEMSIZE:+-m $MEMSIZE} \
1716 if test "$PERSONALITY" != 0 ; then
1717 # have to switch back to PER_LINUX to make qemu work
1722 elif [ "$VM_TYPE" = 'lxc' ]; then
1723 echo "booting $VM_TYPE ..."
1724 LXCCONF="$BUILD_ROOT/.build.lxc.conf"
1726 cat $BUILD_DIR/lxc.conf > "$LXCCONF"
1727 cat >> "$LXCCONF" <<-EOF
1728 lxc.rootfs = $BUILD_ROOT
1730 # XXX: do this always instead of leaking the hosts' one?
1731 echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
1732 LXCID=${BUILD_ROOT##*/}
1733 lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
1734 lxc-create -n "$LXCID" -f "$LXCCONF" || cleanup_and_exit 1
1735 lxc-start -n "$LXCID" "$vm_init_script"
1737 test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
1738 cleanup_and_exit "$BUILDSTATUS"
1740 if test -n "$VM_SWAP" ; then
1741 BUILDSTATUS=`dd if="$VM_SWAP" bs=12 count=1 2>/dev/null`
1742 case $BUILDSTATUS in
1744 mkdir -p $BUILD_ROOT/.build.packages
1745 cd $BUILD_ROOT/.build.packages || cleanup_and_exit 1
1746 echo "build: extracting built packages..."
1747 extractbuild --disk "$VM_IMAGE" --input "$VM_SWAP" --skip 512 -v || cleanup_and_exit 3
1748 # create same layout as with plain chroot
1749 if test "$BUILDTYPE" = spec ; then
1751 for i in *src.rpm *.desktopfiles ; do
1752 test -e "$i" || continue
1756 test -e "$i" || continue
1763 elif test "$BUILDTYPE" = dsc ; then
1765 find . -type f | while read i; do mv "$i" DEBS/; done
1766 elif test "$BUILDTYPE" = arch ; then
1768 find . -type f | while read i; do mv "$i" ARCHPKGS/; done
1769 elif test "$BUILDTYPE" = kiwi ; then
1771 find . -type f | while read i; do mv "$i" KIWI/; done
1774 test -f "$i" || continue
1777 *) mkdir -p OTHER ; mv $i OTHER/ ;;
1780 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1783 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1786 echo "No buildstatus set, either the base system is broken (glibc/bash/perl)"
1787 echo "or the build host has a kernel or hardware problem..."
1796 if test "$DO_INIT" = true ; then
1798 # create legacy .buildenv file
1800 test -z "$INCARNATION" && INCARNATION=0
1801 echo "BUILD_INCARNATION=$INCARNATION" > $BUILD_ROOT/.buildenv
1802 CREATE_BUILD_BINARIES=
1803 test "$BUILDTYPE" = preinstallimage && mkdir -p $BUILD_ROOT/.preinstall_image
1804 egrep '^#[ ]*needsbinariesforbuild[ ]*$' >/dev/null <$MYSRCDIR/$SPECFILE && CREATE_BUILD_BINARIES=--create-build-binaries
1805 set -- init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USE_SYSTEM_QEMU $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1807 "$@" || cleanup_and_exit 1
1809 # arbitrary limit of 10MB
1810 if test $((`stat -f -c "%a*%S/1024/1024" $BUILD_ROOT`)) -lt 10; then
1811 # ensure that old stat is not failing (RHEL4)
1812 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
1814 echo "build does not work on a completely full filesystem"
1818 mount -n -tproc none $BUILD_ROOT/proc || true
1819 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1824 if test "$BUILDTYPE" = preinstallimage ; then
1825 echo "creating preinstall image..."
1826 test -d "$BUILD_ROOT/.preinstall_image" || cleanup_and_exit 1
1827 cd $BUILD_ROOT || cleanup_and_exit 1
1829 if test -x /usr/bin/bsdtar; then
1830 TAR="/usr/bin/bsdtar --chroot"
1833 for DIR in .* * ; do
1836 .build*) continue ;;
1837 .preinstallimage*) continue ;;
1838 .srcfiles*) continue ;;
1840 installed-pkg) continue ;;
1841 proc|sys) continue ;;
1843 TOPDIRS="$TOPDIRS $DIR"
1845 if ! $TAR -czf .preinstallimage.$$.tar.gz --one-file-system $TOPDIRS ; then
1848 echo "image created."
1849 TOPDIR=/usr/src/packages
1850 mkdir -p $BUILD_ROOT$TOPDIR/OTHER
1851 rm -f $BUILD_ROOT$TOPDIR/OTHER/preinstallimage.info
1852 for PKG in $BUILD_ROOT/.preinstall_image/* ; do
1854 read PKG_HDRMD5 PKGID < $BUILD_ROOT/.preinstall_image/$PKG
1855 test -n "$PKG_HDRMD5" || cleanup_and_exit 1
1856 echo "$PKG_HDRMD5 $PKG" >> $BUILD_ROOT$TOPDIR/OTHER/preinstallimage.info
1858 mv $BUILD_ROOT/.preinstallimage.$$.tar.gz $BUILD_ROOT$TOPDIR/OTHER/preinstallimage.tar.gz
1859 rm -f $BUILD_ROOT/.build.packages
1860 ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
1861 test -d "$SRCDIR" && cd "$SRCDIR"
1865 if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
1866 read BUILD_DIST < $BUILD_ROOT/.guessed_dist
1870 # fix rpmrc if we are compiling for i686
1872 test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
1873 if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
1874 mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
1875 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
1879 # install dummy sign program if needed
1881 test -f $BUILD_ROOT/usr/bin/sign_installed && mv $BUILD_ROOT/usr/bin/sign_installed $BUILD_ROOT/usr/bin/sign
1882 if test -n "$SIGNDUMMY" ; then
1883 test -f $BUILD_ROOT/usr/bin/sign && mv $BUILD_ROOT/usr/bin/sign $BUILD_ROOT/usr/bin/sign_installed
1884 cp $BUILD_DIR/signdummy $BUILD_ROOT/usr/bin/sign
1885 chmod 755 $BUILD_ROOT/usr/bin/sign
1889 # check if we want to build with the abuild user
1892 if test -x $BUILD_ROOT/bin/rpm ; then
1893 SUSE_VERSION=`chroot $BUILD_ROOT /bin/rpm --eval '%{?suse_version}' 2>/dev/null`
1894 if test -n "$SUSE_VERSION" && test "$SUSE_VERSION" -le 1020 ; then
1898 if test "$BUILD_USER" = abuild ; then
1899 egrep '^#[ ]*needsrootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=root
1901 egrep '^#[ ]*norootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=abuild
1903 test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
1905 # appliance builds must run as root
1906 if test "$BUILDTYPE" = kiwi; then
1907 imagetype=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $SPECFILE imagetype)
1908 test "$imagetype" = 'product' || BUILD_USER=root
1911 if test $BUILD_USER = abuild ; then
1912 if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1913 echo "abuild:x:${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_ROOT/etc/passwd
1914 echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed on Mandriva 2009
1915 echo 'abuild:*::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu
1916 echo "abuild:x:${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
1917 mkdir -p $BUILD_ROOT/home/abuild
1918 chown "$ABUILD_UID:$ABUILD_GID" $BUILD_ROOT/home/abuild
1920 if ! egrep "^abuild:x?:${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_ROOT/etc/passwd ; then
1921 echo "abuild user present in the buildroot ($BUILD_ROOT) but uid:gid does not match"
1922 echo "buildroot currently using:"
1923 egrep "^abuild:" <$BUILD_ROOT/etc/passwd
1924 echo "build script attempting to use:"
1925 echo "abuild::${ABUILD_UID}:${ABUILD_GID}:..."
1926 echo "build aborting"
1930 if test -f $BUILD_ROOT/etc/shadow ; then
1931 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
1933 if test -f $BUILD_ROOT/etc/gshadow ; then
1934 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/gshadow > $BUILD_ROOT/etc/gshadow.t && mv $BUILD_ROOT/etc/gshadow.t $BUILD_ROOT/etc/gshadow
1936 BUILD_USER_ABUILD_USED=true
1941 if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1942 rm -rf "$BUILD_ROOT/home/abuild"
1943 egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
1944 mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd
1945 egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new
1946 mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group
1947 if test -f $BUILD_ROOT/etc/shadow ; then
1948 egrep -v '^abuild:' <$BUILD_ROOT/etc/shadow >$BUILD_ROOT/etc/shadow.new
1949 mv $BUILD_ROOT/etc/shadow.new $BUILD_ROOT/etc/shadow
1951 if test -f $BUILD_ROOT/etc/gshadow ; then
1952 egrep -v '^abuild:' <$BUILD_ROOT/etc/gshadow >$BUILD_ROOT/etc/gshadow.new
1953 mv $BUILD_ROOT/etc/gshadow.new $BUILD_ROOT/etc/gshadow
1958 if test "$BUILDTYPE" = spec ; then
1959 TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER`
1960 if test -z "$TOPDIR"; then
1961 echo "Error: TOPDIR empty"
1965 TOPDIR=/usr/src/packages
1966 mkdir -p $BUILD_ROOT$TOPDIR
1969 rm -f $BUILD_ROOT/.build.packages
1970 ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
1972 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1973 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
1979 # nasty hack to prevent rpath on known paths
1980 # FIXME: do this only for suse
1981 if test -d "$BUILD_ROOT/etc/profile.d" ; then
1982 echo "export SUSE_IGNORED_RPATHS=/etc/ld.so.conf" > "$BUILD_ROOT/etc/profile.d/buildsystem.sh"
1986 # now clean up RPM building directories
1988 rm -rf "$BUILD_ROOT$TOPDIR"
1989 for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT OTHER ; do
1990 mkdir -p $BUILD_ROOT$TOPDIR/$i
1992 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1995 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
1996 if test "$BUILDTYPE" = kiwi ; then
1997 mkdir -p $BUILD_ROOT$TOPDIR/KIWI
1998 if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1999 mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
2001 if test -z "$LINKSOURCES" ; then
2002 cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
2004 cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
2006 if test "$?" != 0 ; then
2007 echo "source copy failed"
2012 cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
2014 # strip prefix from autogenerated files of source services.
2015 for i in $BUILD_ROOT$TOPDIR/SOURCES/_service\:*; do
2016 mv "$i" "${i%/*}/${i##*:}"
2018 SPECFILE="${SPECFILE##*:}"
2020 test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
2022 test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
2024 if test "$BUILDTYPE" = spec ; then
2025 # do buildrequires/release substitution
2027 if test -n "$RELEASE"; then
2028 args=(--release "$RELEASE")
2030 substitutedeps "${args[@]}" --root "$BUILD_ROOT" --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" $CHANGELOGARGS "$BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1
2031 # extract macros from configuration
2032 getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" > $BUILD_ROOT/root/.rpmmacros
2033 if test -n "$BUILD_DEBUG" ; then
2035 %prep %{?!__debug_package:%{?_build_create_debug:%?_build_insert_debug_package}}%%prep
2036 %package %{?!__debug_package:%{?_build_create_debug:%?_build_insert_debug_package}}%%package
2037 %_build_insert_debug_package \
2038 %global __debug_package 1 \
2039 %undefine _enable_debug_packages \
2042 ' >> $BUILD_ROOT/root/.rpmmacros
2045 if [ -n "$BUILD_JOBS" ]; then
2046 cat >> $BUILD_ROOT/root/.rpmmacros <<-EOF
2048 %_smp_mflags -j$BUILD_JOBS
2051 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
2052 # extract optflags from configuration
2053 getoptflags --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_ROOT/root/.rpmrc
2054 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
2055 if test -z "$ABUILD_TARGET"; then
2056 ABUILD_TARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" )
2057 test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
2060 if test -f $BUILD_ROOT/.spec.new ; then
2061 if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
2062 echo -----------------------------------------------------------------
2063 echo "I have the following modifications for $SPECFILE:"
2064 sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE > $BUILD_ROOT/.spec.t1
2065 sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2
2066 diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
2067 rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
2068 mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE
2070 rm -f $BUILD_ROOT/.spec.new
2074 if test "$BUILDTYPE" = dsc ; then
2075 rm -rf "$BUILD_ROOT$TOPDIR/BUILD"
2076 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
2077 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
2079 DEB_SOURCEDIR=$TOPDIR/SOURCES
2080 DEB_DSCFILE=$SPECFILE
2081 for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
2082 test -f $f && DEB_TRANSFORM=true
2084 if test -n "$DEB_TRANSFORM" ; then
2085 echo "running debian transformer..."
2086 if ! debtransform $CHANGELOGARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
2087 echo "debian transforming failed."
2090 DEB_SOURCEDIR=$TOPDIR/SOURCES.DEB
2091 for DEB_DSCFILE in $BUILD_ROOT/$DEB_SOURCEDIR/*.dsc ; do : ; done
2092 DEB_DSCFILE="${DEB_DSCFILE##*/}"
2094 chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
2097 if test "$BUILDTYPE" = arch ; then
2098 echo "Preparing sources..."
2099 chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES && makepkg -s -o 2>&1 >/dev/null" - $BUILD_USER
2100 mv $BUILD_ROOT/$TOPDIR/SOURCES/* -t $BUILD_ROOT/$TOPDIR/BUILD
2103 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
2104 cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
2106 echo -----------------------------------------------------------------
2107 if test "$BUILD_USER" = root ; then
2108 echo ----- building $SPECFILE
2110 echo ----- building $SPECFILE "(user $BUILD_USER)"
2112 echo -----------------------------------------------------------------
2113 echo -----------------------------------------------------------------
2114 if [ -n "$RUNNING_IN_VM" ]; then
2115 if [ -x /sbin/ip ]; then
2116 ip addr add 127.0.0.1/8 dev lo
2119 ifconfig lo 127.0.0.1 up
2121 if [ -n "$MYHOSTNAME" ]; then
2122 hostname "$MYHOSTNAME"
2126 BUILD_SUCCEEDED=false
2128 if test -n "$OVERLAY" ; then
2129 if test -d "$OVERLAY"; then
2131 echo "Copying overlay to BUILD_ROOT"
2132 tar -cpf - . | (cd $BUILD_ROOT ; tar -xvf -)
2135 echo "OVERLAY ($OVERLAY) is no directory - skipping"
2139 if test -n "$RSYNCSRC" ; then
2140 if test -n "$RSYNCDEST"; then
2141 if test -d "$RSYNCSRC"; then
2142 if ! test -d "$BUILD_ROOT/$RSYNCDEST"; then
2143 echo "ATTENTION! Creating target directory ($BUILD_ROOT/$RSYNCDEST) as its not there."
2144 mkdir -p $BUILD_ROOT/$RSYNCDEST
2146 echo "Running rsync ..."
2147 rsync -av $RSYNCSRC/* $BUILD_ROOT/$RSYNCDEST/
2148 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/$RSYNCDEST"
2152 echo "RSYNCSRC is no directory - skipping"
2155 echo "RSYNCSRC given, but not RSYNCDEST - skipping"
2159 if test "$BUILDTYPE" = spec ; then
2160 test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
2163 test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
2165 # XXX: move _srcdefattr to macro file?
2166 rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--define" "_srcdefattr (-,root,root)")
2167 if test "$rpmbuild" == "rpmbuild" ; then
2168 # use only --nosignature for rpm v4
2169 rpmbopts[${#rpmbopts[@]}]="--nosignature"
2171 if test -n "$ABUILD_TARGET" ; then
2172 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
2174 if test -n "$BUILD_DEBUG" ; then
2175 rpmbopts[${#rpmbopts[@]}]='--define'
2176 rpmbopts[${#rpmbopts[@]}]="_build_create_debug 1"
2178 if test -n "$DISTURL" ; then
2179 rpmbopts[${#rpmbopts[@]}]='--define'
2180 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
2182 if test -n "$RSYNCDONE" ; then
2183 rpmbopts[${#rpmbopts[@]}]='--define'
2184 rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
2187 # su involves a shell which would require even more
2188 # complicated quoting to bypass than this
2189 toshellscript $rpmbuild \
2190 "${definesnstuff[@]}" \
2192 "$TOPDIR/SOURCES/$SPECFILE" \
2193 > $BUILD_ROOT/.build.command
2194 chmod 755 $BUILD_ROOT/.build.command
2196 if test -n "$shell"; then
2197 chroot $BUILD_ROOT su -
2199 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2203 if test "$BUILDTYPE" = dsc ; then
2204 # Checks to see if a build script should be used
2205 # this allows the build environment to be manipulated
2206 # and alternate build commands can be used
2207 # Debian policy requires to build with single CPU by default
2208 # if [ -n "$BUILD_JOBS" ]; then
2209 # DSC_BUILD_JOBS="-j$BUILD_JOBS"
2211 DSC_BUILD_CMD="dpkg-buildpackage -us -uc -rfakeroot-tcp $DSC_BUILD_JOBS"
2212 if test -e $BUILD_ROOT/$TOPDIR/SOURCES/build.script ; then
2213 echo "Sourcing build.script to build - it should normally run 'dpkg-buildpackage -us -uc -rfakeroot-tcp'"
2214 DSC_BUILD_CMD="source $TOPDIR/SOURCES/build.script"
2215 chmod +x $BUILD_ROOT/$TOPDIR/SOURCES/build.script
2218 if test -n "$shell"; then
2219 chroot $BUILD_ROOT su -
2221 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && $DSC_BUILD_CMD" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2224 mkdir -p $BUILD_ROOT/$TOPDIR/DEBS
2225 for DEB in $BUILD_ROOT/$TOPDIR/*.deb ; do
2226 test -e "$DEB" && mv "$DEB" "$BUILD_ROOT/$TOPDIR/DEBS"
2229 ln $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE $BUILD_ROOT/$TOPDIR/DEBS/
2231 ln $BUILD_ROOT/$DEB_SOURCEDIR/$f $BUILD_ROOT/$TOPDIR/DEBS/
2232 done < <(sed -ne '/^Files:/,$s/^ ................................ [0-9][0-9]* //p' < $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE)
2235 if test "$BUILDTYPE" = arch ; then
2236 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && makepkg -f" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2237 mkdir -p $BUILD_ROOT/$TOPDIR/ARCHPKGS
2238 for PKG in $BUILD_ROOT/$TOPDIR/BUILD/*.pkg.tar.?z ; do
2239 test -e "$PKG" && mv "$PKG" "$BUILD_ROOT/$TOPDIR/ARCHPKGS"
2243 if test "$BUILDTYPE" = kiwi ; then
2244 . $BUILD_DIR/build_kiwi.sh
2248 test "$BUILD_SUCCEEDED" = true || cleanup_and_exit 1
2249 test -d "$SRCDIR" && cd "$SRCDIR"
2252 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
2253 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
2255 if test -n "$RPMS" -a -n "$BUILD_USER_ABUILD_USED" ; then
2256 echo "... checking for files with abuild user/group"
2258 while read un gn fn ; do
2259 if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
2263 done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
2264 if test -n "$BADFILE" ; then
2265 echo "please fix your filelist (e.g. add defattr)"
2270 if test -n "$RPMS" -a -d "$BUILD_ROOT/usr/lib/build/checks" ; then
2272 export DO_RPM_REMOVE=true
2273 for SRPM in $BUILD_ROOT/$TOPDIR/SRPMS/*src.rpm ; do
2274 test -f "$SRPM" && PNAME=`rpm --nodigest --nosignature -qp --qf "%{NAME}" $SRPM`
2276 for CHECKSCRIPT in $BUILD_ROOT/usr/lib/build/checks/* ; do
2277 echo "... running `basename $CHECKSCRIPT`"
2278 $CHECKSCRIPT || cleanup_and_exit 1
2282 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
2283 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
2285 if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_ROOT/opt/testing/bin/rpmlint" ; then
2286 LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
2287 \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
2288 -o -name "*-32bit-*" -o -name "*-64bit-*" \
2289 -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
2290 -o -type f -name '*.rpm' -print))
2291 SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
2293 echo "RPMLINT report:"
2294 echo "==============="
2295 rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log
2296 rm -f "$BUILD_ROOT$rpmlint_logfile"
2298 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
2299 chroot $BUILD_ROOT su -s /opt/testing/bin/rpmlint "$BUILD_USER" -- \
2300 --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} \
2301 ${SRPM_FILE_LIST[*]#$BUILD_ROOT} > "$BUILD_ROOT$rpmlint_logfile" || ret=1
2302 cat "$BUILD_ROOT$rpmlint_logfile"
2304 umount -n $BUILD_ROOT/proc 2>/dev/null || true
2305 if test "$ret" = 1; then
2310 if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS"; then
2315 # post build scripts
2316 # TODO: don't hardcode. instead run scripts in a directory as it's done for the checks
2317 if test -n "$RPMS" \
2318 -a -d "$BUILD_ROOT/$TOPDIR/RPMS" \
2319 -a -d "$BUILD_ROOT/.build.oldpackages" \
2321 if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
2322 echo "... comparing built packages with the former built"
2323 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
2324 if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
2325 chroot $BUILD_ROOT touch /.build/.same_result_marker
2326 # XXX: dirty build service hack. fix bs_worker. Search for
2327 # 'same_result_marker' for traces of a first try to get rid of this
2328 if test -n "$REASON" -a -n "$DISTURL"; then
2333 if test ! -e $BUILD_ROOT/.build/.same_result_marker \
2334 -a -x "$BUILD_ROOT/usr/bin/makedeltarpm" \
2335 -a -x $BUILD_ROOT/usr/lib/build/mkdrpms; then
2336 echo "... creating delta rpms"
2337 ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS")
2338 chroot $BUILD_ROOT /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}"
2342 if test -n "$RUNNING_IN_VM" -a -n "$VM_SWAP"; then
2343 echo "... saving built packages"
2345 args="--padstart 512 --padend 512 -v"
2346 case "$BUILDTYPE" in
2348 computeblocklists $args $TOPDIR/RPMS/*/*.{d,}rpm $TOPDIR/SRPMS/* $TOPDIR/OTHER/* > "$VM_SWAP"
2351 computeblocklists $args $TOPDIR/DEBS/*.deb $TOPDIR/SOURCES.DEB/* $TOPDIR/OTHER/* > "$VM_SWAP"
2354 computeblocklists $args $TOPDIR/KIWI/* $TOPDIR/OTHER/* > "$VM_SWAP"
2357 computeblocklists $args $TOPDIR/ARCHPKGS/* $TOPDIR/OTHER/* > "$VM_SWAP"
2360 computeblocklists $args $TOPDIR/OTHER/* > "$VM_SWAP"
2365 esac || cleanup_and_exit 1
2369 echo "$HOST finished \"build $SPECFILE\" at `date --utc`."
2372 cleanup_and_exit "$exitcode"