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 background_monitor_process()
613 if [ -e /proc/meminfo ]; then
615 while read key value unit; do
617 MemTotal:|SwapTotal:)
618 memtotal=$(( $memtotal + $value ))
620 MemFree:|SwapFree:|SwapCached:|Cached:|Buffers:)
621 memtotal=$(( $memtotal - $value ))
626 if [ ${memtotal} -gt $max_mem ]; then
627 max_mem="${memtotal}"
628 echo $(( $max_mem / 1024 )) > /.build/_statistics.memory
633 if [ -x /usr/bin/df ]; then
634 c=(`/usr/bin/df -m $1 | tail -n 1`)
636 if [ ${c[2]} -gt $max ]; then
638 echo $max > /.build/_statistics.df
644 detect_vm_2nd_stage()
646 if ! test "$0" = "/.build/build" ; then
649 if test $$ -eq 1 ; then
650 # ignore special init signals if we're init
651 # we're using ' ' instead of '' so that the signal handlers
652 # are reset in the child processes
657 echo "2nd stage started in virtual machine"
660 . $BUILD_DIR/build.data
661 echo "machine type: `uname -m`"
662 if test "$PERSONALITY" != 0 -a -z "$PERSONALITY_SET" ; then
663 export PERSONALITY_SET=true
664 echo "switching personality to $PERSONALITY..."
665 # this is 32bit perl/glibc, thus the 32bit syscall number
666 exec perl -e 'syscall(136, '$PERSONALITY') == -1 && warn("personality: $!\n");exec "/.build/build" || die("/.build/build: $!\n")'
669 test -e /proc/version || mount -orw -n -tproc none /proc
670 if test "$VM_TYPE" != 'lxc'; then
671 mount -n ${VMDISK_MOUNT_OPTIONS},remount,rw /
673 umount /run >/dev/null 2>&1
674 # qemu inside of xen does not work, check again with kvm later before enabling this
675 # if [ -e /dev/kqemu ]; then
676 # # allow abuild user to run qemu
677 # chmod 0666 /dev/kqemu
679 if test -n "$VM_SWAP" ; then
680 for i in 1 2 3 4 5 6 7 8 9 10 ; do
681 test -e "$VM_SWAP" && break
682 test $i = 1 && echo "waiting for $VM_SWAP to appear"
687 # recreate the swap device manually if it didn't exist for some
688 # reason, hardcoded to hda2 atm
689 if ! test -b "$VM_SWAP" ; then
692 mknod "$VM_SWAP" b 3 2
695 swapon -v "$VM_SWAP" || exit 1
699 # fork a process monitoring max filesystem fillment during build
700 background_monitor_process / >& /dev/null &
708 if [ -z "$SPECFILES" ]; then
711 set -- "${SPECFILES[@]}"
715 if [ "$spec" = "${spec#/}" ]; then
719 if [ -d "$spec" ]; then
720 specs=("$spec"/*.spec)
721 if [ -n "$specs" ]; then
722 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
724 specs=("$spec"/*.spec)
725 if [ -n "$specs" ]; then
726 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
730 SPECFILES[${#SPECFILES[@]}]="$spec";
734 if test -z "$SPECFILES"; then
735 echo no spec files or src rpms found in $@. exit...
740 become_root_or_fail()
742 if [ ! -w /root ]; then
743 echo "You have to be root to use $0" >&2
751 if [ -d "$BUILD_ROOT" ]; then
752 # check if it is owned by root
753 if [ -z "$RUNNING_IN_VM" -a \! -O "$BUILD_ROOT" -a "`stat -c %u $BUILD_ROOT`" -ne 0 ]; then
754 echo "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
758 test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
759 if ! mkdir $BUILD_ROOT; then
760 echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
765 if [ ! -w "$BUILD_ROOT" ]; then
766 echo "Error: BUILD_ROOT=$BUILD_ROOT not writeable, try --clean."
770 rm -rf "$BUILD_ROOT/.build.packages"
771 if [ -z "$VM_TYPE" -a -z "$RUNNING_IN_VM" ]; then
772 # don't touch this in VM
773 rm -rf "$BUILD_ROOT/.build"
774 mkdir -p "$BUILD_ROOT/.build"
780 perl -e 'syscall('$PERSONALITY_SYSCALL', 0); exec(@ARGV) || die("$ARGV[0]: $!\n")' "$@"
789 if [ "$uname" != "ppc" -a "$uname" != "ppc64" ]; then
795 # XXX is this ok for ppc32 hosts? do we care?
796 export kvm_bin="/usr/bin/qemu-system-ppc64"
798 # XXX check host CPU and adjust guest CPU accordingly
799 export KVM_OPTIONS="-enable-kvm -M pseries -mem-path /hugetlbfs"
800 export VM_KERNEL=/boot/vmlinux
801 export VM_INITRD=/boot/initrd
802 if [ -z "$RUNNING_IN_VM" -a "$VM_TYPE" = "kvm" ];then
803 if ! grep "/hugetlbfs" /proc/mounts; then
804 echo "hugetlbfs is not mounted"
807 PAGES_FREE=$(cat /sys/kernel/mm/hugepages/hugepages-16384kB/free_hugepages)
808 PAGES_REQ=$(( ${MEMSIZE:-64} / 16 ))
809 if [ "$PAGES_FREE" -lt "$PAGES_REQ" ];then
810 echo "please adjust nr_hugepages"
813 if ! grep -q kvm_rma_count /proc/cmdline; then
814 echo "put kvm_rma_count=<VM number> to your boot options"
817 if ! grep -q kvm_hpt_count /proc/cmdline; then
818 echo "put kvm_hpt_count=<VM number> to your boot options"
828 archname=`perl -V:archname`
829 archname="${archname#archname=?}"
831 x86_64*) PERSONALITY_SYSCALL=135 ;;
832 alpha*) PERSONALITY_SYSCALL=324 ;;
833 sparc*) PERSONALITY_SYSCALL=191 ;;
834 ia64*) PERSONALITY_SYSCALL=1140 ;;
835 i?86*|ppc*|arm*|sh4|cris|m68k|s390*|unicore32|microblaze) PERSONALITY_SYSCALL=136 ;;
836 *) echo "ARCHITECTURE PERSONALITY IS UNKNOWN"; exit 1;;
841 if detect_vm_2nd_stage ; then
842 set "/.build-srcdir/$SPECFILE"
845 export PATH=$BUILD_DIR:/sbin:/usr/sbin:$PATH
847 . $BUILD_DIR/common_functions || exit 1
853 if [ -z "$ARG" ]; then
854 echo "$PARAM needs an agrument" >&2
859 while test -n "$1"; do
862 [ "$ARG" = "${ARG#-}" ] || ARG=""
868 set -- "----noarg=$PARAM" "$@"
882 CLEAN_BUILD='--clean'
898 export VERIFY_BUILD_SYSTEM=true
912 BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
922 CREATE_BASELIBS=internal
925 USE_SYSTEM_QEMU="--use-system-qemu"
939 old_packages=("${old_packages[@]}" "$ARG")
947 *-xen|*-kvm|--uml|--qemu)
949 if [ -n "$ARG" ]; then
963 xen|kvm|uml|qemu|lxc)
964 test -z "$VM_IMAGE" && VM_IMAGE=1
966 none|chroot) VM_TYPE='' ;;
968 echo "VM $VM_TYPE not supported"
984 *-xenmemory|*-memory)
999 *-vmdisk-rootsize|--vm-disk-size)
1001 VMDISK_ROOTSIZE="$ARG"
1004 *-vmdisk-swapsize|--vm-swap-size)
1006 VMDISK_SWAPSIZE="$ARG"
1009 *-vmdisk-filesystem|--vm-disk-filesystem)
1011 VMDISK_FILESYSTEM="$ARG"
1014 *-vmdisk-mount-options|--vm-disk-mount-options)
1016 # options needs to be quoted to handle argument which might start with "-o ..."
1017 VMDISK_MOUNT_OPTIONS=$(echo $ARG | sed 's/^\"\(.*\)\"$/\1/g')
1021 # delete old root/swap to get rid of the old blocks
1026 RPMLIST="--rpmlist $ARG"
1031 HUGETLBFSPATH="$ARG"
1054 BUILD_RPM_BUILD_STAGE="$ARG"
1058 USEUSEDFORBUILD="--useusedforbuild"
1066 --define|--with|--without)
1068 definesnstuff[${#definesnstuff[@]}]="$PARAM";
1069 definesnstuff[${#definesnstuff[@]}]="$ARG";
1072 --repository|--repo)
1074 repos[${#repos[@]}]="$PARAM";
1075 repos[${#repos[@]}]="$ARG";
1081 if [ "$icecream" -gt 0 ]; then
1106 echo "$ARG does not take an argument"
1130 if test -n "${ABUILD_ID//[0-9:]/}"; then
1131 echo "--uid argument must be uid:gid"
1134 ABUILD_UID=${ABUILD_ID%:*}
1135 ABUILD_GID=${ABUILD_ID#*:}
1146 echo Unknown Option "$PARAM". Exit.
1150 SPECFILES[${#SPECFILES[@]}]="$PARAM";
1157 if test "$VM_TYPE" = "lxc"; then
1162 if test "$VMDISK_MOUNT_OPTIONS" = __default; then
1163 if test "$VMDISK_FILESYSTEM" = reiserfs ; then
1164 VMDISK_MOUNT_OPTIONS='-o data=writeback,commit=150,noatime'
1165 elif test "$VMDISK_FILESYSTEM" = btrfs ; then
1166 VMDISK_MOUNT_OPTIONS='-o nobarrier,noatime'
1168 VMDISK_MOUNT_OPTIONS='-o data=writeback,nobarrier,commit=150,noatime'
1172 if test -n "$KILL" ; then
1173 test -z "$SRCDIR" || usage
1174 if test -n "$VM_IMAGE" -a -n "$VM_SWAP" -a -n "$VM_TYPE"; then
1175 # mark job as failed so that we don't extract packages
1176 echo -n "BUILDSTATUS1" >"$VM_SWAP"
1178 (set -C; > "$BUILD_ROOT/exit" 2>/dev/null || true)
1179 if test "$VM_TYPE" = 'lxc'; then
1180 LXCID=${BUILD_ROOT##*/}
1181 lxc-stop -n "$LXCID" || true
1182 lxc-destroy -n "$LXCID"
1183 elif test -z "$VM_IMAGE" ; then
1184 if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
1185 echo "could not kill build in $BUILD_ROOT"
1188 elif test "$VM_TYPE" = 'xen'; then
1189 XENID="${VM_IMAGE%/root}"
1190 XENID="${XENID%/tmpfs}"
1191 XENID="${XENID##*/}"
1192 XENID="${XENID#root_}"
1193 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1194 if ! xm destroy "build_$XENID" ; then
1195 echo "could not kill xen build $XENID"
1199 elif test -n "$VM_TYPE"; then
1200 if ! fuser -k -TERM "$VM_IMAGE"; then
1201 echo "could not kill build in $VM_IMAGE"
1205 echo "don't know how to kill this build job"
1211 if [ "$VM_TYPE" = 'xen' -a -z "$RUNNING_IN_VM" ]; then
1212 # XXX: merge with kvm path?
1213 if [ -n "$VM_KERNEL" ]; then
1214 vm_kernel="$VM_KERNEL"
1215 elif [ -e "/boot/vmlinuz-xen" ]; then
1216 vm_kernel="/boot/vmlinuz-xen"
1218 if [ -n "$VM_INITRD" ]; then
1219 vm_initrd="$VM_INITRD"
1220 elif [ -e "/boot/initrd-xen" ]; then
1221 vm_initrd="/boot/initrd-xen"
1225 if [ "$VM_TYPE" = 'kvm' -a -z "$RUNNING_IN_VM" ]; then
1226 if [ ! -r /dev/kvm -o ! -x "$kvm_bin" ]; then
1227 echo "host doesn't support kvm"
1228 echo "either the kvm kernel-module is not loaded or kvm is not installed or hardware virtualization is deactivated in the BIOS."
1232 if [ -n "$VM_KERNEL" ]; then
1233 vm_kernel="$VM_KERNEL"
1236 # check if a SUSE system with virtio initrd is running
1237 if [ -z "$VM_INITRD" -a -e /etc/sysconfig/kernel ]; then
1238 a=$( source /etc/sysconfig/kernel; echo $INITRD_MODULES )
1242 [ "$i" == "virtio_pci" ] && have_virtio_pci="1"
1243 [ "$i" == "virtio_blk" ] && have_virtio_blk="1"
1245 [ -n "$have_virtio_pci" -a -n "$have_virtio_blk" ] && VM_INITRD="/boot/initrd"
1248 if [ -n "$VM_INITRD" ]; then
1249 vm_initrd="$VM_INITRD"
1251 elif [ -e "${vm_initrd}-build" ]; then
1252 vm_initrd="${vm_initrd}-build"
1255 if [ -L "$vm_initrd" ]; then
1256 vm_initrd=`readlink -f "$vm_initrd"` || cleanup_and_exit 3
1258 vm_initrd_virtio="${vm_initrd}-virtio"
1260 if [ ! -e ${vm_initrd_virtio} -o $vm_kernel -nt ${vm_initrd_virtio} ]; then
1261 mkinitrd_virtio_cmd=(env rootfstype="$VMDISK_FILESYSTEM" \
1262 mkinitrd -d /dev/null \
1263 -m "ext3 ext4 btrfs reiserfs binfmt_misc virtio_pci virtio_blk" \
1265 -i ${vm_initrd_virtio})
1266 if [ ! -w /root -o -n "$RPMLIST" ]; then
1267 echo "No initrd that provides virtio support found. virtio accelleration disabled."
1268 echo "Run the following command as root to enable virtio:"
1269 shellquote "${mkinitrd_virtio_cmd[@]}"
1271 elif /sbin/modinfo virtio_pci >/dev/null 2>&1; then
1272 echo "creating $vm_initrd_virtio"
1273 "${mkinitrd_virtio_cmd[@]}" || cleanup_and_exit 1
1275 vm_initrd="${vm_initrd_virtio}"
1279 vm_initrd="${vm_initrd_virtio}"
1283 if [ "$HOST_ARCH" = ppc ]; then
1284 # KVM on PPC can not run virtio yet, so we need to use the default vio
1288 if [ "$kvm_virtio" = 1 ]; then
1290 qemu_rootdev=/dev/vda
1293 qemu_rootdev=/dev/sda
1297 if [ "$VM_TYPE" = 'qemu' ]; then
1299 qemu_rootdev=/dev/sda
1302 if [ -z "$RPMLIST" -a -z "$RUNNING_IN_VM" ]; then
1303 if [ -z "$repos" -a -z "$BUILD_RPMS" ]; then
1304 repos=(--repository 'zypp://')
1312 if [ -n "$CLEAN_BUILD" ]; then
1318 if test -n "$LIST_STATE" ; then
1319 BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
1320 test -d "$BUILD_ROOT" || cleanup_and_exit 3
1321 SPECFILE=$SPECFILES # only one specified anyways
1322 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1323 rm -rf "$BUILD_ROOT/usr/src/packages"
1324 mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES $BUILD_ROOT/usr/src/packages/SPECS
1325 rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
1326 echo "could not install $SPECFILE." 2>&1
1327 rm -rf "$BUILD_ROOT"
1330 for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
1332 init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" --list-state "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
1334 rm -rf "$BUILD_ROOT"
1335 cleanup_and_exit $ERR
1338 if test -z "$RUNNING_IN_VM" ; then
1339 if test -n "$VM_IMAGE" ; then
1340 if test "$VM_IMAGE" = 1 ; then
1341 VM_IMAGE="$BUILD_ROOT.img"
1342 echo "using $VM_IMAGE as vm image"
1343 if test -z "$VM_SWAP"; then
1344 VM_SWAP="$BUILD_ROOT.swap"
1345 echo "using $VM_SWAP as vm swap"
1348 if [ "$VM_TYPE" = 'xen' ]; then
1349 # this should not be needed, but sometimes a xen instance got lost
1350 XENID="${VM_IMAGE%/root}"
1351 XENID="${XENID%/tmpfs}"
1352 XENID="${XENID##*/}"
1353 XENID="${XENID#root_}"
1354 xm destroy "build_$XENID" >/dev/null 2>&1
1356 if test -n "$VMDISK_CLEAN" ; then
1357 # delete old root/swap to get rid of the old blocks
1358 if test -f "$VM_IMAGE" ; then
1359 echo "Deleting old $VM_IMAGE"
1362 if test -n "$VM_SWAP" -a -f "$VM_SWAP" ; then
1363 echo "Deleting old $VM_SWAP"
1367 if test ! -e "$VM_IMAGE"; then
1368 echo "Creating $VM_IMAGE (${VMDISK_ROOTSIZE}M)"
1369 mkdir -p "${VM_IMAGE%/*}"
1370 dd if=/dev/zero of="$VM_IMAGE" bs=1M count=0 seek="$VMDISK_ROOTSIZE" || cleanup_and_exit 3
1371 if test -z "$CLEAN_BUILD" ; then
1372 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1375 if test -n "$VM_SWAP" -a ! -e "$VM_SWAP"; then
1377 echo "Creating $VM_SWAP (${VMDISK_SWAPSIZE}M)"
1378 mkdir -p "${VM_SWAP%/*}"
1379 dd if=/dev/zero of="$VM_SWAP" bs=1M count=0 seek="$VMDISK_SWAPSIZE" || cleanup_and_exit 3
1381 if test ! -e "$VM_IMAGE" ; then
1382 echo "you need to create $VM_IMAGE first"
1385 if test -n "$CLEAN_BUILD" ; then
1386 vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
1389 if [ -w /root ]; then
1390 if [ -b $VM_IMAGE ]; then
1391 # mount device directly
1392 mount $VMDISK_MOUNT_OPTIONS $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1394 mount ${VMDISK_MOUNT_OPTIONS},loop $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1397 if ! mount $BUILD_ROOT; then
1398 echo "mounting the build root failed. An fstab entry is probably missing or incorrect."
1399 echo "/etc/fstab should contain an entry like this:"
1400 echo "$VM_IMAGE $BUILD_ROOT auto noauto,user,loop 0 0"
1405 test -w /root || become_root_or_fail
1407 if test -n "$VM_SWAP" ; then
1408 dd if=/dev/zero of="$VM_SWAP" bs=12 count=1 conv=notrunc 2>/dev/null
1409 echo "mkswap $VM_SWAP"
1416 if [ "$BUILD_ROOT" = / ]; then
1417 read dummy dummy browner dummy < <(ls -ld /)
1420 rm -f $BUILD_ROOT/exit
1422 if [ -w /root ]; then
1423 mkdir -p $BUILD_ROOT/proc
1424 mkdir -p $BUILD_ROOT/dev/pts
1425 mount -n -tproc none $BUILD_ROOT/proc || true
1426 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1429 if test -z "$VM_IMAGE" -a -z "$LOGFILE"; then
1430 LOGFILE="$BUILD_ROOT/.build.log"
1433 if test -n "$LOGFILE" -a -z "$shell" ; then
1434 echo logging output to $LOGFILE...
1437 # set start time, to be substracted for build log timestamps
1438 STARTTIME=`perl -e 'print time()'`
1440 if [ -n "$RUNNING_IN_VM" ]; then
1441 # no additional timestamps in inner vm build system
1442 exec 1> >(exec -a 'build logging' tee -a $LOGFILE) 2>&1
1443 elif test -n "$VM_IMAGE" ; then
1444 # external run of virtualization build
1445 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
1448 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
1457 test -z "$HOST" && HOST=`hostname`
1459 if [ -z "$RUNNING_IN_VM" ]; then
1460 echo Using BUILD_ROOT=$BUILD_ROOT
1461 test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
1462 echo Using BUILD_ARCH=$BUILD_ARCH
1463 test -n "$VM_TYPE" && echo "Doing $VM_TYPE build${VM_IMAGE:+ in $VM_IMAGE}"
1467 test "$BUILD_ARCH" = all && BUILD_ARCH=
1468 BUILD_USER_ABUILD_USED=
1470 for SPECFILE in "${SPECFILES[@]}" ; do
1472 SRCDIR="${SPECFILE%/*}"
1473 SPECFILE="${SPECFILE##*/}"
1477 *.spec|*.src.rpm) BUILDTYPE=spec ;;
1478 *.dsc) BUILDTYPE=dsc ;;
1479 *.kiwi) BUILDTYPE=kiwi ;;
1480 PKGBUILD) BUILDTYPE=arch ;;
1481 _preinstallimage) BUILDTYPE=preinstallimage ;;
1483 if test -z "$BUILDTYPE" ; then
1484 echo "don't know how to build $SPECFILE"
1490 if [ -z "$RUNNING_IN_VM" ]; then
1492 echo "$HOST started \"build $SPECFILE\" at `date --utc`."
1494 test -n "$REASON" && echo "$REASON"
1499 # first setup building directory...
1501 test -s "$SPECFILE" || {
1502 echo "$SPECFILE" is empty. This should not happen...
1506 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1507 echo processing src rpm $SRCDIR/$SPECFILE ...
1508 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1510 mkdir -p "$MYSRCDIR"
1511 cd $MYSRCDIR || cleanup_and_exit 1
1512 $BUILD_DIR/unrpm -q $SRCDIR/$SPECFILE || {
1513 echo "could not install $SPECFILE."
1516 for SPECFILE in *.spec ; do : ; done
1521 # FIX to work with baselibs_$PROJ etc
1522 if test "$BUILDTYPE" == "dsc" -a -e ${SRCDIR}/baselibs-deb.conf ; then
1523 # Set CREATE_BASELIBS if not set
1524 echo "dsc build and baselibs-deb.conf present: forcing --baselibs to true"
1525 CREATE_BASELIBS=true
1528 # Currently local osc build does not allow extra .deb packages to be
1529 # specified on the command line. Both init_buildsystem and expanddeps
1530 # need to handle .deb dependencies first
1531 # if test -n "$CREATE_BASELIBS" ; then
1532 # case $BUILDTYPE in
1534 # dsc) BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS libparse-debcontrol-perl" ;;
1538 echo processing specfile $MYSRCDIR/$SPECFILE ...
1541 test -z "$BUILD_EXTRA_PACKS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
1542 test -z "$CREATE_BASELIBS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
1543 test "$ccache" = '0' || ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
1544 test "$icecream" = 0 || ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
1545 test -z "$DO_LINT" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
1547 if test -n "$CHANGELOG" -a -z "$RUNNING_IN_VM" ; then
1548 rm -f $BUILD_ROOT/.build-changelog
1550 *.dsc) CFFORMAT=debian ;;
1553 echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
1554 if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
1555 rm -f $BUILD_ROOT/.build-changelog
1559 if test -n "$VM_TYPE" -a -z "$RUNNING_IN_VM"; then
1560 rm -rf "$BUILD_ROOT/.build"
1561 mkdir -p "$BUILD_ROOT/.build"
1562 if test "$DO_INIT" = true ; then
1563 # do fist stage of init_buildsystem
1564 rm -f $BUILD_ROOT/.build.success
1565 set -- init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" --prepare "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USE_SYSTEM_QEMU $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1567 "$@" || cleanup_and_exit 1
1569 if [ ! -w /root ]; then
1570 # remove setuid bit if files belong to user to make e.g. mount work
1571 find $BUILD_ROOT/{bin,sbin,usr/bin,usr/sbin} -type f -uid $UID -perm +4000 -print0 | xargs -0 --no-run-if-empty chmod -s
1575 # start up xen, rerun ourself
1576 cp -a $BUILD_DIR/. $BUILD_ROOT/.build
1577 if ! test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1578 rm -rf "$BUILD_ROOT/.build-srcdir"
1579 mkdir "$BUILD_ROOT/.build-srcdir"
1580 if test "$BUILDTYPE" = kiwi ; then
1581 cp -pRL "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1583 cp -p "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1585 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1587 # cwd is at $BUILD_ROOT/.build-srcdir which we want to
1588 # umount later so step aside
1592 echo "SPECFILE='${SPECFILE//"'"/$Q}'" > $BUILD_ROOT/.build/build.data
1593 echo "BUILD_JOBS='${BUILD_JOBS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1594 echo "BUILD_ARCH='${BUILD_ARCH//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1595 echo "BUILD_RPMS='${BUILD_RPMS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1598 cp $BUILD_DIST $BUILD_ROOT/.build/build.dist
1599 BUILD_DIST=/.build/build.dist
1602 echo "BUILD_DIST='${BUILD_DIST//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1603 echo "RELEASE='${RELEASE//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1604 echo "BUILD_DEBUG='${BUILD_DEBUG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1605 echo "SIGNDUMMY='${SIGNDUMMY//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1606 echo "DO_LINT='${DO_LINT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1607 echo "DO_CHECKS='${DO_CHECKS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1608 echo "NOROOTFORBUILD='${NOROOTFORBUILD//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1609 echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
1610 echo "REASON='${REASON//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1611 echo "CHANGELOG='${CHANGELOG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1612 echo "INCARNATION='${INCARNATION//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1613 echo "DISTURL='${DISTURL//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1614 echo "DO_INIT='${DO_INIT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1615 # FIXME: this depends on the kernel and vm.
1616 # could be hda2, sda2 for xen or hdb/sdb for qemu
1617 test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV:-/dev/hda2}'" >> $BUILD_ROOT/.build/build.data
1618 test -n "$VMDISK_MOUNT_OPTIONS" && echo "VMDISK_MOUNT_OPTIONS='${VMDISK_MOUNT_OPTIONS}'" >> $BUILD_ROOT/.build/build.data
1620 if test "$VM_TYPE" != 'lxc'; then
1621 test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
1623 if test "$(uname -m)" = 'ppc'; then
1624 # ppc kernel never tells us if a 32bit personality is active
1627 echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
1628 echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
1629 echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
1630 shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
1631 echo ")" >> $BUILD_ROOT/.build/build.data
1632 echo -n "repos=(" >> $BUILD_ROOT/.build/build.data
1633 shellquote "${repos[@]}" >> $BUILD_ROOT/.build/build.data
1634 echo ")" >> $BUILD_ROOT/.build/build.data
1635 echo "VM_TYPE='$VM_TYPE'" >> $BUILD_ROOT/.build/build.data
1636 echo "shell='$shell'" >> $BUILD_ROOT/.build/build.data
1637 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
1638 umount -n $BUILD_ROOT/proc 2> /dev/null || true
1639 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
1640 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
1642 if [ -n "$VM_IMAGE" ]; then
1644 # needs to work otherwise we have a corrupted file system
1645 umount $BUILD_ROOT || cleanup_and_exit 1
1648 if check_use_emulator; then
1649 if [ -x "$BUILD_DIR/initvm" -a -e "$BUILD_DIR/qemu-reg" ]; then
1650 vm_init_script="/.build/initvm"
1651 elif [ -e $BUILD_DIR/initscript_qemu_vm ]; then
1652 vm_init_script="/.build/initscript_qemu_vm"
1654 echo "Warning: can't find initscript to register binfmts"
1657 vm_init_script="/.build/build"
1660 if [ "$VM_TYPE" = 'xen' ]; then
1661 XMROOT="file:$(readlink -f $VM_IMAGE)"
1662 XMROOT=${XMROOT/#file:\/dev/phy:/dev}
1663 XMROOT="disk=$XMROOT,hda1,w"
1665 if test -n "$VM_SWAP" ; then
1666 XMSWAP="file:$(readlink -f $VM_SWAP)"
1667 XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
1668 XMSWAP="disk=$XMSWAP,hda2,w"
1670 XENID="${VM_IMAGE%/root}"
1671 XENID="${XENID%/tmpfs}"
1672 XENID="${XENID##*/}"
1673 XENID="${XENID#root_}"
1675 echo "booting XEN kernel ..."
1676 if xm list "build_$XENID" >/dev/null 2>&1 ; then
1677 echo "Instance already exist, something really went wrong..."
1678 echo "Please report to your server admin, there might be multiple services running for same domain"
1681 XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
1682 echo "kernel = \"$vm_kernel\"" > $XEN_CONF_FILE
1683 echo "ramdisk = \"$vm_initrd\"" >> $XEN_CONF_FILE
1684 echo "memory = ${MEMSIZE:-64}" >> $XEN_CONF_FILE
1685 echo "vcpus = $BUILD_JOBS" >> $XEN_CONF_FILE
1686 echo "root = \"/dev/hda1 ro\"" >> $XEN_CONF_FILE
1687 echo "extra = \"init=/bin/bash console=ttyS0 panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
1688 echo "on_poweroff = 'destroy'" >> $XEN_CONF_FILE
1689 echo "on_reboot = 'destroy'" >> $XEN_CONF_FILE
1690 echo "on_crash = 'destroy'" >> $XEN_CONF_FILE
1691 set -- xm create -c $XEN_CONF_FILE name="build_$XENID" $XMROOT $XMSWAP extra="quiet init="$vm_init_script" elevator=noop panic=1 console=ttyS0"
1692 if test "$PERSONALITY" != 0 ; then
1693 # have to switch back to PER_LINUX to make xm work
1697 "$@" || cleanup_and_exit 3
1699 elif [ "$VM_TYPE" = 'uml' ]; then
1700 echo "booting UML kernel ..."
1701 set -- $uml_kernel initrd=$uml_initrd root=/ubda init="$vm_init_script" panic=1 elevator=noop quiet ubd0=$VM_IMAGE ${MEMSIZE:+mem=$MEMSIZE}
1704 elif [ "$VM_TYPE" = 'qemu' -o "$VM_TYPE" = 'kvm' ]; then
1705 echo "booting $VM_TYPE ..."
1706 if [ "$VM_TYPE" = 'kvm' -a -b "$VM_IMAGE" ]; then
1707 # speed optimization when using kvm with raw devices
1710 # speed optimization when using kvm with raw files
1711 CACHE=",cache=unsafe"
1713 if [ "$kvm_virtio" = 1 ]; then
1714 qemu_args=(-drive file="$VM_IMAGE",if=virtio$CACHE -drive file="$VM_IMAGE",if=ide,index=0$CACHE)
1715 if [ -n "$VM_SWAP" ]; then
1716 qemu_args=("${qemu_args[@]}" "-drive")
1717 qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=virtio$CACHE")
1720 if [ "$HOST_ARCH" = "ppc" ];then
1721 qemu_args=( "-drive" )
1722 qemu_args=("${qemu_args[@]}" "file=$VM_IMAGE,if=scsi,cache=unsafe")
1724 qemu_args=(-hda "$VM_IMAGE")
1726 if [ -n "$VM_SWAP" ]; then
1727 qemu_args=("${qemu_args[@]}" "-drive")
1728 if [ "$HOST_ARCH" = "ppc" ];then
1733 qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=$DISK_IF,index=1$CACHE")
1736 if [ -n "$BUILD_JOBS" -a "$icecream" = 0 ]; then
1737 qemu_args=("${qemu_args[@]}" "-smp" "$BUILD_JOBS")
1739 # cpuid is not set correctly in kvm without this
1740 if [ "$HOST_ARCH" != "ppc" ]; then
1743 if [ "$VM_TYPE" = 'kvm' ]; then
1744 KVM_OPTIONS="$KVM_OPTIONS -cpu host"
1745 if [ -n "$HUGETLBFSPATH" ]; then
1746 KVM_OPTIONS="$KVM_OPTIONS -mem-path $HUGETLBFSPATH"
1750 set -- $qemu_bin -no-reboot -nographic -net none $KVM_OPTIONS \
1751 -kernel $vm_kernel \
1752 -initrd $vm_initrd \
1753 -append "root=$qemu_rootdev panic=1 quiet no-kvmclock nmi_watchdog=0 rw elevator=noop console=$console init=$vm_init_script" \
1754 ${MEMSIZE:+-m $MEMSIZE} \
1757 if test "$PERSONALITY" != 0 ; then
1758 # have to switch back to PER_LINUX to make qemu work
1763 elif [ "$VM_TYPE" = 'lxc' ]; then
1764 echo "booting $VM_TYPE ..."
1765 LXCCONF="$BUILD_ROOT/.build.lxc.conf"
1767 cat $BUILD_DIR/lxc.conf > "$LXCCONF"
1768 cat >> "$LXCCONF" <<-EOF
1769 lxc.rootfs = $BUILD_ROOT
1771 # XXX: do this always instead of leaking the hosts' one?
1772 echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
1773 LXCID=${BUILD_ROOT##*/}
1774 lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
1775 lxc-create -n "$LXCID" -f "$LXCCONF" || cleanup_and_exit 1
1776 lxc-start -n "$LXCID" "$vm_init_script"
1778 test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
1779 cleanup_and_exit "$BUILDSTATUS"
1781 if test -n "$VM_SWAP" ; then
1782 BUILDSTATUS=`dd if="$VM_SWAP" bs=12 count=1 2>/dev/null`
1783 case $BUILDSTATUS in
1785 mkdir -p $BUILD_ROOT/.build.packages
1786 cd $BUILD_ROOT/.build.packages || cleanup_and_exit 1
1787 echo "build: extracting built packages..."
1788 extractbuild --disk "$VM_IMAGE" --input "$VM_SWAP" --skip 512 -v || cleanup_and_exit 3
1789 # create same layout as with plain chroot
1790 if test "$BUILDTYPE" = spec ; then
1792 for i in *src.rpm *.desktopfiles ; do
1793 test -e "$i" || continue
1797 test -e "$i" || continue
1804 elif test "$BUILDTYPE" = dsc ; then
1806 find . -type f | while read i; do mv "$i" DEBS/; done
1807 elif test "$BUILDTYPE" = arch ; then
1809 find . -type f | while read i; do mv "$i" ARCHPKGS/; done
1810 elif test "$BUILDTYPE" = kiwi ; then
1812 find . -type f | while read i; do mv "$i" KIWI/; done
1815 test -f "$i" || continue
1818 *) mkdir -p OTHER ; mv $i OTHER/ ;;
1821 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1824 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1827 echo "No buildstatus set, either the base system is broken (glibc/bash/perl)"
1828 echo "or the build host has a kernel or hardware problem..."
1837 if test "$DO_INIT" = true ; then
1839 # create legacy .buildenv file
1841 test -z "$INCARNATION" && INCARNATION=0
1842 echo "BUILD_INCARNATION=$INCARNATION" > $BUILD_ROOT/.buildenv
1843 CREATE_BUILD_BINARIES=
1844 test "$BUILDTYPE" = preinstallimage && mkdir -p $BUILD_ROOT/.preinstall_image
1845 egrep '^#[ ]*needsbinariesforbuild[ ]*$' >/dev/null <$MYSRCDIR/$SPECFILE && CREATE_BUILD_BINARIES=--create-build-binaries
1846 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
1848 "$@" || cleanup_and_exit 1
1850 # arbitrary limit of 10MB
1851 if test $((`stat -f -c "%a*%S/1024/1024" $BUILD_ROOT`)) -lt 10; then
1852 # ensure that old stat is not failing (RHEL4)
1853 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
1855 echo "build does not work on a completely full filesystem"
1859 mount -n -tproc none $BUILD_ROOT/proc || true
1860 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1865 if test "$BUILDTYPE" = preinstallimage ; then
1866 echo "creating preinstall image..."
1867 test -d "$BUILD_ROOT/.preinstall_image" || cleanup_and_exit 1
1868 cd $BUILD_ROOT || cleanup_and_exit 1
1870 if test -x /usr/bin/bsdtar; then
1871 TAR="/usr/bin/bsdtar --chroot"
1874 for DIR in .* * ; do
1877 .build*) continue ;;
1878 .preinstallimage*) continue ;;
1879 .srcfiles*) continue ;;
1881 .rpm-cache) continue ;;
1882 installed-pkg) continue ;;
1883 proc|sys) continue ;;
1885 TOPDIRS="$TOPDIRS $DIR"
1887 if ! $TAR -czf .preinstallimage.$$.tar.gz --one-file-system $TOPDIRS ; then
1890 echo "image created."
1891 TOPDIR=/usr/src/packages
1892 mkdir -p $BUILD_ROOT$TOPDIR/OTHER
1893 rm -f $BUILD_ROOT$TOPDIR/OTHER/preinstallimage.info
1894 for PKG in $BUILD_ROOT/.preinstall_image/* ; do
1896 read PKG_HDRMD5 PKGID < $BUILD_ROOT/.preinstall_image/$PKG
1897 test -n "$PKG_HDRMD5" || cleanup_and_exit 1
1898 echo "$PKG_HDRMD5 $PKG" >> $BUILD_ROOT$TOPDIR/OTHER/preinstallimage.info
1900 mv $BUILD_ROOT/.preinstallimage.$$.tar.gz $BUILD_ROOT$TOPDIR/OTHER/preinstallimage.tar.gz
1901 rm -f $BUILD_ROOT/.build.packages
1902 ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
1903 test -d "$SRCDIR" && cd "$SRCDIR"
1907 if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
1908 read BUILD_DIST < $BUILD_ROOT/.guessed_dist
1912 # fix rpmrc if we are compiling for i686
1914 test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
1915 if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
1916 mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
1917 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
1921 # install dummy sign program if needed
1923 test -f $BUILD_ROOT/usr/bin/sign_installed && mv $BUILD_ROOT/usr/bin/sign_installed $BUILD_ROOT/usr/bin/sign
1924 if test -n "$SIGNDUMMY" ; then
1925 test -f $BUILD_ROOT/usr/bin/sign && mv $BUILD_ROOT/usr/bin/sign $BUILD_ROOT/usr/bin/sign_installed
1926 cp $BUILD_DIR/signdummy $BUILD_ROOT/usr/bin/sign
1927 chmod 755 $BUILD_ROOT/usr/bin/sign
1931 # check if we want to build with the abuild user
1934 if test -x $BUILD_ROOT/bin/rpm ; then
1935 SUSE_VERSION=`chroot $BUILD_ROOT /bin/rpm --eval '%{?suse_version}' 2>/dev/null`
1936 if test -n "$SUSE_VERSION" && test "$SUSE_VERSION" -le 1020 ; then
1940 if test "$BUILD_USER" = abuild ; then
1941 egrep '^#[ ]*needsrootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=root
1943 egrep '^#[ ]*norootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=abuild
1945 test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
1947 # appliance builds must run as root
1948 if test "$BUILDTYPE" = kiwi; then
1949 imagetype=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $SPECFILE imagetype)
1950 test "$imagetype" = 'product' || BUILD_USER=root
1953 if test $BUILD_USER = abuild ; then
1954 if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1955 echo "abuild:x:${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_ROOT/etc/passwd
1956 echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed on Mandriva 2009
1957 echo 'abuild:*::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu
1958 echo "abuild:x:${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
1959 mkdir -p $BUILD_ROOT/home/abuild
1960 chown "$ABUILD_UID:$ABUILD_GID" $BUILD_ROOT/home/abuild
1962 if ! egrep "^abuild:x?:${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_ROOT/etc/passwd ; then
1963 echo "abuild user present in the buildroot ($BUILD_ROOT) but uid:gid does not match"
1964 echo "buildroot currently using:"
1965 egrep "^abuild:" <$BUILD_ROOT/etc/passwd
1966 echo "build script attempting to use:"
1967 echo "abuild::${ABUILD_UID}:${ABUILD_GID}:..."
1968 echo "build aborting"
1972 if test -f $BUILD_ROOT/etc/shadow ; then
1973 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
1975 if test -f $BUILD_ROOT/etc/gshadow ; then
1976 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/gshadow > $BUILD_ROOT/etc/gshadow.t && mv $BUILD_ROOT/etc/gshadow.t $BUILD_ROOT/etc/gshadow
1978 BUILD_USER_ABUILD_USED=true
1983 if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1984 rm -rf "$BUILD_ROOT/home/abuild"
1985 egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
1986 mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd
1987 egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new
1988 mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group
1989 if test -f $BUILD_ROOT/etc/shadow ; then
1990 egrep -v '^abuild:' <$BUILD_ROOT/etc/shadow >$BUILD_ROOT/etc/shadow.new
1991 mv $BUILD_ROOT/etc/shadow.new $BUILD_ROOT/etc/shadow
1993 if test -f $BUILD_ROOT/etc/gshadow ; then
1994 egrep -v '^abuild:' <$BUILD_ROOT/etc/gshadow >$BUILD_ROOT/etc/gshadow.new
1995 mv $BUILD_ROOT/etc/gshadow.new $BUILD_ROOT/etc/gshadow
2000 if test "$BUILDTYPE" = spec ; then
2001 TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER`
2002 if test -z "$TOPDIR"; then
2003 echo "Error: TOPDIR empty"
2007 TOPDIR=/usr/src/packages
2008 mkdir -p $BUILD_ROOT$TOPDIR
2011 rm -f $BUILD_ROOT/.build.packages
2012 ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
2014 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
2015 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
2021 # nasty hack to prevent rpath on known paths
2022 # FIXME: do this only for suse
2023 if test -d "$BUILD_ROOT/etc/profile.d" ; then
2024 echo "export SUSE_IGNORED_RPATHS=/etc/ld.so.conf" > "$BUILD_ROOT/etc/profile.d/buildsystem.sh"
2028 # now clean up RPM building directories
2030 rm -rf "$BUILD_ROOT$TOPDIR"
2031 for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT OTHER ; do
2032 mkdir -p $BUILD_ROOT$TOPDIR/$i
2034 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
2037 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
2038 if test "$BUILDTYPE" = kiwi ; then
2039 mkdir -p $BUILD_ROOT$TOPDIR/KIWI
2040 if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
2041 mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
2043 if test -z "$LINKSOURCES" ; then
2044 cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
2046 cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
2048 if test "$?" != 0 ; then
2049 echo "source copy failed"
2054 cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
2056 # strip prefix from autogenerated files of source services.
2057 for i in $BUILD_ROOT$TOPDIR/SOURCES/_service\:*; do
2058 mv "$i" "${i%/*}/${i##*:}"
2060 SPECFILE="${SPECFILE##*:}"
2062 test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
2064 test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
2066 if test "$BUILDTYPE" = spec ; then
2067 # do buildrequires/release substitution
2069 if test -n "$RELEASE"; then
2070 args=(--release "$RELEASE")
2072 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
2073 # extract macros from configuration
2074 getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" > $BUILD_ROOT/root/.rpmmacros
2075 if test -n "$BUILD_DEBUG" ; then
2077 %prep %{?!__debug_package:%{?_build_create_debug:%?_build_insert_debug_package}}%%prep
2078 %package %{?!__debug_package:%{?_build_create_debug:%?_build_insert_debug_package}}%%package
2079 %_build_insert_debug_package \
2080 %global __debug_package 1 \
2081 %undefine _enable_debug_packages \
2084 ' >> $BUILD_ROOT/root/.rpmmacros
2087 if [ -n "$BUILD_JOBS" ]; then
2088 cat >> $BUILD_ROOT/root/.rpmmacros <<-EOF
2090 %_smp_mflags -j$BUILD_JOBS
2093 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
2094 # extract optflags from configuration
2095 getoptflags --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_ROOT/root/.rpmrc
2096 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
2097 if test -z "$ABUILD_TARGET"; then
2098 ABUILD_TARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" )
2099 test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
2102 if test -f $BUILD_ROOT/.spec.new ; then
2103 if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
2104 echo -----------------------------------------------------------------
2105 echo "I have the following modifications for $SPECFILE:"
2106 sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE > $BUILD_ROOT/.spec.t1
2107 sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2
2108 diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
2109 rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
2110 mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE
2112 rm -f $BUILD_ROOT/.spec.new
2116 if test "$BUILDTYPE" = dsc ; then
2117 rm -rf "$BUILD_ROOT$TOPDIR/BUILD"
2118 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
2119 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
2121 DEB_SOURCEDIR=$TOPDIR/SOURCES
2122 DEB_DSCFILE=$SPECFILE
2123 for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
2124 test -f $f && DEB_TRANSFORM=true
2126 if test -n "$DEB_TRANSFORM" ; then
2127 echo "running debian transformer..."
2128 if ! debtransform $CHANGELOGARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
2129 echo "debian transforming failed."
2132 DEB_SOURCEDIR=$TOPDIR/SOURCES.DEB
2133 for DEB_DSCFILE in $BUILD_ROOT/$DEB_SOURCEDIR/*.dsc ; do : ; done
2134 DEB_DSCFILE="${DEB_DSCFILE##*/}"
2136 chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
2139 if test "$BUILDTYPE" = arch ; then
2140 echo "Preparing sources..."
2141 chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES && makepkg -s -o 2>&1 >/dev/null" - $BUILD_USER
2142 mv $BUILD_ROOT/$TOPDIR/SOURCES/* -t $BUILD_ROOT/$TOPDIR/BUILD
2145 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
2146 cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
2148 echo -----------------------------------------------------------------
2149 if test "$BUILD_USER" = root ; then
2150 echo ----- building $SPECFILE
2152 echo ----- building $SPECFILE "(user $BUILD_USER)"
2154 echo -----------------------------------------------------------------
2155 echo -----------------------------------------------------------------
2156 if [ -n "$RUNNING_IN_VM" ]; then
2157 if [ -x /sbin/ip ]; then
2158 ip addr add 127.0.0.1/8 dev lo
2161 ifconfig lo 127.0.0.1 up
2163 if [ -n "$MYHOSTNAME" ]; then
2164 hostname "$MYHOSTNAME"
2168 BUILD_SUCCEEDED=false
2170 if test -n "$OVERLAY" ; then
2171 if test -d "$OVERLAY"; then
2173 echo "Copying overlay to BUILD_ROOT"
2174 tar -cpf - . | (cd $BUILD_ROOT ; tar -xvf -)
2177 echo "OVERLAY ($OVERLAY) is no directory - skipping"
2181 if test -n "$RSYNCSRC" ; then
2182 if test -n "$RSYNCDEST"; then
2183 if test -d "$RSYNCSRC"; then
2184 if ! test -d "$BUILD_ROOT/$RSYNCDEST"; then
2185 echo "ATTENTION! Creating target directory ($BUILD_ROOT/$RSYNCDEST) as its not there."
2186 mkdir -p $BUILD_ROOT/$RSYNCDEST
2188 echo "Running rsync ..."
2189 rsync -av $RSYNCSRC/* $BUILD_ROOT/$RSYNCDEST/
2190 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/$RSYNCDEST"
2194 echo "RSYNCSRC is no directory - skipping"
2197 echo "RSYNCSRC given, but not RSYNCDEST - skipping"
2201 if test "$BUILDTYPE" = spec ; then
2202 test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
2205 test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
2207 # XXX: move _srcdefattr to macro file?
2208 rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--define" "_srcdefattr (-,root,root)")
2209 if test "$rpmbuild" == "rpmbuild" ; then
2210 # use only --nosignature for rpm v4
2211 rpmbopts[${#rpmbopts[@]}]="--nosignature"
2213 if test -n "$ABUILD_TARGET" ; then
2214 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
2216 if test -n "$BUILD_DEBUG" ; then
2217 rpmbopts[${#rpmbopts[@]}]='--define'
2218 rpmbopts[${#rpmbopts[@]}]="_build_create_debug 1"
2220 if test -n "$DISTURL" ; then
2221 rpmbopts[${#rpmbopts[@]}]='--define'
2222 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
2224 if test -n "$RSYNCDONE" ; then
2225 rpmbopts[${#rpmbopts[@]}]='--define'
2226 rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
2229 # su involves a shell which would require even more
2230 # complicated quoting to bypass than this
2231 toshellscript $rpmbuild \
2232 "${definesnstuff[@]}" \
2234 "$TOPDIR/SOURCES/$SPECFILE" \
2235 > $BUILD_ROOT/.build.command
2236 chmod 755 $BUILD_ROOT/.build.command
2238 if test -n "$shell"; then
2239 chroot $BUILD_ROOT su -
2241 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2245 if test "$BUILDTYPE" = dsc ; then
2246 # Checks to see if a build script should be used
2247 # this allows the build environment to be manipulated
2248 # and alternate build commands can be used
2249 # Debian policy requires to build with single CPU by default
2250 # if [ -n "$BUILD_JOBS" ]; then
2251 # DSC_BUILD_JOBS="-j$BUILD_JOBS"
2253 DSC_BUILD_CMD="dpkg-buildpackage -us -uc -rfakeroot-tcp $DSC_BUILD_JOBS"
2254 if test -e $BUILD_ROOT/$TOPDIR/SOURCES/build.script ; then
2255 echo "Sourcing build.script to build - it should normally run 'dpkg-buildpackage -us -uc -rfakeroot-tcp'"
2256 DSC_BUILD_CMD="source $TOPDIR/SOURCES/build.script"
2257 chmod +x $BUILD_ROOT/$TOPDIR/SOURCES/build.script
2260 if test -n "$shell"; then
2261 chroot $BUILD_ROOT su -
2263 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && $DSC_BUILD_CMD" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2266 mkdir -p $BUILD_ROOT/$TOPDIR/DEBS
2267 for DEB in $BUILD_ROOT/$TOPDIR/*.deb ; do
2268 test -e "$DEB" && mv "$DEB" "$BUILD_ROOT/$TOPDIR/DEBS"
2271 ln $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE $BUILD_ROOT/$TOPDIR/DEBS/
2273 ln $BUILD_ROOT/$DEB_SOURCEDIR/$f $BUILD_ROOT/$TOPDIR/DEBS/
2274 done < <(sed -ne '/^Files:/,$s/^ ................................ [0-9][0-9]* //p' < $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE)
2277 if test "$BUILDTYPE" = arch ; then
2278 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && makepkg -f" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
2279 mkdir -p $BUILD_ROOT/$TOPDIR/ARCHPKGS
2280 for PKG in $BUILD_ROOT/$TOPDIR/BUILD/*.pkg.tar.?z ; do
2281 test -e "$PKG" && mv "$PKG" "$BUILD_ROOT/$TOPDIR/ARCHPKGS"
2285 if test "$BUILDTYPE" = kiwi ; then
2286 . $BUILD_DIR/build_kiwi.sh
2290 test "$BUILD_SUCCEEDED" = true || cleanup_and_exit 1
2291 test -d "$SRCDIR" && cd "$SRCDIR"
2294 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
2295 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
2297 if test -n "$RPMS" -a -n "$BUILD_USER_ABUILD_USED" ; then
2298 echo "... checking for files with abuild user/group"
2300 while read un gn fn ; do
2301 if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
2305 done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
2306 if test -n "$BADFILE" ; then
2307 echo "please fix your filelist (e.g. add defattr)"
2312 if test -n "$RPMS" -a -d "$BUILD_ROOT/usr/lib/build/checks" ; then
2314 export DO_RPM_REMOVE=true
2315 for SRPM in $BUILD_ROOT/$TOPDIR/SRPMS/*src.rpm ; do
2316 test -f "$SRPM" && PNAME=`rpm --nodigest --nosignature -qp --qf "%{NAME}" $SRPM`
2318 for CHECKSCRIPT in $BUILD_ROOT/usr/lib/build/checks/* ; do
2319 echo "... running `basename $CHECKSCRIPT`"
2320 $CHECKSCRIPT || cleanup_and_exit 1
2324 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
2325 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
2327 if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_ROOT/opt/testing/bin/rpmlint" ; then
2328 LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
2329 \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
2330 -o -name "*-32bit-*" -o -name "*-64bit-*" \
2331 -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
2332 -o -type f -name '*.rpm' -print))
2333 SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
2335 echo "RPMLINT report:"
2336 echo "==============="
2337 rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log
2338 rm -f "$BUILD_ROOT$rpmlint_logfile"
2340 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
2341 chroot $BUILD_ROOT su -s /opt/testing/bin/rpmlint "$BUILD_USER" -- \
2342 --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} \
2343 ${SRPM_FILE_LIST[*]#$BUILD_ROOT} > "$BUILD_ROOT$rpmlint_logfile" || ret=1
2344 cat "$BUILD_ROOT$rpmlint_logfile"
2346 umount -n $BUILD_ROOT/proc 2>/dev/null || true
2347 if test "$ret" = 1; then
2352 if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS"; then
2357 # post build scripts
2358 # TODO: don't hardcode. instead run scripts in a directory as it's done for the checks
2359 if test -n "$RPMS" \
2360 -a -d "$BUILD_ROOT/$TOPDIR/RPMS" \
2361 -a -d "$BUILD_ROOT/.build.oldpackages" \
2363 if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
2364 echo "... comparing built packages with the former built"
2365 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
2366 if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
2367 chroot $BUILD_ROOT touch /.build/.same_result_marker
2368 # XXX: dirty build service hack. fix bs_worker. Search for
2369 # 'same_result_marker' for traces of a first try to get rid of this
2370 if test -n "$REASON" -a -n "$DISTURL"; then
2375 if test ! -e $BUILD_ROOT/.build/.same_result_marker \
2376 -a -x "$BUILD_ROOT/usr/bin/makedeltarpm" \
2377 -a -x $BUILD_ROOT/usr/lib/build/mkdrpms; then
2378 echo "... creating delta rpms"
2379 ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS")
2380 chroot $BUILD_ROOT /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}"
2384 if test -n "$RUNNING_IN_VM" -a -n "$VM_SWAP"; then
2385 echo "... saving built statistics"
2386 echo "# statistics about used resources during build" > $TOPDIR/OTHER/_statistics
2387 if [ -e /.build/_statistics.df ]; then
2388 echo -n "MAX_mb_used_on_disk: " >> $TOPDIR/OTHER/_statistics
2389 cat /.build/_statistics.df >> $TOPDIR/OTHER/_statistics
2390 rm /.build/_statistics.df
2392 if [ -e /.build/_statistics.memory ]; then
2393 echo -n "MAX_mb_used_memory: " >> $TOPDIR/OTHER/_statistics
2394 cat /.build/_statistics.memory >> $TOPDIR/OTHER/_statistics
2395 rm /.build/_statistics.memory
2397 mount -n sys /sys -t sysfs
2399 [ -e /dev/vda ] && device="vda"
2400 disk=(`cat /sys/block/${device}/stat`)
2401 echo "IO_requests_read: ${disk[0]}" >> $TOPDIR/OTHER/_statistics
2402 echo "IO_sectors_read: ${disk[2]}" >> $TOPDIR/OTHER/_statistics
2403 echo "IO_requests_write: ${disk[4]}" >> $TOPDIR/OTHER/_statistics
2404 echo "IO_sectors_write: ${disk[6]}" >> $TOPDIR/OTHER/_statistics
2407 echo "... saving built packages"
2409 args="--padstart 512 --padend 512 -v"
2410 case "$BUILDTYPE" in
2412 computeblocklists $args $TOPDIR/RPMS/*/*.{d,}rpm $TOPDIR/SRPMS/* $TOPDIR/OTHER/* > "$VM_SWAP"
2415 computeblocklists $args $TOPDIR/DEBS/*.deb $TOPDIR/SOURCES.DEB/* $TOPDIR/OTHER/* > "$VM_SWAP"
2418 computeblocklists $args $TOPDIR/KIWI/* $TOPDIR/OTHER/* > "$VM_SWAP"
2421 computeblocklists $args $TOPDIR/ARCHPKGS/* $TOPDIR/OTHER/* > "$VM_SWAP"
2424 computeblocklists $args $TOPDIR/OTHER/* > "$VM_SWAP"
2429 esac || cleanup_and_exit 1
2433 echo "$HOST finished \"build $SPECFILE\" at `date --utc`."
2436 cleanup_and_exit "$exitcode"