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, forx eaxmple:
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
236 Copy overlay filesystem to buildroot after installing
237 all RPMs. This must be a valid directory.
240 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
241 inside the buildroot using rsync.
242 It will "%define RSYNCDONE 1" for handling %setup in your
246 %setup -n aaa_base -T -D -b 5 -b 7
248 %setup -n aaa_base -b 5 -b 7
251 --rsync-dest RSYNCDEST
252 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
253 inside the buildroot using rsync.
256 Specify the uid and gid to use for the abuild user.
257 This is useful if you are hacking in the buildroot.
258 This must be set to the same value if the buildroot is re-used.
261 Use virtual machine instead of chroot
262 TYPE is one of xen|kvm|uml|qemu|lxc
265 Use FILE as disk for virtual machine.
266 Defaults to \$BUILD_ROOT.img if unset
269 Use FILE as swap space for virtual machine. The swap space is
270 also used for retrieving packages from the VM so it's size must be
273 --vm-disk-size SIZEINMB
274 --vm-swap-size SIZEINMB
275 --vm-disk-filesystem TYPE
276 Defaults for automatic setup of VM root/swap files
279 Set amount of RAM for VMs
283 Kernel and initrd to use for VM (kvm and qemu only)
286 enable creation of a debuginfo package
288 Remember to have fun!
290 [*] Maximum RPM: http://www.rpm.org/max-rpm/
294 echo "Usage: `basename $0` [--no-init|--clean|--rpms path|--verify|--help] [dir-to-build|spec-to-build]"
300 # return values: 0 -> success, new packages built
301 # 1 -> error, build failed
302 # 2 -> successfull build, but no changes to former built packages
303 # 3 -> something wrong with build host
305 cleanup_and_exit () {
307 test -z "$1" && set 0
308 rm -f $BUILD_ROOT/exit
309 if test "$1" -eq 1 -a -x /bin/df ; then
310 # okay, it failed, but maybe because disk space?
311 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
315 if test -n "$RUNNING_IN_VM" ; then
316 chown $browner $BUILD_ROOT
318 if test -n "$VM_SWAP" -a -e "$VM_SWAP" ; then
319 swapoff "$VM_SWAP" 2>/dev/null
320 echo -n "BUILDSTATUS$1" >"$VM_SWAP"
322 exec >&0 2>&0 # so that the logging tee finishes
323 sleep 1 # wait till tee terminates
324 if test "$VM_TYPE" != lxc; then
325 kill -9 -1 # goodbye cruel world
326 if ! test -x /sbin/halt ; then
327 test -e /proc/sysrq-trigger || mount -n -tproc none /proc
329 sleep 2 # like halt does
330 if test -e /proc/sysrq-trigger; then
331 echo o > /proc/sysrq-trigger
332 sleep 5 # wait for sysrq to take effect
334 echo "Warning: VM doesn't support sysrq and /sbin/halt not installed"
339 echo "Warning: clean shut down of the VM didn't work"
342 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
343 umount -n $BUILD_ROOT/proc 2>/dev/null || true
344 umount -n $BUILD_ROOT/dev/pts 2>/dev/null || true
345 test "$VM_IMAGE" = 1 && VM_IMAGE=
346 [ -n "$VM_IMAGE" ] && umount $BUILD_ROOT 2>/dev/null || true
348 # echo "pid $$ exit $1"
368 # create a shell script from command line. Used for preserving arguments
380 if [ "$ccache" = 1 ]; then
381 if mkdir -p $BUILD_ROOT/var/lib/build/ccache/bin; then
382 for i in $(ls $BUILD_ROOT/usr/bin | grep -E '^(cc|gcc|[cg][+][+])([-]?[234][.]?[0-9])*$'); do
383 # ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
384 rm -f $BUILD_ROOT/var/lib/build/ccache/bin/$i
385 test -e $BUILD_ROOT/usr/bin/$i || continue
386 echo '#! /bin/sh' > $BUILD_ROOT/var/lib/build/ccache/bin/$i
387 echo "test -e /usr/bin/$i || exit 1" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
388 echo 'export PATH=/opt/icecream/bin:/usr/bin:$PATH' >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
389 echo "ccache $i \"\$@\"" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
390 chmod 755 $BUILD_ROOT/var/lib/build/ccache/bin/$i
391 echo "Installed ccache wrapper as $BUILD_ROOT/var/lib/build/ccache/bin/$i"
394 mkdir -p "$BUILD_ROOT"/.ccache
395 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/.ccache"
396 echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
397 echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
399 rm -f "$BUILD_ROOT$builduserhome"/bin/{gcc,g++,cc,c++}
400 rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
406 if [ "$icecream" -eq 0 ]; then
407 rm -rf "$BUILD_ROOT"/var/run/icecream
408 rm -f "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
412 if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then
413 echo "*** icecream package not installed ***"
418 echo "using icecream with $icecream jobs"
420 if [ "$ccache" -ne 1 ]; then
421 echo 'export PATH=/opt/icecream/bin:$PATH' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
423 echo 'export CCACHE_PATH=/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
426 local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
427 icecc_vers=${icecc_vers//$BUILD_ROOT/}
429 # XXX use changelog like autobuild does instead?
430 # only run create-env if compiler or glibc changed
431 if [ -z "$icecc_vers" \
432 -o ! -e "$BUILD_ROOT/$icecc_vers" \
433 -o "$BUILD_ROOT/usr/bin/gcc" -nt "$BUILD_ROOT/$icecc_vers" \
434 -o "$BUILD_ROOT/usr/bin/g++" -nt "$BUILD_ROOT/$icecc_vers" \
435 -o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
436 -o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers" ]
438 rm -rf $BUILD_ROOT/var/run/icecream
439 mkdir -p $BUILD_ROOT/var/run/icecream
440 if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
441 createenv=/usr/bin/create-env
442 elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
443 createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
444 elif [ -e "$BUILD_ROOT"/usr/lib64/icecc/icecc-create-env ]; then
445 createenv="/usr/lib64/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
447 echo "create-env not found"
451 chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv" || cleanup_and_exit 1
452 icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
453 icecc_vers=${icecc_vers//$BUILD_ROOT/}
455 echo "reusing existing icecream environment $icecc_vers"
457 if [ -n "$icecc_vers" ]; then
458 echo "export ICECC_VERSION=$icecc_vers" >> "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
464 if [ -n "$VM_IMAGE" -o -n "$RUNNING_IN_VM" ]; then
473 eval "limit=\$(($2/3*4))"
477 eval "limit=\$(($2/3*4+$limit))"
480 done < <(cat /proc/meminfo) # cat for proc stuff
483 echo "Memory limit set to ${limit}KB"
492 if test "$BUILDTYPE" == "arch" ; then
495 if test "$BUILDTYPE" == "dsc" ; then
498 if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
499 BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
501 if test -e $BUILD_ROOT/usr/lib/build/baselibs_global.conf; then
502 BASELIBS_GLOBAL="-c /usr/lib/build/baselibs_global.conf"
507 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
508 # don't use -R as extracted sources, build root etc might be below $TOPDIR
509 chown "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"/* "$BUILD_ROOT$TOPDIR"/RPMS/* || true
511 local mkbaselibs="/usr/lib/build/mkbaselibs"
513 # $BUILD_DIR is set to /.build when using a vm. So we need to
514 # hardcode /usr/lib/build instead of $BUILD_DIR to prefer
515 # mkbaselibs from the distro.
516 if test -f $BUILD_ROOT$mkbaselibs; then
517 if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
518 BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
521 if test "$CREATE_BASELIBS" = 'internal'; then
522 echo "Warning: mkbaselibs missing in build root, skipping baselibs"
525 # use external version
526 whichone=" (external)"
527 mkbaselibs="/.mkbaselibs/mkbaselibs"
528 rm -rf $BUILD_ROOT/.mkbaselibs
529 mkdir -p $BUILD_ROOT/.mkbaselibs
530 cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs/
531 if test "$BUILDTYPE" == "dsc" ; then
532 cp -f $BUILD_DIR/baselibs_global-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
533 cp -f $BUILD_ROOT$TOPDIR/SOURCES/baselibs-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs-deb.conf
534 BASELIBS_CFG="-c /.mkbaselibs/baselibs-deb.conf"
536 cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
537 if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf; then
538 cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf
539 BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf"
542 if test -e $BUILD_ROOT/.mkbaselibs/baselibs_g.conf; then
543 BASELIBS_GLOBAL="-c /.mkbaselibs/baselibs_g.conf"
546 echo "... creating baselibs$whichone"
547 chroot $BUILD_ROOT su -c "$mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG ${pkgs[*]#$BUILD_ROOT}" - $BUILD_USER || cleanup_and_exit 1
548 rm -rf $BUILD_ROOT/.mkbaselibs
556 [ -z "$RUNNING_IN_VM" ] || return 0
557 if [ -z "$old_packages" ]; then
558 rm -rf "$BUILD_ROOT"/.build.oldpackages*
561 for d in "${old_packages[@]}"; do
562 dest="$BUILD_ROOT/.build.oldpackages"
563 test "$i" = 0 || dest="$dest$i"
564 if [ -d "$d" -a "$d" != "$dest" ] ; then
578 eval "mkfs=\"\$vm_img_mkfs_${fs}\""
579 eval "tunefs=\"\$vm_img_tunefs_${fs}\""
581 if test -z "$mkfs"; then
582 echo "filesystem \"$fs\" isn't supported"
587 echo "Creating $fs filesystem on $img"
589 if test -n "$tunefs" ; then
590 $tunefs "$img" || cleanup_and_exit 3
595 detect_vm_2nd_stage()
597 if ! test "$0" = "/.build/build" ; then
600 if test $$ -eq 1 ; then
601 # ignore special init signals if we're init
602 # we're using ' ' instead of '' so that the signal handlers
603 # are reset in the child processes
608 echo "2nd stage started in virtual machine"
611 . $BUILD_DIR/build.data
612 echo "machine type: `uname -m`"
613 if test "$PERSONALITY" != 0 -a -z "$PERSONALITY_SET" ; then
614 export PERSONALITY_SET=true
615 echo "switching personality to $PERSONALITY..."
616 # this is 32bit perl/glibc, thus the 32bit syscall number
617 exec perl -e 'syscall(136, '$PERSONALITY') == -1 && warn("personality: $!\n");exec "/.build/build" || die("/.build/build: $!\n")'
620 mount -orw -n -tproc none /proc
621 if test "$VM_TYPE" != 'lxc'; then
622 mount -n ${VMDISK_MOUNT_OPTIONS},remount,rw /
624 # qemu inside of xen does not work, check again with kvm later before enabling this
625 # if [ -e /dev/kqemu ]; then
626 # # allow abuild user to run qemu
627 # chmod 0666 /dev/kqemu
629 if test -n "$VM_SWAP" ; then
630 for i in 1 2 3 4 5 6 7 8 9 10 ; do
631 test -e "$VM_SWAP" && break
632 test $i = 1 && echo "waiting for $VM_SWAP to appear"
637 # recreate the swap device manually if it didn't exist for some
638 # reason, hardcoded to hda2 atm
639 if ! test -b "$VM_SWAP" ; then
642 mknod "$VM_SWAP" b 3 2
645 swapon -v "$VM_SWAP" || exit 1
655 if [ -z "$SPECFILES" ]; then
658 set -- "${SPECFILES[@]}"
662 if [ "$spec" = "${spec#/}" ]; then
666 if [ -d "$spec" ]; then
667 specs=("$spec"/*.spec)
668 if [ -n "$specs" ]; then
669 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
671 specs=("$spec"/*.spec)
672 if [ -n "$specs" ]; then
673 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
677 SPECFILES[${#SPECFILES[@]}]="$spec";
681 if test -z "$SPECFILES"; then
682 echo no spec files or src rpms found in $@. exit...
687 become_root_or_fail()
689 if [ ! -w /root ]; then
690 echo "You have to be root to use $0" >&2
698 if [ -d "$BUILD_ROOT" ]; then
699 # check if it is owned by root
700 if [ -z "$RUNNING_IN_VM" -a \! -O "$BUILD_ROOT" -a "`stat -c %u $BUILD_ROOT`" -ne 0 ]; then
701 echo "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
705 test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
706 if ! mkdir $BUILD_ROOT; then
707 echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
712 if [ ! -w "$BUILD_ROOT" ]; then
713 echo "Error: BUILD_ROOT=$BUILD_ROOT not writeable, try --clean."
717 rm -rf "$BUILD_ROOT"/.build.packages
718 if [ -z "$VM_TYPE" -a -z "$RUNNING_IN_VM" ]; then
719 # don't touch this in VM
720 rm -rf "$BUILD_ROOT"/.build
721 mkdir -p "$BUILD_ROOT"/.build
727 perl -e 'syscall('$PERSONALITY_SYSCALL', 0); exec(@ARGV) || die("$ARGV[0]: $!\n")' "$@"
736 if [ "$uname" != "ppc" -a "$uname" != "ppc64" ]; then
742 # XXX is this ok for ppc32 hosts? do we care?
743 export kvm_bin="/usr/bin/qemu-system-ppc64"
745 # XXX check host CPU and adjust guest CPU accordingly
746 export KVM_OPTIONS="-enable-kvm -M pseries -mem-path /hugetlbfs"
747 export VM_KERNEL=/boot/vmlinux
748 export VM_INITRD=/boot/initrd
749 if [ -z "$RUNNING_IN_VM" -a "$VM_TYPE" = "kvm" ];then
750 cat /proc/mounts | grep "/hugetlbfs" &>/dev/null
751 if [ "$?" != "0" ];then
752 echo "hugetlbfs is not mounted"
755 PAGES_FREE=$(cat /sys/kernel/mm/hugepages/hugepages-16384kB/free_hugepages)
756 PAGES_REQ=$(( $MEMSIZE / 16 ))
757 if [ "$PAGES_FREE" -lt "$PAGES_REQ" ];then
758 echo "please adjust nr_hugepages"
761 grep kvm_rma_count /proc/cmdline &>/dev/null
762 if [ "$?" != "0" ];then
763 echo "put kvm_rma_count=<VM number> to your boot options"
766 grep kvm_hpt_count /proc/cmdline &>/dev/null
767 if [ "$?" != "0" ];then
768 echo "put kvm_hpt_count=<VM number> to your boot options"
778 archname=`perl -V:archname`
779 archname="${archname#archname=?}"
781 x86_64*) PERSONALITY_SYSCALL=135 ;;
782 alpha*) PERSONALITY_SYSCALL=324 ;;
783 sparc*) PERSONALITY_SYSCALL=191 ;;
784 i?86*|ppc*|arm*|sh4|cris|m68k|s390*|unicore32|microblaze) PERSONALITY_SYSCALL=136 ;;
785 *) echo "ARCHITECTURE PERSONALITY IS UNKNOWN"; exit 1;;
790 if detect_vm_2nd_stage ; then
791 set "/.build-srcdir/$SPECFILE"
795 export PATH=$BUILD_DIR:/sbin:/usr/sbin:$PATH
797 . $BUILD_DIR/common_functions || exit 1
803 if [ -z "$ARG" ]; then
804 echo "$PARAM needs an agrument" >&2
809 while test -n "$1"; do
812 [ "$ARG" = "${ARG#-}" ] || ARG=""
818 set -- "----noarg=$PARAM" "$@"
832 CLEAN_BUILD='--clean'
848 export VERIFY_BUILD_SYSTEM=true
862 BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
872 CREATE_BASELIBS=internal
886 old_packages=("${old_packages[@]}" "$ARG")
894 *-xen|*-kvm|--uml|--qemu)
896 if [ -n "$ARG" ]; then
910 xen|kvm|uml|qemu|lxc)
911 test -z "$VM_IMAGE" && VM_IMAGE=1
913 none|chroot) VM_TYPE='' ;;
915 echo "VM $VM_TYPE not supported"
931 *-xenmemory|*-memory)
946 *-vmdisk-rootsize|--vm-disk-size)
948 VMDISK_ROOTSIZE="$ARG"
951 *-vmdisk-swapsize|--vm-swap-size)
953 VMDISK_SWAPSIZE="$ARG"
956 *-vmdisk-filesystem|--vm-disk-filesystem)
958 VMDISK_FILESYSTEM="$ARG"
961 *-vmdisk-mount-options|--vm-disk-mount-options)
963 # options needs to be quoted to handle argument which might start with "-o ..."
964 VMDISK_MOUNT_OPTIONS=$(echo $ARG | sed 's/^\"\(.*\)\"$/\1/g')
969 RPMLIST="--rpmlist $ARG"
993 BUILD_RPM_BUILD_STAGE="$ARG"
997 USEUSEDFORBUILD="--useusedforbuild"
1002 --define|--with|--without)
1004 definesnstuff[${#definesnstuff[@]}]="$PARAM";
1005 definesnstuff[${#definesnstuff[@]}]="$ARG";
1008 --repository|--repo)
1010 repos[${#repos[@]}]="$PARAM";
1011 repos[${#repos[@]}]="$ARG";
1017 if [ "$icecream" -gt 0 ]; then
1042 echo "$ARG does not take an argument"
1066 if test -n "${ABUILD_ID//[0-9:]/}"; then
1067 echo "--uid argument must be uid:gid"
1070 ABUILD_UID=${ABUILD_ID%:*}
1071 ABUILD_GID=${ABUILD_ID#*:}
1082 echo Unknown Option "$PARAM". Exit.
1086 SPECFILES[${#SPECFILES[@]}]="$PARAM";
1093 if test "$VM_TYPE" = "lxc"; then
1098 if test "$VMDISK_MOUNT_OPTIONS" = __default; then
1099 if test "$VMDISK_FILESYSTEM" = reiserfs ; then
1100 VMDISK_MOUNT_OPTIONS='-o data=writeback,commit=150,noatime'
1102 VMDISK_MOUNT_OPTIONS='-o data=writeback,nobarrier,commit=150,noatime'
1106 if test -n "$KILL" ; then
1107 test -z "$SRCDIR" || usage
1108 if test -n "$VM_IMAGE" -a -n "$VM_SWAP" -a -n "$VM_TYPE"; then
1109 # mark job as failed so that we don't extract packages
1110 echo -n "BUILDSTATUS1" >"$VM_SWAP"
1112 (set -C; > "$BUILD_ROOT/exit" 2>/dev/null || true)
1113 if test "$VM_TYPE" = 'lxc'; then
1114 LXCID=${BUILD_ROOT##*/}
1115 lxc-stop -n "$LXCID" || true
1116 lxc-destroy -n "$LXCID"
1117 elif test -z "$VM_IMAGE" ; then
1118 if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
1119 echo "could not kill build in $BUILD_ROOT"
1122 elif test "$VM_TYPE" = 'xen'; then
1123 XENID="${VM_IMAGE%/root}"
1124 XENID="${XENID%/tmpfs}"
1125 XENID="${XENID##*/}"
1126 XENID="${XENID#root_}"
1127 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1128 if ! xm destroy "build_$XENID" ; then
1129 echo "could not kill xen build $XENID"
1133 elif test -n "$VM_TYPE"; then
1134 if ! fuser -k -TERM "$VM_IMAGE"; then
1135 echo "could not kill build in $VM_IMAGE"
1139 echo "don't know how to kill this build job"
1145 if [ "$VM_TYPE" = 'xen' -a -z "$RUNNING_IN_VM" ]; then
1146 # XXX: merge with kvm path?
1147 if [ -n "$VM_KERNEL" ]; then
1148 vm_kernel="$VM_KERNEL"
1149 elif [ -e "/boot/vmlinuz-xen" ]; then
1150 vm_kernel="/boot/vmlinuz-xen"
1152 if [ -n "$VM_INITRD" ]; then
1153 vm_initrd="$VM_INITRD"
1154 elif [ -e "/boot/initrd-xen" ]; then
1155 vm_initrd="/boot/initrd-xen"
1159 if [ "$VM_TYPE" = 'kvm' -a -z "$RUNNING_IN_VM" ]; then
1160 if [ ! -r /dev/kvm -o ! -x "$kvm_bin" ]; then
1161 echo "host doesn't support kvm"
1162 echo "either the kvm kernel-module is not loaded or kvm is not installed or hardware virtualization is deactivated in the BIOS."
1166 if [ -n "$VM_KERNEL" ]; then
1167 vm_kernel="$VM_KERNEL"
1170 # check if a SUSE system with virtio initrd is running
1171 if [ -z "$VM_INITRD" -a -e /etc/sysconfig/kernel ]; then
1172 a=$( source /etc/sysconfig/kernel; echo $INITRD_MODULES )
1176 [ "$i" == "virtio_pci" ] && have_virtio_pci="1"
1177 [ "$i" == "virtio_blk" ] && have_virtio_blk="1"
1179 [ -n "$have_virtio_pci" -a -n "$have_virtio_blk" ] && VM_INITRD="/boot/initrd"
1182 if [ -n "$VM_INITRD" ]; then
1183 vm_initrd="$VM_INITRD"
1185 elif [ -e "${vm_initrd}-build" ]; then
1186 vm_initrd="${vm_initrd}-build"
1189 if [ -L "$vm_initrd" ]; then
1190 vm_initrd=`readlink -f "$vm_initrd"` || cleanup_and_exit 3
1192 vm_initrd_virtio="${vm_initrd}-virtio"
1194 if [ ! -e ${vm_initrd_virtio} -o $vm_kernel -nt ${vm_initrd_virtio} ]; then
1195 mkinitrd_virtio_cmd=(env rootfstype="$VMDISK_FILESYSTEM" \
1196 mkinitrd -d /dev/null \
1197 -m "ext3 ext4 btrfs reiserfs binfmt_misc virtio_pci virtio_blk" \
1199 -i ${vm_initrd_virtio})
1200 if [ ! -w /root -o -n "$RPMLIST" ]; then
1201 echo "No initrd that provides virtio support found. virtio accelleration disabled."
1202 echo "Run the following command as root to enable virtio:"
1203 shellquote "${mkinitrd_virtio_cmd[@]}"
1205 elif /sbin/modinfo virtio_pci >/dev/null 2>&1; then
1206 echo "creating $vm_initrd_virtio"
1207 "${mkinitrd_virtio_cmd[@]}" || cleanup_and_exit 1
1209 vm_initrd="${vm_initrd_virtio}"
1213 vm_initrd="${vm_initrd_virtio}"
1217 if [ "$HOST_ARCH" = ppc ]; then
1218 # KVM on PPC can not run virtio yet, so we need to use the default vio
1222 if [ "$kvm_virtio" = 1 ]; then
1224 qemu_rootdev=/dev/vda
1227 qemu_rootdev=/dev/sda
1231 if [ "$VM_TYPE" = 'qemu' ]; then
1233 qemu_rootdev=/dev/sda
1236 if [ -z "$RPMLIST" -a -z "$RUNNING_IN_VM" ]; then
1237 if [ -z "$repos" -a -z "$BUILD_RPMS" ]; then
1238 repos=(--repository 'zypp://')
1246 if [ -n "$CLEAN_BUILD" ]; then
1252 if test -n "$LIST_STATE" ; then
1253 BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
1254 test -d "$BUILD_ROOT" || cleanup_and_exit 3
1255 SPECFILE=$SPECFILES # only one specified anyways
1256 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1257 rm -rf $BUILD_ROOT/usr/src/packages
1258 mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES $BUILD_ROOT/usr/src/packages/SPECS
1259 rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
1260 echo "could not install $SPECFILE." 2>&1
1264 for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
1266 init_buildsystem --cachedir "$CACHE_DIR" --list-state "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
1269 cleanup_and_exit $ERR
1272 if test -z "$RUNNING_IN_VM" ; then
1273 if test -n "$VM_IMAGE" ; then
1274 if test "$VM_IMAGE" = 1 ; then
1275 VM_IMAGE="$BUILD_ROOT.img"
1276 echo "using $VM_IMAGE as vm image"
1277 if test -z "$VM_SWAP"; then
1278 VM_SWAP="$BUILD_ROOT.swap"
1279 echo "using $VM_SWAP as vm swap"
1282 if [ "$VM_TYPE" = 'xen' ]; then
1283 # this should not be needed, but sometimes a xen instance got lost
1284 XENID="${VM_IMAGE%/root}"
1285 XENID="${XENID%/tmpfs}"
1286 XENID="${XENID##*/}"
1287 XENID="${XENID#root_}"
1288 xm destroy "build_$XENID" >/dev/null 2>&1
1290 if test ! -e "$VM_IMAGE"; then
1291 echo "Creating $VM_IMAGE (${VMDISK_ROOTSIZE}M)"
1292 mkdir -p "${VM_IMAGE%/*}"
1293 dd if=/dev/zero of="$VM_IMAGE" bs=1M count=0 seek="$VMDISK_ROOTSIZE" || cleanup_and_exit 3
1294 if test -z "$CLEAN_BUILD" ; then
1295 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1298 if test -n "$VM_SWAP" -a ! -e "$VM_SWAP"; then
1300 echo "Creating $VM_SWAP (${VMDISK_SWAPSIZE}M)"
1301 mkdir -p "${VM_SWAP%/*}"
1302 dd if=/dev/zero of="$VM_SWAP" bs=1M count=0 seek="$VMDISK_SWAPSIZE" || cleanup_and_exit 3
1304 if test ! -e "$VM_IMAGE" ; then
1305 echo "you need to create $VM_IMAGE first"
1308 if test -n "$CLEAN_BUILD" ; then
1309 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1312 if [ -w /root ]; then
1313 if [ -b $VM_IMAGE ]; then
1314 # mount device directly
1315 mount $VMDISK_MOUNT_OPTIONS $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1317 mount ${VMDISK_MOUNT_OPTIONS},loop $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1320 if ! mount $BUILD_ROOT; then
1321 echo "mounting the build root failed. An fstab entry is probably missing or incorrect."
1322 echo "/etc/fstab should contain an entry like this:"
1323 echo "$VM_IMAGE $BUILD_ROOT auto noauto,user,loop 0 0"
1328 test -w /root || become_root_or_fail
1330 if test -n "$VM_SWAP" ; then
1331 dd if=/dev/zero of="$VM_SWAP" bs=12 count=1 conv=notrunc 2>/dev/null
1332 echo "mkswap $VM_SWAP"
1339 if [ "$BUILD_ROOT" = / ]; then
1340 read dummy dummy browner dummy < <(ls -ld /)
1343 rm -f $BUILD_ROOT/exit
1345 if [ -w /root ]; then
1346 mkdir -p $BUILD_ROOT/proc
1347 mkdir -p $BUILD_ROOT/dev/pts
1348 mount -n -tproc none $BUILD_ROOT/proc || true
1349 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1352 if test -z "$VM_IMAGE" -a -z "$LOGFILE"; then
1353 LOGFILE="$BUILD_ROOT/.build.log"
1356 if test -n "$LOGFILE" -a -z "$shell" ; then
1357 echo logging output to $LOGFILE...
1360 if test -n "$VM_IMAGE" ; then
1361 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
1363 exec 1> >(exec -a 'build logging tee' tee -a $LOGFILE) 2>&1
1372 test -z "$HOST" && HOST=`hostname`
1374 if [ -z "$RUNNING_IN_VM" ]; then
1375 echo Using BUILD_ROOT=$BUILD_ROOT
1376 test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
1377 echo Using BUILD_ARCH=$BUILD_ARCH
1378 test -n "$VM_TYPE" && echo "Doing $VM_TYPE build${VM_IMAGE:+ in $VM_IMAGE}"
1382 test "$BUILD_ARCH" = all && BUILD_ARCH=
1383 BUILD_USER_ABUILD_USED=
1385 for SPECFILE in "${SPECFILES[@]}" ; do
1387 SRCDIR="${SPECFILE%/*}"
1388 SPECFILE="${SPECFILE##*/}"
1392 *.spec|*.src.rpm) BUILDTYPE=spec ;;
1393 *.dsc) BUILDTYPE=dsc ;;
1394 *.kiwi) BUILDTYPE=kiwi ;;
1395 PKGBUILD) BUILDTYPE=arch ;;
1397 if test -z "$BUILDTYPE" ; then
1398 echo "don't know how to build $SPECFILE"
1404 if [ -z "$RUNNING_IN_VM" ]; then
1406 echo "$HOST started \"build $SPECFILE\" at `date --utc`."
1408 test -n "$REASON" && echo "$REASON"
1413 # first setup building directory...
1415 test -s "$SPECFILE" || {
1416 echo "$SPECFILE" is empty. This should not happen...
1420 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1421 echo processing src rpm $SRCDIR/$SPECFILE ...
1422 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1425 cd $MYSRCDIR || cleanup_and_exit 1
1426 $BUILD_DIR/unrpm -q $SRCDIR/$SPECFILE || {
1427 echo "could not install $SPECFILE."
1430 for SPECFILE in *.spec ; do : ; done
1435 # FIX to work with baselibs_$PROJ etc
1436 if test "$BUILDTYPE" == "dsc" -a -e ${SRCDIR}/baselibs-deb.conf ; then
1437 # Set CREATE_BASELIBS if not set
1438 echo "dsc build and baselibs-deb.conf present: forcing --baselibs to true"
1439 CREATE_BASELIBS=true
1442 # Currently local osc build does not allow extra .deb packages to be
1443 # specified on the command line. Both init_buildsystem and expanddeps
1444 # need to handle .deb dependencies first
1445 # if test -n "$CREATE_BASELIBS" ; then
1446 # case $BUILDTYPE in
1448 # dsc) BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS libparse-debcontrol-perl" ;;
1452 echo processing specfile $MYSRCDIR/$SPECFILE ...
1455 test -z "$BUILD_EXTRA_PACKS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
1456 test -z "$CREATE_BASELIBS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
1457 test "$ccache" = '0' || ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
1458 test "$icecream" = 0 || ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
1459 test -z "$DO_LINT" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
1461 if test -n "$CHANGELOG" -a -z "$RUNNING_IN_VM" ; then
1462 rm -f $BUILD_ROOT/.build-changelog
1464 *.dsc) CFFORMAT=debian ;;
1467 echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
1468 if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
1469 rm -f $BUILD_ROOT/.build-changelog
1473 if test -n "$VM_TYPE" -a -z "$RUNNING_IN_VM"; then
1474 rm -rf $BUILD_ROOT/.build
1475 mkdir -p $BUILD_ROOT/.build
1476 if test "$DO_INIT" = true ; then
1477 # do fist stage of init_buildsystem
1478 rm -f $BUILD_ROOT/.build.success
1479 set -- init_buildsystem --cachedir "$CACHE_DIR" --prepare "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1481 "$@" || cleanup_and_exit 1
1483 if [ ! -w /root ]; then
1484 # remove setuid bit if files belong to user to make e.g. mount work
1485 find $BUILD_ROOT/{bin,sbin,usr/bin,usr/sbin} -type f -uid $UID -perm +4000 -print0 | xargs -0 --no-run-if-empty chmod -s
1489 # start up xen, rerun ourself
1490 cp -a $BUILD_DIR/. $BUILD_ROOT/.build
1491 if ! test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1492 rm -rf $BUILD_ROOT/.build-srcdir
1493 mkdir $BUILD_ROOT/.build-srcdir
1494 if test "$BUILDTYPE" = kiwi ; then
1495 cp -pRL "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1497 cp -p "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1499 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1501 # cwd is at $BUILD_ROOT/.build-srcdir which we want to
1502 # umount later so step aside
1506 echo "SPECFILE='${SPECFILE//"'"/$Q}'" > $BUILD_ROOT/.build/build.data
1507 echo "BUILD_JOBS='${BUILD_JOBS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1508 echo "BUILD_ARCH='${BUILD_ARCH//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1509 echo "BUILD_RPMS='${BUILD_RPMS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1512 cp $BUILD_DIST $BUILD_ROOT/.build/build.dist
1513 BUILD_DIST=/.build/build.dist
1516 echo "BUILD_DIST='${BUILD_DIST//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1517 echo "RELEASE='${RELEASE//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1518 echo "BUILD_DEBUG='${BUILD_DEBUG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1519 echo "SIGNDUMMY='${SIGNDUMMY//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1520 echo "DO_LINT='${DO_LINT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1521 echo "DO_CHECKS='${DO_CHECKS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1522 echo "NOROOTFORBUILD='${NOROOTFORBUILD//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1523 echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
1524 echo "REASON='${REASON//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1525 echo "CHANGELOG='${CHANGELOG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1526 echo "INCARNATION='${INCARNATION//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1527 echo "DISTURL='${DISTURL//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1528 echo "DO_INIT='${DO_INIT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1529 # FIXME: this depends on the kernel and vm.
1530 # could be hda2, sda2 for xen or hdb/sdb for qemu
1531 test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV:-/dev/hda2}'" >> $BUILD_ROOT/.build/build.data
1532 test -n "$VMDISK_MOUNT_OPTIONS" && echo "VMDISK_MOUNT_OPTIONS='${VMDISK_MOUNT_OPTIONS}'" >> $BUILD_ROOT/.build/build.data
1534 if test "$VM_TYPE" != 'lxc'; then
1535 test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
1537 if test "$(uname -m)" = 'ppc'; then
1538 # ppc kernel never tells us if a 32bit personality is active
1541 echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
1542 echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
1543 echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
1544 shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
1545 echo ")" >> $BUILD_ROOT/.build/build.data
1546 echo -n "repos=(" >> $BUILD_ROOT/.build/build.data
1547 shellquote "${repos[@]}" >> $BUILD_ROOT/.build/build.data
1548 echo ")" >> $BUILD_ROOT/.build/build.data
1549 echo "VM_TYPE='$VM_TYPE'" >> $BUILD_ROOT/.build/build.data
1550 echo "shell='$shell'" >> $BUILD_ROOT/.build/build.data
1551 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
1552 umount -n $BUILD_ROOT/proc 2> /dev/null || true
1553 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
1554 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
1556 if [ -n "$VM_IMAGE" ]; then
1558 # needs to work otherwise we have a corrupted file system
1559 umount $BUILD_ROOT || cleanup_and_exit 1
1562 if check_use_emulator; then
1563 if [ -x "$BUILD_DIR/initvm" -a -e "$BUILD_DIR/qemu-reg" ]; then
1564 vm_init_script="/.build/initvm"
1565 elif [ -e $BUILD_DIR/initscript_qemu_vm ]; then
1566 vm_init_script="/.build/initscript_qemu_vm"
1568 echo "Warning: can't find initscript to register binfmts"
1571 vm_init_script="/.build/build"
1574 if [ "$VM_TYPE" = 'xen' ]; then
1575 XMROOT="file:$(readlink -f $VM_IMAGE)"
1576 XMROOT=${XMROOT/#file:\/dev/phy:/dev}
1577 XMROOT="disk=$XMROOT,hda1,w"
1579 if test -n "$VM_SWAP" ; then
1580 XMSWAP="file:$(readlink -f $VM_SWAP)"
1581 XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
1582 XMSWAP="disk=$XMSWAP,hda2,w"
1584 XENID="${VM_IMAGE%/root}"
1585 XENID="${XENID%/tmpfs}"
1586 XENID="${XENID##*/}"
1587 XENID="${XENID#root_}"
1589 echo "booting XEN kernel ..."
1590 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1591 echo "Instance already exist, something really went wrong..."
1592 echo "Please report to your server admin, there might be multiple services running for same domain"
1595 XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
1596 echo "kernel = \"$vm_kernel\"" > $XEN_CONF_FILE
1597 echo "ramdisk = \"$vm_initrd\"" >> $XEN_CONF_FILE
1598 echo "memory = ${MEMSIZE:-64}" >> $XEN_CONF_FILE
1599 echo "vcpus = $BUILD_JOBS" >> $XEN_CONF_FILE
1600 echo "root = \"/dev/hda1 ro\"" >> $XEN_CONF_FILE
1601 echo "extra = \"init=/bin/bash console=ttyS0 panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
1602 echo "on_poweroff = 'destroy'" >> $XEN_CONF_FILE
1603 echo "on_reboot = 'destroy'" >> $XEN_CONF_FILE
1604 echo "on_crash = 'destroy'" >> $XEN_CONF_FILE
1605 set -- xm create -c $XEN_CONF_FILE name="build_$XENID" $XMROOT $XMSWAP extra="quiet init="$vm_init_script" elevator=noop panic=1 console=ttyS0"
1606 if test "$PERSONALITY" != 0 ; then
1607 # have to switch back to PER_LINUX to make xm work
1611 "$@" || cleanup_and_exit 3
1613 elif [ "$VM_TYPE" = 'uml' ]; then
1614 echo "booting UML kernel ..."
1615 set -- $uml_kernel initrd=$uml_initrd root=/ubda init="$vm_init_script" panic=1 elevator=noop quiet ubd0=$VM_IMAGE ${MEMSIZE:+mem=$MEMSIZE}
1618 elif [ "$VM_TYPE" = 'qemu' -o "$VM_TYPE" = 'kvm' ]; then
1619 echo "booting $VM_TYPE ..."
1620 if [ "$VM_TYPE" = 'kvm' -a -b "$VM_IMAGE" ]; then
1621 # speed optimization when using kvm with raw devices
1624 # speed optimization when using kvm with raw files
1625 CACHE=",cache=unsafe"
1627 if [ "$kvm_virtio" = 1 ]; then
1628 qemu_args=(-drive file="$VM_IMAGE",if=virtio$CACHE -drive file="$VM_IMAGE",if=ide,index=0$CACHE)
1629 if [ -n "$VM_SWAP" ]; then
1630 qemu_args=("${qemu_args[@]}" "-drive")
1631 qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=virtio$CACHE")
1634 if [ "$HOST_ARCH" = "ppc" ];then
1635 qemu_args=( "-drive" )
1636 qemu_args=("${qemu_args[@]}" "file=$VM_IMAGE,if=scsi,cache=unsafe")
1638 qemu_args=(-hda "$VM_IMAGE")
1640 if [ -n "$VM_SWAP" ]; then
1641 qemu_args=("${qemu_args[@]}" "-drive")
1642 if [ "$HOST_ARCH" = "ppc" ];then
1647 qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=$DISK_IF,index=1$CACHE")
1650 if [ -n "$BUILD_JOBS" -a "$icecream" = 0 ]; then
1651 qemu_args=("${qemu_args[@]}" "-smp" "$BUILD_JOBS")
1653 # cpuid is not set correctly in kvm without this
1654 if [ "$HOST_ARCH" != "ppc" ]; then
1657 if [ "$VM_TYPE" = 'kvm' ]; then
1658 KVM_OPTIONS="$KVM_OPTIONS -cpu host"
1661 set -- $qemu_bin -no-reboot -nographic -net none $KVM_OPTIONS \
1662 -kernel $vm_kernel \
1663 -initrd $vm_initrd \
1664 -append "root=$qemu_rootdev panic=1 quiet no-kvmclock nmi_watchdog=0 rw elevator=noop console=$console init=$vm_init_script" \
1665 ${MEMSIZE:+-m $MEMSIZE} \
1668 if test "$PERSONALITY" != 0 ; then
1669 # have to switch back to PER_LINUX to make qemu work
1674 elif [ "$VM_TYPE" = 'lxc' ]; then
1675 echo "booting $VM_TYPE ..."
1676 LXCCONF="$BUILD_ROOT/.build.lxc.conf"
1678 cat $BUILD_DIR/lxc.conf > "$LXCCONF"
1679 cat >> "$LXCCONF" <<-EOF
1680 lxc.rootfs = $BUILD_ROOT
1682 # XXX: do this always instead of leaking the hosts' one?
1683 echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
1684 LXCID=${BUILD_ROOT##*/}
1685 lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
1686 lxc-create -n "$LXCID" -f "$LXCCONF" || cleanup_and_exit 1
1687 lxc-start -n "$LXCID" "$vm_init_script"
1689 test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
1690 cleanup_and_exit "$BUILDSTATUS"
1692 if test -n "$VM_SWAP" ; then
1693 BUILDSTATUS=`dd if="$VM_SWAP" bs=12 count=1 2>/dev/null`
1694 case $BUILDSTATUS in
1696 mkdir -p $BUILD_ROOT/.build.packages
1697 cd $BUILD_ROOT/.build.packages || cleanup_and_exit 1
1698 echo "build_ extracting built packages..."
1699 extractbuild --disk "$VM_IMAGE" --input "$VM_SWAP" --skip 512 -v || cleanup_and_exit 3
1700 # create same layout as with plain chroot
1701 if test "$BUILDTYPE" = spec ; then
1703 for i in *src.rpm *.desktopfiles ; do
1704 test -e "$i" || continue
1708 test -e "$i" || continue
1715 elif test "$BUILDTYPE" = dsc ; then
1717 find . -type f | while read i; do mv "$i" DEBS/; done
1718 elif test "$BUILDTYPE" = arch ; then
1720 find . -type f | while read i; do mv "$i" ARCHPKGS/; done
1723 find . -type f | while read i; do mv "$i" KIWI/; done
1726 test -f "$i" || continue
1729 *) mkdir -p OTHER ; mv $i OTHER/ ;;
1732 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1735 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1738 echo "No buildstatus set, either the base system is broken (glibc/bash/perl)"
1739 echo "or the build host has a kernel or hardware problem..."
1748 if test "$DO_INIT" = true ; then
1750 # create legacy .buildenv file
1752 test -z "$INCARNATION" && INCARNATION=0
1753 echo "BUILD_INCARNATION=$INCARNATION" > $BUILD_ROOT/.buildenv
1754 CREATE_BUILD_BINARIES=
1755 egrep '^#[ ]*needsbinariesforbuild[ ]*$' >/dev/null <$MYSRCDIR/$SPECFILE && CREATE_BUILD_BINARIES=--create-build-binaries
1756 set -- init_buildsystem --cachedir "$CACHE_DIR" "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1758 "$@" || cleanup_and_exit 1
1760 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
1762 echo "build does not work on a completely full filesystem"
1765 mount -n -tproc none $BUILD_ROOT/proc || true
1766 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1771 if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
1772 read BUILD_DIST < $BUILD_ROOT/.guessed_dist
1776 # fix rpmrc if we are compiling for i686
1778 test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
1779 if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
1780 mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
1781 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
1785 # install dummy sign program if needed
1787 test -f $BUILD_ROOT/usr/bin/sign_installed && mv $BUILD_ROOT/usr/bin/sign_installed $BUILD_ROOT/usr/bin/sign
1788 if test -n "$SIGNDUMMY" ; then
1789 test -f $BUILD_ROOT/usr/bin/sign && mv $BUILD_ROOT/usr/bin/sign $BUILD_ROOT/usr/bin/sign_installed
1790 cp $BUILD_DIR/signdummy $BUILD_ROOT/usr/bin/sign
1791 chmod 755 $BUILD_ROOT/usr/bin/sign
1795 # check if we want to build with the abuild user
1798 if test -x $BUILD_ROOT/bin/rpm ; then
1799 SUSE_VERSION=`chroot $BUILD_ROOT /bin/rpm --eval '%{?suse_version}' 2>/dev/null`
1800 if test -n "$SUSE_VERSION" && test "$SUSE_VERSION" -le 1020 ; then
1804 if test "$BUILD_USER" = abuild ; then
1805 egrep '^#[ ]*needsrootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=root
1807 egrep '^#[ ]*norootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=abuild
1809 test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
1811 if test $BUILD_USER = abuild ; then
1812 if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1813 echo "abuild:x:${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_ROOT/etc/passwd
1814 echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed on Mandriva 2009
1815 echo 'abuild:*::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu
1816 echo "abuild:x:${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
1817 mkdir -p $BUILD_ROOT/home/abuild
1818 chown "$ABUILD_UID:$ABUILD_GID" $BUILD_ROOT/home/abuild
1820 if ! egrep "^abuild:x?:${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_ROOT/etc/passwd ; then
1821 echo "abuild user present in the buildroot ($BUILD_ROOT) but uid:gid does not match"
1822 echo "buildroot currently using:"
1823 egrep "^abuild:" <$BUILD_ROOT/etc/passwd
1824 echo "build script attempting to use:"
1825 echo "abuild::${ABUILD_UID}:${ABUILD_GID}:..."
1826 echo "build aborting"
1830 if test -f $BUILD_ROOT/etc/shadow ; then
1831 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
1833 if test -f $BUILD_ROOT/etc/gshadow ; then
1834 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/gshadow > $BUILD_ROOT/etc/gshadow.t && mv $BUILD_ROOT/etc/gshadow.t $BUILD_ROOT/etc/gshadow
1836 BUILD_USER_ABUILD_USED=true
1841 if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1842 rm -rf $BUILD_ROOT/home/abuild
1843 egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
1844 mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd
1845 egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new
1846 mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group
1847 if test -f $BUILD_ROOT/etc/shadow ; then
1848 egrep -v '^abuild:' <$BUILD_ROOT/etc/shadow >$BUILD_ROOT/etc/shadow.new
1849 mv $BUILD_ROOT/etc/shadow.new $BUILD_ROOT/etc/shadow
1851 if test -f $BUILD_ROOT/etc/gshadow ; then
1852 egrep -v '^abuild:' <$BUILD_ROOT/etc/gshadow >$BUILD_ROOT/etc/gshadow.new
1853 mv $BUILD_ROOT/etc/gshadow.new $BUILD_ROOT/etc/gshadow
1858 if test "$BUILDTYPE" = spec ; then
1859 TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER`
1860 if test -z "$TOPDIR"; then
1861 echo "Error: TOPDIR empty"
1865 TOPDIR=/usr/src/packages
1866 mkdir -p $BUILD_ROOT$TOPDIR
1869 rm -f $BUILD_ROOT/.build.packages
1870 ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
1872 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1873 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
1879 # nasty hack to prevent rpath on known paths
1880 # FIXME: do this only for suse
1881 if test -d "$BUILD_ROOT/etc/profile.d" ; then
1882 echo "export SUSE_IGNORED_RPATHS=/etc/ld.so.conf" > "$BUILD_ROOT/etc/profile.d/buildsystem.sh"
1886 # now clean up RPM building directories
1888 rm -rf $BUILD_ROOT$TOPDIR
1889 for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT OTHER ; do
1890 mkdir -p $BUILD_ROOT$TOPDIR/$i
1892 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1895 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
1896 if test "$BUILDTYPE" = kiwi ; then
1897 mkdir -p $BUILD_ROOT$TOPDIR/KIWI
1898 if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1899 mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1901 if test -z "$LINKSOURCES" ; then
1902 cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1904 cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1906 if test "$?" != 0 ; then
1907 echo "source copy failed"
1912 cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1914 # strip prefix from autogenerated files of source services.
1915 for i in $BUILD_ROOT$TOPDIR/SOURCES/_service\:*; do
1916 mv "$i" "${i%/*}/${i##*:}"
1918 SPECFILE="${SPECFILE##*:}"
1920 test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
1922 test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
1924 if test "$BUILDTYPE" = spec ; then
1925 # do buildrequires/release substitution
1927 if test -n "$RELEASE"; then
1928 args=(--release "$RELEASE")
1930 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
1931 # extract macros from configuration
1932 getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
1933 if test -n "$BUILD_DEBUG" ; then
1935 %prep %{?!_suse_insert_debug_package_seen:%?_suse_insert_debug_package}%%prep
1936 %package %{?!_suse_insert_debug_package_seen:%?_suse_insert_debug_package}%%package
1937 %suse_insert_debug_package \
1938 %global _suse_insert_debug_package \\\
1939 %%global _suse_insert_debug_package_seen 1 \\\
1942 ' >> $BUILD_ROOT/root/.rpmmacros
1945 if [ -n "$BUILD_JOBS" ]; then
1946 cat >> $BUILD_ROOT/root/.rpmmacros <<-EOF
1948 %_smp_mflags -j$BUILD_JOBS
1951 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
1952 # extract optflags from configuration
1953 getoptflags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_ROOT/root/.rpmrc
1954 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
1955 if test -z "$ABUILD_TARGET"; then
1956 ABUILD_TARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" )
1957 test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
1960 if test -f $BUILD_ROOT/.spec.new ; then
1961 if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
1962 echo -----------------------------------------------------------------
1963 echo I have the following modifications for $SPECFILE:
1964 sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE > $BUILD_ROOT/.spec.t1
1965 sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2
1966 diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
1967 rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
1968 mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE
1970 rm -f $BUILD_ROOT/.spec.new
1974 if test "$BUILDTYPE" = dsc ; then
1975 rm -rf $BUILD_ROOT$TOPDIR/BUILD
1976 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
1977 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1979 DEB_SOURCEDIR=$TOPDIR/SOURCES
1980 DEB_DSCFILE=$SPECFILE
1981 for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
1982 test -f $f && DEB_TRANSFORM=true
1984 if test -n "$DEB_TRANSFORM" ; then
1985 echo "running debian transformer..."
1986 if ! debtransform $CHANGELOGARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
1987 echo "debian transforming failed."
1990 DEB_SOURCEDIR=$TOPDIR/SOURCES.DEB
1991 for DEB_DSCFILE in $BUILD_ROOT/$DEB_SOURCEDIR/*.dsc ; do : ; done
1992 DEB_DSCFILE="${DEB_DSCFILE##*/}"
1994 chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
1997 if test "$BUILDTYPE" = arch ; then
1998 echo "Preparing sources..."
1999 chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES && makepkg -s -o 2>&1 >/dev/null" - $BUILD_USER
2000 mv $BUILD_ROOT/$TOPDIR/SOURCES/* -t $BUILD_ROOT/$TOPDIR/BUILD
2003 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
2004 cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
2006 echo -----------------------------------------------------------------
2007 if test "$BUILD_USER" = root ; then
2008 echo ----- building $SPECFILE
2010 echo ----- building $SPECFILE "(user $BUILD_USER)"
2012 echo -----------------------------------------------------------------
2013 echo -----------------------------------------------------------------
2014 if [ -n "$RUNNING_IN_VM" ]; then
2015 if [ -x /sbin/ip ]; then
2016 ip addr add 127.0.0.1/8 dev lo
2019 ifconfig lo 127.0.0.1 up
2021 if [ -n "$MYHOSTNAME" ]; then
2022 hostname "$MYHOSTNAME"
2026 BUILD_SUCCEEDED=false
2028 if test -n "$OVERLAY" ; then
2029 if test -d "$OVERLAY"; then
2031 echo "Copying overlay to BUILD_ROOT"
2032 tar -cpf - . | (cd $BUILD_ROOT ; tar -xvf -)
2035 echo "OVERLAY ($OVERLAY) is no directory - skipping"
2039 if test -n "$RSYNCSRC" ; then
2040 if test -n "$RSYNCDEST"; then
2041 if test -d "$RSYNCSRC"; then
2042 if ! test -d "$BUILD_ROOT/$RSYNCDEST"; then
2043 echo "ATTENTION! Creating target directory ($BUILD_ROOT/$RSYNCDEST) as its not there."
2044 mkdir -p $BUILD_ROOT/$RSYNCDEST
2046 echo "Running rsync ..."
2047 rsync -av $RSYNCSRC/* $BUILD_ROOT/$RSYNCDEST/
2048 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/$RSYNCDEST"
2052 echo "RSYNCSRC is no directory - skipping"
2055 echo "RSYNCSRC given, but not RSYNCDEST - skipping"
2059 if test "$BUILDTYPE" = spec ; then
2060 test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
2063 test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
2065 # XXX: move _srcdefattr to macro file?
2066 rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--define" "_srcdefattr (-,root,root)")
2067 if [ "$rpmbuild" == "rpmbuild" ]; then
2068 # use only --nosignature for rpm v4
2069 rpmbopts[${#rpmbopts[@]}]="--nosignature"
2071 if [ -n "$ABUILD_TARGET" ]; then
2072 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
2074 if [ -n "$DISTURL" ]; then
2075 rpmbopts[${#rpmbopts[@]}]='--define'
2076 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
2078 if test -s "$BUILD_ROOT/usr/lib/rpm/mandriva/macros" ; then
2079 rpmbopts[${#rpmbopts[@]}]='--eval'
2080 rpmbopts[${#rpmbopts[@]}]="%undefine _enable_debug_packages"
2082 if [ -n "$BUILD_DEBUG" ]; then
2083 rpmbopts[${#rpmbopts[@]}]='--eval'
2084 rpmbopts[${#rpmbopts[@]}]="%suse_insert_debug_package"
2086 if [ -n "$RSYNCDONE" ] ; then
2087 rpmbopts[${#rpmbopts[@]}]='--define'
2088 rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
2091 # su involves a shell which would require even more
2092 # complicated quoting to bypass than this
2093 toshellscript $rpmbuild \
2094 "${definesnstuff[@]}" \
2096 "$TOPDIR/SOURCES/$SPECFILE" \
2097 > $BUILD_ROOT/.build.command
2098 chmod 755 $BUILD_ROOT/.build.command
2100 if test -n "$shell"; then
2101 chroot $BUILD_ROOT su -
2103 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2107 if test "$BUILDTYPE" = dsc ; then
2108 # Checks to see if a build script should be used
2109 # this allows the build environment to be manipulated
2110 # and alternate build commands can be used
2111 # Debian policy requires to build with single CPU by default
2112 # if [ -n "$BUILD_JOBS" ]; then
2113 # DSC_BUILD_JOBS="-j$BUILD_JOBS"
2115 DSC_BUILD_CMD="dpkg-buildpackage -us -uc -rfakeroot-tcp $DSC_BUILD_JOBS"
2116 if test -e $BUILD_ROOT/$TOPDIR/SOURCES/build.script ; then
2117 echo "Sourcing build.script to build - it should normally run 'dpkg-buildpackage -us -uc -rfakeroot-tcp'"
2118 DSC_BUILD_CMD="source $TOPDIR/SOURCES/build.script"
2119 chmod +x $BUILD_ROOT/$TOPDIR/SOURCES/build.script
2122 if test -n "$shell"; then
2123 chroot $BUILD_ROOT su -
2125 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && $DSC_BUILD_CMD" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2128 mkdir -p $BUILD_ROOT/$TOPDIR/DEBS
2129 for DEB in $BUILD_ROOT/$TOPDIR/*.deb ; do
2130 test -e "$DEB" && mv "$DEB" "$BUILD_ROOT/$TOPDIR/DEBS"
2133 ln $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE $BUILD_ROOT/$TOPDIR/DEBS/
2135 ln $BUILD_ROOT/$DEB_SOURCEDIR/$f $BUILD_ROOT/$TOPDIR/DEBS/
2136 done < <(sed -ne '/^Files:/,$s/^ ................................ [0-9][0-9]* //p' < $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE)
2139 if test "$BUILDTYPE" = arch ; then
2140 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && makepkg -f" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2141 mkdir -p $BUILD_ROOT/$TOPDIR/ARCHPKGS
2142 for PKG in $BUILD_ROOT/$TOPDIR/BUILD/*.pkg.tar.?z ; do
2143 test -e "$PKG" && mv "$PKG" "$BUILD_ROOT/$TOPDIR/ARCHPKGS"
2147 if test "$BUILDTYPE" = kiwi ; then
2148 . $BUILD_DIR/build_kiwi.sh
2152 test "$BUILD_SUCCEEDED" = true || cleanup_and_exit 1
2153 test -d "$SRCDIR" && cd "$SRCDIR"
2156 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
2157 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
2159 if test -n "$RPMS" -a -n "$BUILD_USER_ABUILD_USED" ; then
2160 echo "... checking for files with abuild user/group"
2162 while read un gn fn ; do
2163 if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
2167 done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
2168 if test -n "$BADFILE" ; then
2169 echo "please fix your filelist (e.g. add defattr)"
2174 if test -n "$RPMS" -a -d "$BUILD_ROOT/usr/lib/build/checks" ; then
2176 export DO_RPM_REMOVE=true
2177 for SRPM in $BUILD_ROOT/$TOPDIR/SRPMS/*src.rpm ; do
2178 test -f "$SRPM" && PNAME=`rpm --nodigest --nosignature -qp --qf "%{NAME}" $SRPM`
2180 for CHECKSCRIPT in $BUILD_ROOT/usr/lib/build/checks/* ; do
2181 echo "... running `basename $CHECKSCRIPT`"
2182 $CHECKSCRIPT || cleanup_and_exit 1
2186 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
2187 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
2189 if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_ROOT/opt/testing/bin/rpmlint" ; then
2190 LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
2191 \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
2192 -o -name "*-32bit-*" -o -name "*-64bit-*" \
2193 -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
2194 -o -type f -name '*.rpm' -print))
2195 SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
2197 echo "RPMLINT report:"
2198 echo "==============="
2199 rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log
2200 rm -f "$BUILD_ROOT$rpmlint_logfile"
2202 chroot $BUILD_ROOT su -s /opt/testing/bin/rpmlint "$BUILD_USER" -- \
2203 --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} \
2204 ${SRPM_FILE_LIST[*]#$BUILD_ROOT} > "$BUILD_ROOT$rpmlint_logfile" || ret=1
2205 cat "$BUILD_ROOT$rpmlint_logfile"
2207 if test "$ret" = 1; then
2212 if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS"; then
2217 # post build scripts
2218 # TODO: don't hardcode. instead run scripts in a directory as it's done for the checks
2219 if test -n "$RPMS" \
2220 -a -d "$BUILD_ROOT/$TOPDIR/RPMS" \
2221 -a -d "$BUILD_ROOT/.build.oldpackages" \
2223 if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
2224 echo "... comparing built packages with the former built"
2225 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
2226 if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
2227 chroot $BUILD_ROOT touch /.build/.same_result_marker
2228 # XXX: dirty build service hack. fix bs_worker. Search for
2229 # 'same_result_marker' for traces of a first try to get rid of this
2230 if test -n "$REASON" -a -n "$DISTURL"; then
2235 if test ! -e $BUILD_ROOT/.build/.same_result_marker \
2236 -a -x "$BUILD_ROOT/usr/bin/makedeltarpm" \
2237 -a -x $BUILD_ROOT/usr/lib/build/mkdrpms; then
2238 echo "... creating delta rpms"
2239 ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS")
2240 chroot $BUILD_ROOT /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}"
2244 if test -n "$RUNNING_IN_VM" -a -n "$VM_SWAP"; then
2245 echo "... saving built packages"
2247 args="--padstart 512 --padend 512 -v"
2248 case "$BUILDTYPE" in
2250 computeblocklists $args $TOPDIR/RPMS/*/*.{d,}rpm $TOPDIR/SRPMS/* $TOPDIR/OTHER/* > "$VM_SWAP"
2253 computeblocklists $args $TOPDIR/DEBS/*.deb $TOPDIR/SOURCES.DEB/* $TOPDIR/OTHER/* > "$VM_SWAP"
2256 computeblocklists $args $TOPDIR/KIWI/* $TOPDIR/OTHER/* > "$VM_SWAP"
2259 computeblocklists $args $TOPDIR/ARCHPKGS/* $TOPDIR/OTHER/* > "$VM_SWAP"
2261 esac || cleanup_and_exit 1
2265 echo "$HOST finished \"build $SPECFILE\" at `date --utc`."
2268 cleanup_and_exit "$exitcode"