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
20 # mkreiserfs only works with qemu/uml if it is able to create a file
21 # system that is owned by the calling user (bnc#369006)
22 #vm_img_mkfs='mkreiserfs -q -f'
23 #vm_img_mkfs='mkfs.ext2 -m 0 -q -F'
24 vm_img_mkfs='mkfs.ext3 -m 0 -q -F'
25 vm_img_tunefs='tune2fs -c 0'
26 qemu_kernel=/boot/vmlinuz
27 qemu_initrd=/boot/initrd
28 qemu_bin=/usr/bin/qemu
29 uml_kernel=/boot/vmlinux-um
30 uml_initrd=/boot/initrd-um
32 kvm_kernel=/boot/vmlinuz-kvm
33 kvm_initrd=/boot/initrd-kvm
34 kvm_bin=/usr/bin/qemu-kvm
35 mkinitrd_virtio_cmd=(env rootfstype=ext3 mkinitrd -d /dev/null -m "binfmt_misc virtio_pci virtio_blk" -k $kvm_kernel -i ${kvm_initrd}-virtio)
36 # whether we have virtio support
40 # Default uid:gid for the build user
84 export YAST_IS_RUNNING=instsys
94 Some comments for build
95 -----------------------
97 With build you can create rpm packages. They will be built in a chroot
98 system. This chroot system will be setup automatically. Normally you can
99 simply call build with a spec file as parameter - nothing else has to be
102 If you want to set the directory were the chroot system will be setup
103 (at the moment it uses $BUILD_ROOT),
104 simply set the the environment variable BUILD_ROOT.
108 export BUILD_ROOT=/var/tmp/mybuildroot
111 Normally build builds the complete package including src.rpm (rpmbuild -ba).
112 If you want let build only make the binary package, simply set
114 export BUILD_RPM_BUILD_STAGE=-bb
116 (or -bc, -bp, -bi, ... see "Maximum RPM" for more details [*]).
118 When the build command succeeds, the rpm files can be found under
119 $BUILD_ROOT/usr/src/packages/RPMS/
124 --help You already got it :)
126 --clean Delete old build root before initializing it
128 --no-init Skip initialization of build root and start with build
131 --no-checks Do not run post-build checks
134 Use package repository at PATH. Supported formats are
136 Alternatively zypp://NAME specifies the zypp
137 repository NAME. The repo must be refreshed with zypp
138 so package meta data is available locally. With emtpy
139 NAME all enabled repositories are used.
141 --rpms path1:path2:...
142 Specify path where to find the RPMs for the build system
144 --arch arch1:arch2:...
145 Specify what architectures to select from the RPMs
147 --verify Run verify when initializing the build root
150 Also install package 'pack'
153 Use 'rootdir' to setup chroot environment
155 --oldpackages oldpackagesdir
156 Define a directory with a former build
158 --baselibs Create -32bit/-64bit/-x86 rpms for other architectures
161 List rpms that would be used to create a fresh build root.
162 Does not create the build root or perform a build.
165 enable feature X for build
168 disable feature X for build
171 define macro X with value Y
174 use ccache to speed up rebuilds
177 use N parallel build jobs with icecream
179 Copy overlay filesystem to buildroot after installing
180 all RPMs. This must be a valid directory.
183 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
184 inside the buildroot using rsync.
185 It will "%define RSYNCDONE 1" for handling %setup in your
189 %setup -n aaa_base -T -D -b 5 -b 7
191 %setup -n aaa_base -b 5 -b 7
194 --rsync-dest RSYNCDEST
195 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
196 inside the buildroot using rsync.
199 Specify the uid and gid to use for the abuild user.
200 This is useful if you are hacking in the buildroot.
201 This must be set to the same value if the buildroot is re-used.
204 --vmdisk-rootsize <size in MB>
205 --vmdisk-swapsize <size in MB>
206 --vmdisk-filesystem <ext3|ext4>
207 --vmdisk-force [forces (re-)setup]
208 Enable automatic setup of VM root/swap files
212 Kernel and initrd to use for VM build.
215 enable creation of a debuginfo package
217 Remember to have fun!
219 [*] Maximum RPM: http://www.rpm.org/max-rpm/
223 echo "Usage: `basename $0` [--no-init|--clean|--rpms path|--verify|--help] [dir-to-build|spec-to-build]"
229 # return values: 0 -> success, new packages built
230 # 1 -> error, build failed
231 # 2 -> successfull build, but no changes to former built packages
232 # 3 -> something wrong with build host
234 cleanup_and_exit () {
236 test -z "$1" && set 0
237 if test -n "$RUNNING_IN_VM" ; then
239 if test -n "$VM_SWAP" -a -e "$VM_SWAP" ; then
240 swapoff "$VM_SWAP" 2>/dev/null
241 echo -n "BUILDSTATUS$1" >"$VM_SWAP"
243 exec >&0 2>&0 # so that the logging tee finishes
244 sleep 1 # wait till tee terminates
245 if test "$VM_TYPE" != lxc; then
246 kill -9 -1 # goodbye cruel world
247 if ! test -x /sbin/halt ; then
248 mount -n -tproc none /proc
250 sleep 2 # like halt does
251 test -e /proc/sysrq-trigger && echo o > /proc/sysrq-trigger
256 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
257 umount -n $BUILD_ROOT/proc 2>/dev/null || true
258 umount -n $BUILD_ROOT/dev/pts 2>/dev/null || true
259 test "$VM_IMAGE" = 1 && VM_IMAGE=
260 [ -n "$VM_IMAGE" ] && umount $BUILD_ROOT 2>/dev/null || true
262 # echo "pid $$ exit $1"
282 # create a shell script from command line. Used for preserving arguments
294 if [ "$ccache" = 1 ]; then
295 if mkdir -p $BUILD_ROOT/var/lib/build/ccache/bin; then
296 for i in gcc g++ cc c++; do
297 # ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
298 rm -f $BUILD_ROOT/var/lib/build/ccache/bin/$i
299 test -e $BUILD_ROOT/usr/bin/$i || continue
300 echo '#! /bin/sh' > $BUILD_ROOT/var/lib/build/ccache/bin/$i
301 echo "test -e /usr/bin/$i || exit 1" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
302 echo 'export PATH=/opt/icecream/bin:/usr/bin:$PATH' >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
303 echo "ccache $i \"\$@\"" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
304 chmod 755 $BUILD_ROOT/var/lib/build/ccache/bin/$i
305 echo "Installed ccache wrapper as $BUILD_ROOT/var/lib/build/ccache/bin/$i"
308 mkdir -p "$BUILD_ROOT"/.ccache
309 chroot "$BUILD_ROOT" chown -R "$BUILD_USER" "/.ccache"
310 echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
311 echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
313 rm -f "$BUILD_ROOT$builduserhome"/bin/{gcc,g++,cc,c++}
314 rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
320 if [ "$icecream" -eq 0 ]; then
321 rm -rf "$BUILD_ROOT"/var/run/icecream
322 rm -f "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
326 if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then
327 echo "*** icecream package not installed ***"
332 echo "using icecream with $icecream jobs"
334 if [ "$ccache" -ne 1 ]; then
335 echo 'export PATH=/opt/icecream/bin:$PATH' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
337 echo 'export CCACHE_PATH=/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
340 local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
341 icecc_vers=${icecc_vers//$BUILD_ROOT/}
343 # XXX use changelog like autobuild does instead?
344 # only run create-env if compiler or glibc changed
345 if [ -z "$icecc_vers" \
346 -o ! -e "$BUILD_ROOT/$icecc_vers" \
347 -o "$BUILD_ROOT/usr/bin/gcc" -nt "$BUILD_ROOT/$icecc_vers" \
348 -o "$BUILD_ROOT/usr/bin/g++" -nt "$BUILD_ROOT/$icecc_vers" \
349 -o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
350 -o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers" ]
352 rm -rf $BUILD_ROOT/var/run/icecream
353 mkdir -p $BUILD_ROOT/var/run/icecream
354 if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
355 createenv=/usr/bin/create-env
356 elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
357 createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
358 elif [ -e "$BUILD_ROOT"/usr/lib64/icecc/icecc-create-env ]; then
359 createenv="/usr/lib64/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
361 echo "create-env not found"
365 chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv" || cleanup_and_exit 1
366 icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
367 icecc_vers=${icecc_vers//$BUILD_ROOT/}
369 echo "reusing existing icecream environment $icecc_vers"
371 if [ -n "$icecc_vers" ]; then
372 echo "export ICECC_VERSION=$icecc_vers" >> "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
378 if [ -n "$VM_IMAGE" -o -n "$RUNNING_IN_VM" ]; then
386 eval "mem=\$(($2/3*4))"
388 echo "Memory limit set to ${mem}KB"
392 done < <(cat /proc/meminfo) # cat for proc stuff
395 function create_baselibs {
396 echo "... creating baselibs"
398 for RPM in $BUILD_ROOT$TOPDIR/RPMS/*/*.rpm ; do
399 BRPMS="$BRPMS ${RPM#$BUILD_ROOT}"
402 for DEB in $BUILD_ROOT$TOPDIR/DEBS/*.deb ; do
403 BDEBS="$BDEBS ${DEB#$BUILD_ROOT}"
406 ## Nb REPO is the name of the project instance
407 ## DISTRO is the underlying (remote?) distro
408 # if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs_${REPO}.conf ; then
409 # BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs_${REPO}.conf"
410 # elif test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs_${DISTRO}.conf ; then
411 # BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs_${DISTRO}.conf"
412 # elif test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
414 if test "$BUILDTYPE" == "dsc" ; then
417 if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
418 BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
420 if test -e $BUILD_ROOT/usr/lib/build/baselibs_global.conf; then
421 BASELIBS_GLOBAL="-c /usr/lib/build/baselibs_global.conf"
425 if test -f $BUILD_ROOT/usr/lib/build/mkbaselibs ; then
426 if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
427 BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
429 echo "RUNNING internal mkbaselibs ... "
430 chroot $BUILD_ROOT su -c "/usr/lib/build/mkbaselibs -v $BASELIBS_GLOBAL $BASELIBS_CFG $BPKGS" - $BUILD_USER || cleanup_and_exit 1
432 # use external version
433 rm -rf $BUILD_ROOT/.mkbaselibs
434 mkdir -p $BUILD_ROOT/.mkbaselibs
435 cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs/
436 if test "$BUILDTYPE" == "dsc" ; then
437 cp -f $BUILD_DIR/baselibs_global-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
438 cp -f $BUILD_ROOT$TOPDIR/SOURCES/baselibs-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs-deb.conf
439 BASELIBS_CFG="-c /.mkbaselibs/baselibs-deb.conf"
441 cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
442 if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf; then
443 cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf
444 BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf"
447 if test -e $BUILD_ROOT/.mkbaselibs/baselibs_g.conf; then
448 BASELIBS_GLOBAL="-c /.mkbaselibs/baselibs_g.conf"
450 chroot $BUILD_ROOT su -c "/.mkbaselibs/mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG $BPKGS" - $BUILD_USER || cleanup_and_exit 1
451 rm -rf $BUILD_ROOT/.mkbaselibs
455 detect_vm_2nd_stage()
457 if ! test "$0" = "/.build/build" ; then
460 if test $$ -eq 1 ; then
461 # ignore special init signals if we're init
462 # we're using ' ' instead of '' so that the signal handlers
463 # are reset in the child processes
468 echo "2nd stage started in virtual machine"
471 . $BUILD_DIR/build.data
472 echo "machine type: `uname -m`"
473 if test "$PERSONALITY" != 0 -a -z "$PERSONALITY_SET" ; then
474 export PERSONALITY_SET=true
475 echo "switching personality to $PERSONALITY..."
476 # this is 32bit perl/glibc, thus the 32bit syscall number
477 exec perl -e 'syscall(136, '$PERSONALITY') == -1 && warn("personality: $!\n");exec "/.build/build" || die("/.build/build: $!\n")'
480 mount -orw -n -tproc none /proc
481 if test "$VM_TYPE" != 'lxc'; then
482 mount -n -o remount,rw /
484 # qemu inside of xen does not work, check again with kvm later before enabling this
485 # if [ -e /dev/kqemu ]; then
486 # # allow abuild user to run qemu
487 # chmod 0666 /dev/kqemu
489 if test -n "$VM_SWAP" ; then
490 for i in 1 2 3 4 5 6 7 8 9 10 ; do
491 test -e "$VM_SWAP" && break
492 test $i = 1 && echo "waiting for $VM_SWAP to appear"
497 # recreate the swap device manually if it didn't exist for some
498 # reason, hardcoded to hda2 atm
499 if ! test -b "$VM_SWAP" ; then
502 mknod "$VM_SWAP" b 3 2
505 swapon -v "$VM_SWAP" || exit 1
515 if [ -z "$SPECFILES" ]; then
518 set -- "${SPECFILES[@]}"
522 if [ "$spec" = "${spec#/}" ]; then
526 if [ -d "$spec" ]; then
527 specs=("$spec"/*.spec)
528 if [ -n "$specs" ]; then
529 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
531 specs=("$spec"/*.spec)
532 if [ -n "$specs" ]; then
533 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
537 SPECFILES[${#SPECFILES[@]}]="$spec";
541 if test -z "$SPECFILES"; then
542 echo no spec files or src rpms found in $@. exit...
547 become_root_or_fail()
549 if [ ! -w /root ]; then
550 echo "You have to be root to use $0" >&2
558 if [ -d "$BUILD_ROOT" ]; then
559 # check if it is owned by root
560 if [ -z "$RUNNING_IN_VM" -a \! -O "$BUILD_ROOT" -a "`stat -c %u $BUILD_ROOT`" -ne 0 ]; then
561 echo "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
565 test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
566 if ! mkdir $BUILD_ROOT; then
567 echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
572 rm -rf "$BUILD_ROOT"/.build.packages
573 if [ -z "$RUNNING_IN_VM" ]; then
574 # don't touch this in VM
575 rm -rf "$BUILD_ROOT"/.build
581 perl -e 'syscall('$PERSONALITY_SYSCALL', 0); exec(@ARGV) || die("$ARGV[0]: $!\n")' "$@"
588 case `perl -V:archname` in
589 *x86_64*) PERSONALITY_SYSCALL=135 ;;
590 *i?86*) PERSONALITY_SYSCALL=136 ;;
595 if detect_vm_2nd_stage ; then
596 set "/.build-srcdir/$SPECFILE"
600 export PATH=$BUILD_DIR:/sbin:/usr/sbin:$PATH
602 . $BUILD_DIR/common_functions || exit 1
606 while test -n "$1"; do
614 set -- "----noarg=$PARAM" "$@"
628 CLEAN_BUILD='--clean'
635 if [ -z "$BUILD_RPMS" ] ; then
646 export VERIFY_BUILD_SYSTEM=true
649 ABUILD_TARGET_ARCH="$ARG"
657 BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
667 CREATE_BASELIBS=internal
682 *-xen|*-kvm|--uml|--qemu)
684 if [ -n "$ARG" -a "$ARG" = "${ARG#-}" ]; then
698 *-xenmemory|*-memory)
712 VMDISK_AUTOSETUP=true
715 VMDISK_ROOTSIZE="$ARG"
719 VMDISK_SWAPSIZE="$ARG"
726 VMDISK_FILESYSTEM="$ARG"
730 RPMLIST="--rpmlist $ARG"
750 BUILD_RPM_BUILD_STAGE="$ARG"
754 USEUSEDFORBUILD="--useusedforbuild"
759 --define|--with|--without)
760 definesnstuff[${#definesnstuff[@]}]="$PARAM";
761 definesnstuff[${#definesnstuff[@]}]="$ARG";
765 if [ -z "$ARG" ] ; then
769 repos[${#repos[@]}]="$PARAM";
770 repos[${#repos[@]}]="$ARG";
774 if [ -z "$ARG" ] ; then
775 echo "--icecream needs an argument" >&2
780 if [ "$icecream" -gt 0 ]; then
803 echo "$ARG does not take an argument"
823 if test -n "${ABUILD_ID//[0-9:]/}"; then
824 echo "--uid argument must be uid:gid"
827 ABUILD_UID=${ABUILD_ID%:*}
828 ABUILD_GID=${ABUILD_ID#*:}
832 echo Unknown Option "$PARAM". Exit.
836 SPECFILES[${#SPECFILES[@]}]="$PARAM";
841 if test -n "$KILL" ; then
842 test -z "$SRCDIR" || usage
843 if test -n "$VM_IMAGE" -a -n "$VM_SWAP" -a -n "$VM_TYPE"; then
844 # mark job as failed so that we don't extract packages
845 echo -n "BUILDSTATUS1" >"$VM_SWAP"
847 (set -C; > "$BUILD_ROOT/exit" || true)
848 if test "$VM_TYPE" = 'lxc'; then
849 LXCID=${BUILD_ROOT##*/}
850 lxc-stop -n "$LXCID" || true
851 lxc-destroy -n "$LXCID"
852 elif test -z "$VM_IMAGE" ; then
853 if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
854 echo "could not kill build in $BUILD_ROOT"
857 elif test "$VM_TYPE" = 'xen'; then
858 XENID="${VM_IMAGE%/root}"
859 XENID="${XENID%/tmpfs}"
861 if xm list "build:$XENID" >/dev/null 2>&1 ; then
862 if ! xm destroy "build:$XENID" ; then
863 echo "could not kill xen build $XENID"
867 elif test -n "$VM_TYPE"; then
868 if ! fuser -k -TERM "$VM_IMAGE"; then
869 echo "could not kill build in $VM_IMAGE"
873 echo "don't know how to kill this build job"
879 if test "ext4" = "$VMDISK_FILESYSTEM"; then
880 vm_img_mkfs='mkfs.ext4 -m 0 -q -F'
882 # mkinitrd_virtio_cmd=(env rootfstype=ext4 mkinitrd -d /dev/null -m "ext4 binfmt_misc virtio_pci virtio_blk" -k $kvm_kernel -i ${kvm_initrd}-ext4-virtio)
883 # env rootfstype=ext4 mkinitrd -d /dev/null -m "ext4 binfmt_misc virtio_pci virtio_blk" -k $kvm_kernel -i ${kvm_initrd}-ext4
884 # export kvm_initrd=${kvm_initrd}-ext4
885 # export rootfstype="rootfstype=ext4"
888 if [ "$VM_TYPE" = 'kvm' -a -z "$RUNNING_IN_VM" -a -n "$VM_KERNEL" -a -n "$VM_INITRD" ] ; then
891 qemu_initrd="$VM_INITRD"
892 qemu_kernel="$VM_KERNEL"
894 qemu_rootdev=/dev/vda
896 elif [ "$VM_TYPE" = 'kvm' -a -z "$RUNNING_IN_VM" -a -f "${kvm_initrd}-build" ]; then
898 qemu_kernel="$kvm_kernel"
899 qemu_initrd="${kvm_initrd}-build"
901 qemu_rootdev=/dev/vda
903 elif [ "$VM_TYPE" = 'kvm' -a -z "$RUNNING_IN_VM" ]; then
904 if [ ! -r /dev/kvm -o ! -x "$qemu_bin"-kvm ]; then
905 echo "host doesn't support kvm"
909 qemu_kernel="$kvm_kernel"
910 qemu_initrd="$kvm_initrd"
911 if [ ! -e ${qemu_initrd}-virtio -o $qemu_kernel -nt ${qemu_initrd}-virtio ]; then
912 if [ ! -w /root ]; then
913 echo "No initrd that provides virtio support found. virtio accelleration disabled."
914 echo "Run the following command as root to enable virtio:"
915 shellquote "${mkinitrd_virtio_cmd[@]}"
917 elif /sbin/modinfo virtio_pci >/dev/null 2>&1; then
918 echo "creating $qemu_initrd-virtio"
919 "${mkinitrd_virtio_cmd[@]}" || cleanup_and_exit 1
928 if [ "$kvm_virtio" = 1 ]; then
929 qemu_initrd="${qemu_initrd}-virtio"
931 qemu_rootdev=/dev/vda
934 qemu_rootdev=/dev/sda
938 if [ "$VM_TYPE" = 'qemu' ]; then
940 qemu_rootdev=/dev/sda
943 if [ -z "$RPMLIST" ]; then
944 if [ -z "$repos" -a -z "$BUILD_RPMS" ]; then
945 repos=(--repository 'zypp://')
953 if [ -n "$CLEAN_BUILD" ]; then
959 if test -n "$LIST_STATE" ; then
960 BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
961 test -d "$BUILD_ROOT" || cleanup_and_exit 3
962 SPECFILE=$SPECFILES # only one specified anyways
963 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
964 rm -rf $BUILD_ROOT/usr/src/packages
965 mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES $BUILD_ROOT/usr/src/packages/SPECS
966 rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
967 echo "could not install $SPECFILE." 2>&1
971 for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
973 init_buildsystem --list-state "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
976 cleanup_and_exit $ERR
979 if test -z "$RUNNING_IN_VM" ; then
980 if test -n "$VM_IMAGE" ; then
981 if test "$VM_IMAGE" = 1 ; then
982 VM_IMAGE="$BUILD_ROOT.img"
984 if test -n "$VMDISK_AUTOSETUP"; then
985 if test -n "$VMDISK_ROOTSIZE" -a -n "$VMDISK_SWAPSIZE" ; then
986 if test -e "$VM_IMAGE" -a -e "$VM_SWAP" -a ! "$VMDISK_FORCE"; then
987 echo "$BUILD_ROOT and $VM_SWAP present, skipping autosetup without --vmdisk-force being set."
989 # assuming MB for size ! thus root=4096 swap=1024
992 echo "$VMDISK_ROOTSIZE"
993 echo """dd if=/dev/zero of="$VM_IMAGE" bs=1 count=1 seek=$(( ${VMDISK_ROOTSIZE} * 1024 * 1024 )) || cleanup_and_exit 3"""
994 dd if=/dev/zero of="$VM_IMAGE" bs=1 count=1 seek=$(( ${VMDISK_ROOTSIZE} * 1024 * 1024 )) || cleanup_and_exit 3
995 if test -z "$CLEAN_BUILD"; then
996 $vm_img_mkfs $VM_IMAGE || cleanup_and_exit 3
997 if test -n "$vm_img_tunefs" ; then
998 $vm_img_tunefs $VM_IMAGE || cleanup_and_exit 3
1002 dd if=/dev/zero of="$VM_SWAP" bs=1 count=1 seek=$(( ${VMDISK_SWAPSIZE} * 1024 * 1024 )) || cleanup_and_exit 3
1003 if test -z "$CLEAN_BUILD"; then
1004 mkswap "$VM_SWAP" || cleanup_and_exit 3
1008 echo "--vmdisk-autosetup used, but either --vmdisk-rootsize or --vmdisk-swapsize not set."
1010 # error, bad build(-host) setup
1013 if test ! -e "$VM_IMAGE" ; then
1014 echo "you need to create a file system on $VM_IMAGE first"
1018 if test -n "$VM_IMAGE" ; then
1019 if test -n "$CLEAN_BUILD" ; then
1020 echo "Creating filesystem on $VM_IMAGE"
1021 $vm_img_mkfs $VM_IMAGE || cleanup_and_exit 3
1022 if test -n "$vm_img_tunefs" ; then
1023 $vm_img_tunefs $VM_IMAGE || cleanup_and_exit 3
1027 if [ -w /root ]; then
1028 mount -o loop $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 3
1030 mount $BUILD_ROOT || cleanup_and_exit 3
1033 test -w /root || become_root_or_fail
1035 if test -n "$VM_SWAP" ; then
1036 dd if=/dev/zero of="$VM_SWAP" bs=12 count=1 conv=notrunc 2>/dev/null
1043 rm -f $BUILD_ROOT/exit
1045 if [ -w /root ]; then
1046 mkdir -p $BUILD_ROOT/proc
1047 mkdir -p $BUILD_ROOT/dev/pts
1048 mount -n -tproc none $BUILD_ROOT/proc || true
1049 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1052 if test -z "$VM_IMAGE" -a -z "$LOGFILE"; then
1053 LOGFILE="$BUILD_ROOT/.build.log"
1056 if test -n "$LOGFILE" ; then
1057 echo logging output to $LOGFILE...
1060 if test -n "$VM_IMAGE" ; then
1061 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
1063 exec 1> >(exec -a 'build logging tee' tee -a $LOGFILE) 2>&1
1072 test -z "$HOST" && HOST=`hostname`
1074 if [ -z "$RUNNING_IN_VM" ]; then
1075 echo Using BUILD_ROOT=$BUILD_ROOT
1076 test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
1077 echo Using BUILD_ARCH=$BUILD_ARCH
1078 test -n "$VM_TYPE" && echo "Doing $VM_TYPE build${VM_IMAGE:+ in $VM_IMAGE}"
1082 test "$BUILD_ARCH" = all && BUILD_ARCH=
1083 BUILD_USER_ABUILD_USED=
1085 for SPECFILE in "${SPECFILES[@]}" ; do
1087 SRCDIR="${SPECFILE%/*}"
1088 SPECFILE="${SPECFILE##*/}"
1092 *.spec|*.src.rpm) BUILDTYPE=spec ;;
1093 *.dsc) BUILDTYPE=dsc ;;
1094 *.kiwi) BUILDTYPE=kiwi ;;
1096 if test -z "$BUILDTYPE" ; then
1097 echo "don't know how to build $SPECFILE"
1103 if [ -z "$RUNNING_IN_VM" ]; then
1105 echo "$HOST started \"build $SPECFILE\" at `date`."
1107 test -n "$REASON" && echo "$REASON"
1112 # first setup building directory...
1114 test -s "$SPECFILE" || {
1115 echo "$SPECFILE" is empty. This should not happen...
1119 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
1120 echo processing src rpm $SRCDIR/$SPECFILE ...
1121 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1124 cd $MYSRCDIR || cleanup_and_exit 1
1125 $BUILD_DIR/unrpm -q $SRCDIR/$SPECFILE || {
1126 echo "could not install $SPECFILE."
1129 for SPECFILE in *.spec ; do : ; done
1132 # strip prefix from autogenerated files from OBS.
1133 for i in $MYSRCDIR/_service\:*; do
1136 SPECFILE="${SPECFILE##*:}"
1139 # FIX to work with baselibs_$PROJ etc
1140 if test "$BUILDTYPE" == "dsc" -a -e ${SRCDIR}/baselibs-deb.conf ; then
1141 # Set CREATE_BASELIBS if not set
1142 echo "dsc build and baselibs-deb.conf present: forcing --baselibs to true"
1143 CREATE_BASELIBS=true
1146 # Currently local osc build does not allow extra .deb packages to be
1147 # specified on the command line. Both init_buildsystem and expanddeps
1148 # need to handle .deb dependencies first
1149 # if test -n "$CREATE_BASELIBS" ; then
1150 # case $BUILDTYPE in
1152 # dsc) BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS libparse-debcontrol-perl" ;;
1156 echo processing specfile $MYSRCDIR/$SPECFILE ...
1159 test -n "$BUILD_EXTRA_PACKS" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
1160 test -n "$CREATE_BASELIBS" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
1161 test "$ccache" = '1' && ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
1162 test "$icecream" -gt 1 && ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
1163 test -n "$DO_LINT" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
1164 test -n "$OLD_PACKAGES" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS build-compare"
1166 if test -n "$CHANGELOG" -a -z "$RUNNING_IN_VM" ; then
1167 rm -f $BUILD_ROOT/.build-changelog
1169 *.dsc) CFFORMAT=debian ;;
1172 echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
1173 if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
1174 rm -f $BUILD_ROOT/.build-changelog
1178 if test -n "$VM_TYPE" -a -z "$RUNNING_IN_VM"; then
1179 rm -rf $BUILD_ROOT/.build
1180 mkdir -p $BUILD_ROOT/.build
1181 if test "$DO_INIT" = true ; then
1182 # do fist stage of init_buildsystem
1183 rm -f $BUILD_ROOT/.build.success
1184 set -- init_buildsystem --prepare "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1186 "$@" || cleanup_and_exit 1
1188 if [ ! -w /root ]; then
1189 # remove setuid bit if files belong to user to make e.g. mount work
1190 find $BUILD_ROOT/{bin,sbin,usr/bin,usr/sbin} -type f -uid $UID -perm +4000 -print0 | xargs -0 --no-run-if-empty chmod -s
1192 if [ -d "$OLD_PACKAGES" ]; then
1193 rm -rf $BUILD_ROOT/.build.oldpackages
1194 cp -a $OLD_PACKAGES $BUILD_ROOT/.build.oldpackages
1197 # start up xen, rerun ourself
1198 cp -a $BUILD_DIR/. $BUILD_ROOT/.build
1199 if ! test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1200 rm -rf $BUILD_ROOT/.build-srcdir
1201 mkdir $BUILD_ROOT/.build-srcdir
1202 if test "$BUILDTYPE" = kiwi ; then
1203 cp -pRL "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1205 cp -p "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
1207 MYSRCDIR=$BUILD_ROOT/.build-srcdir
1209 # cwd is at $BUILD_ROOT/.build-srcdir which we want to
1210 # umount later so step aside
1214 echo "SPECFILE='${SPECFILE//"'"/$Q}'" > $BUILD_ROOT/.build/build.data
1215 echo "BUILD_JOBS='${BUILD_JOBS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1216 echo "BUILD_ARCH='${BUILD_ARCH//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1217 echo "BUILD_RPMS='${BUILD_RPMS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1220 cp $BUILD_DIST $BUILD_ROOT/.build/build.dist
1221 BUILD_DIST=/.build/build.dist
1224 echo "BUILD_DIST='${BUILD_DIST//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1225 echo "RELEASE='${RELEASE//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1226 echo "BUILD_DEBUG='${BUILD_DEBUG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1227 echo "DO_LINT='${DO_LINT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1228 echo "DO_CHECKS='${DO_CHECKS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1229 echo "NOROOTFORBUILD='${NOROOTFORBUILD//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1230 echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
1231 echo "REASON='${REASON//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1232 echo "CHANGELOG='${CHANGELOG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1233 echo "INCARNATION='${INCARNATION//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1234 echo "DISTURL='${DISTURL//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1235 # FIXME: this depends on the kernel and vm.
1236 # could be hda2, sda2 for xen or hdb/sdb for qemu
1237 test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV:-/dev/hda2}'" >> $BUILD_ROOT/.build/build.data
1239 if test "$VM_TYPE" != 'lxc'; then
1240 test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
1242 echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
1243 echo "OLD_PACKAGES='$OLD_PACKAGES'" >> $BUILD_ROOT/.build/build.data
1244 echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
1245 echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
1246 shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
1247 echo ")" >> $BUILD_ROOT/.build/build.data
1248 echo -n "repos=(" >> $BUILD_ROOT/.build/build.data
1249 shellquote "${repos[@]}" >> $BUILD_ROOT/.build/build.data
1250 echo ")" >> $BUILD_ROOT/.build/build.data
1251 echo "VM_TYPE='$VM_TYPE'" >> $BUILD_ROOT/.build/build.data
1252 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
1253 umount -n $BUILD_ROOT/proc 2> /dev/null || true
1254 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
1255 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
1257 if [ -n "$VM_IMAGE" ]; then
1259 # needs to work otherwise we have a corrupted file system
1260 umount $BUILD_ROOT || cleanup_and_exit 1
1263 if [ "$VM_TYPE" = 'xen' ]; then
1264 XMROOT=file:$VM_IMAGE
1265 XMROOT=${XMROOT/#file:\/dev/phy:/dev}
1266 XMROOT="disk=$XMROOT,hda1,w"
1268 if test -n "$VM_SWAP" ; then
1269 XMSWAP=file:$VM_SWAP
1270 XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
1271 XMSWAP="disk=$XMSWAP,hda2,w"
1273 XENID="${VM_IMAGE%/root}"
1274 XENID="${XENID%/tmpfs}"
1275 XENID="${XENID##*/}"
1276 CROSS_INIT_SCRIPT="/.build/build"
1277 # to run the qemu initialization in the XEN chroot, we need to register it with a statically build shell
1278 if [ x"$BUILD_ARCH" == xarmv4l -o x"$BUILD_ARCH" == xarmv5el -o x"$BUILD_ARCH" == xarmv7el -o x"$BUILD_ARCH" == xsh4 -o x"$BUILD_ARCH" == xppc -o x"$BUILD_ARCH" == xppc64 -o x"$BUILD_ARCH" == xmips -o x"$BUILD_ARCH" == xmipsel ]; then
1279 if [ -n "$(uname -m | grep '[x3-6]86')" ]; then
1280 if [ -e /bin/bash-static -a -e /bin/mount-static ]; then
1281 CROSS_INIT_SCRIPT="/.build/initscript_qemu_vm"
1286 echo "booting XEN kernel ..."
1287 if xm list "build:$XENID" >/dev/null 2>&1 ; then
1288 echo "Instance already exist, something really went wrong..."
1289 echo "Please report to your server admin, there might be multiple services running for same domain"
1292 set -- xm create -c $BUILD_DIR/xen.conf name="build:$XENID" ${MEMSIZE:+memory=$MEMSIZE} $XMROOT $XMSWAP extra="quiet init="$CROSS_INIT_SCRIPT" panic=1 console=ttyS0"
1293 if test "$PERSONALITY" != 0 ; then
1294 # have to switch back to PER_LINUX to make xm work
1298 "$@" || cleanup_and_exit 3
1299 elif [ "$VM_TYPE" = 'uml' ]; then
1300 echo "booting UML kernel ..."
1301 set -- $uml_kernel initrd=$uml_initrd root=/ubda init=/.build/build panic=1 quiet ubd0=$VM_IMAGE ${MEMSIZE:+mem=$MEMSIZE}
1304 elif [ "$VM_TYPE" = 'qemu' -o "$VM_TYPE" = 'kvm' ]; then
1305 echo "booting $VM_TYPE ..."
1306 if [ "$kvm_virtio" = 1 ]; then
1307 qemu_disks=(-drive file="$VM_IMAGE",if=virtio -hda "$VM_IMAGE")
1308 if [ -n "$VM_SWAP" ]; then
1309 qemu_disks[${#qemu_disks[@]}]="-drive"
1310 qemu_disks[${#qemu_disks[@]}]="file=$VM_SWAP,if=virtio"
1313 qemu_disks=(-hda "$VM_IMAGE")
1314 if [ -n "$VM_SWAP" ]; then
1315 qemu_disks[${#qemu_disks[@]}]="-hdb"
1316 qemu_disks[${#qemu_disks[@]}]="$VM_SWAP"
1319 CROSS_INIT_SCRIPT="/.build/build"
1320 # to run the qemu initialization in the XEN chroot, we need to register it with a statically build shell
1321 if [ x"$BUILD_ARCH" == xarmv4l -o x"$BUILD_ARCH" == xarmv5el -o x"$BUILD_ARCH" == xarmv6el -o x"$BUILD_ARCH" == xarmv7el -o x"$BUILD_ARCH" == xarmv8el -o x"$BUILD_ARCH" == xsh4 -o x"$BUILD_ARCH" == xppc -o x"$BUILD_ARCH" == xppc64 -o x"$BUILD_ARCH" == xmips -o x"$BUILD_ARCH" == xmipsel ]; then
1322 echo "Building for arch: $BUILD_ARCH"
1323 if [ -n "$(uname -m | grep '[x3-6]86')" ]; then
1324 echo " on arch: $(uname -m | grep '[x3-6]86')"
1325 if [ -e /bin/bash-static -a -e /bin/mount-static ]; then
1326 echo " using cross-init"
1327 CROSS_INIT_SCRIPT="/.build/initscript_qemu_vm"
1331 set -- $qemu_bin -no-reboot -nographic -net none -serial stdio \
1332 -kernel $qemu_kernel \
1333 -initrd $qemu_initrd \
1334 -append "root=$qemu_rootdev $rootfstype panic=1 quiet noapic rw console=ttyS0 init=$CROSS_INIT_SCRIPT" \
1335 ${MEMSIZE:+-m $MEMSIZE} \
1338 if test "$PERSONALITY" != 0 ; then
1339 # have to switch back to PER_LINUX to make qemu work
1344 elif [ "$VM_TYPE" = 'lxc' ]; then
1345 echo "booting $VM_TYPE ..."
1346 LXCCONF="$BUILD_ROOT/.build.lxc.conf"
1348 cat $BUILD_DIR/lxc.conf > "$LXCCONF"
1349 cat >> "$LXCCONF" <<-EOF
1350 lxc.rootfs = $BUILD_ROOT
1352 # XXX: do this always instead of leaking the hosts' one?
1353 echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
1354 LXCID=${BUILD_ROOT##*/}
1355 lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
1356 lxc-create -n "$LXCID" -f "$LXCCONF" || cleanup_and_exit 1
1357 CROSS_INIT_SCRIPT="/.build/build"
1358 # to run the qemu initialization in the XEN chroot, we need to register it with a statically build shell
1359 if [ x"$BUILD_ARCH" == xarmv4l -o x"$BUILD_ARCH" == xarmv5el -o x"$BUILD_ARCH" == xarmv7el -o x"$BUILD_ARCH" == xsh4 -o x"$BUILD_ARCH" == xppc -o x"$BUILD_ARCH" == xppc64 -o x"$BUILD_ARCH" == xmips -o x"$BUILD_ARCH" == xmipsel ]; then
1360 if [ -n "$(uname -m | grep '[x3-6]86')" ]; then
1361 if [ -e /bin/bash-static -a -e /bin/mount-static ]; then
1362 CROSS_INIT_SCRIPT="/.build/initscript_qemu_vm"
1366 lxc-start -n "$LXCID" "$CROSS_INIT_SCRIPT"
1368 test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
1369 cleanup_and_exit "$BUILDSTATUS"
1371 if test -n "$VM_SWAP" ; then
1372 BUILDSTATUS=`dd if="$VM_SWAP" bs=12 count=1 2>/dev/null`
1373 case $BUILDSTATUS in
1375 mkdir -p $BUILD_ROOT/.build.packages
1376 cd $BUILD_ROOT/.build.packages || cleanup_and_exit 1
1377 echo "build: extracting built packages..."
1378 extractbuild --disk "$VM_IMAGE" --input "$VM_SWAP" --skip 512 -v || cleanup_and_exit 3
1379 # create same layout as with plain chroot
1380 if test "$BUILDTYPE" = spec ; then
1382 for i in *src.rpm; do mv "$i" SRPMS/; done
1387 mv "$i" RPMS/$arch/;
1389 elif test "$BUILDTYPE" = dsc ; then
1391 find . -type f | while read i; do mv "$i" DEBS/; done
1394 find . -type f | while read i; do mv "$i" KIWI/; done
1396 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1399 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1402 echo "No buildstatus set, packager broke either the base system (glibc/bash) or the build host has a problem, server will retry..."
1411 if test "$DO_INIT" = true ; then
1413 # create legacy .buildenv file
1415 test -z "$INCARNATION" && INCARNATION=0
1416 echo "BUILD_INCARNATION=$INCARNATION" > $BUILD_ROOT/.buildenv
1417 CREATE_BUILD_BINARIES=
1418 egrep '^#[ ]*needsbinariesforbuild[ ]*$' >/dev/null <$MYSRCDIR/$SPECFILE && CREATE_BUILD_BINARIES=--create-build-binaries
1419 set -- init_buildsystem "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1421 "$@" || cleanup_and_exit 1
1423 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
1425 echo "build does not work on a completely full filesystem"
1428 mount -n -tproc none $BUILD_ROOT/proc || true
1429 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1430 if [ -d "$OLD_PACKAGES" ]; then
1431 rm -rf "$BUILD_ROOT/.build.oldpackages"
1432 cp -r $OLD_PACKAGES $BUILD_ROOT/.build.oldpackages
1436 if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
1437 read BUILD_DIST < $BUILD_ROOT/.guessed_dist
1441 # fix rpmrc if we are compiling for i686
1443 test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
1444 if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
1445 mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
1446 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
1450 # check if we want to build with the abuild user
1453 if test -x $BUILD_ROOT/bin/rpm ; then
1454 SUSE_VERSION=`chroot $BUILD_ROOT /bin/rpm --eval '%{?suse_version}' 2>/dev/null`
1455 if test -n "$SUSE_VERSION" && test "$SUSE_VERSION" -le 1020 ; then
1459 if test "$BUILD_USER" = abuild ; then
1460 egrep '^#[ ]*needsrootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=root
1462 egrep '^#[ ]*norootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=abuild
1464 test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
1466 if test $BUILD_USER = abuild ; then
1467 if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1468 echo "abuild::${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_ROOT/etc/passwd
1469 echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed on Mandriva 2009
1470 echo 'abuild:*::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu
1471 echo "abuild::${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
1472 mkdir -p $BUILD_ROOT/home/abuild
1473 chown ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT/home/abuild
1475 if ! egrep "^abuild::${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_ROOT/etc/passwd ; then
1476 echo "abuild user present in the buildroot ($BUILD_ROOT) but uid:gid does not match"
1477 echo "buildroot currently using:"
1478 egrep "^abuild:" <$BUILD_ROOT/etc/passwd
1479 echo "build script attempting to use:"
1480 echo "abuild::${ABUILD_UID}:${ABUILD_GID}:..."
1481 echo "build aborting"
1485 if test -f $BUILD_ROOT/etc/shadow ; then
1486 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
1488 if test -f $BUILD_ROOT/etc/gshadow ; then
1489 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/gshadow > $BUILD_ROOT/etc/gshadow.t && mv $BUILD_ROOT/etc/gshadow.t $BUILD_ROOT/etc/gshadow
1491 BUILD_USER_ABUILD_USED=true
1493 if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1494 rm -rf $BUILD_ROOT/home/abuild
1495 egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
1496 mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd
1497 egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new
1498 mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group
1499 if test -f $BUILD_ROOT/etc/shadow ; then
1500 egrep -v '^abuild:' <$BUILD_ROOT/etc/shadow >$BUILD_ROOT/etc/shadow.new
1501 mv $BUILD_ROOT/etc/shadow.new $BUILD_ROOT/etc/shadow
1503 if test -f $BUILD_ROOT/etc/gshadow ; then
1504 egrep -v '^abuild:' <$BUILD_ROOT/etc/gshadow >$BUILD_ROOT/etc/gshadow.new
1505 mv $BUILD_ROOT/etc/gshadow.new $BUILD_ROOT/etc/gshadow
1510 if test "$BUILDTYPE" = spec ; then
1511 TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER`
1513 TOPDIR=/usr/src/packages
1514 mkdir -p $BUILD_ROOT$TOPDIR
1517 rm -f $BUILD_ROOT/.build.packages
1518 ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
1520 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1521 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
1527 # nasty hack to prevent rpath on known paths
1528 # FIXME: do this only for suse
1529 if test -d "$BUILD_ROOT/etc/profile.d" ; then
1530 echo "export SUSE_IGNORED_RPATHS=/etc/ld.so.conf" > "$BUILD_ROOT/etc/profile.d/buildsystem.sh"
1534 # now clean up RPM building directories
1536 rm -rf $BUILD_ROOT$TOPDIR
1537 for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT; do
1538 mkdir -p $BUILD_ROOT$TOPDIR/$i
1539 test $BUILD_USER = abuild && chown ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT$TOPDIR/$i
1543 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
1544 if test "$BUILDTYPE" = kiwi ; then
1545 mkdir -p $BUILD_ROOT$TOPDIR/KIWI
1546 if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1547 mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1549 if test -z "$LINKSOURCES" ; then
1550 cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1552 cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1554 if test "$?" != 0 ; then
1555 echo "source copy failed"
1560 cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1562 test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
1564 test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
1566 if test "$BUILDTYPE" = spec ; then
1567 # do buildrequires/release substitution
1569 if test -n "$RELEASE"; then
1570 args=(--release "$RELEASE")
1572 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
1573 # extract macros from configuration
1574 getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
1575 if test -n "$BUILD_DEBUG" ; then
1577 %prep %?_suse_insert_debug_package%%prep
1578 %package %?_suse_insert_debug_package%%package
1579 %suse_insert_debug_package \
1580 %global _suse_insert_debug_package \\\
1581 %%undefine _suse_insert_debug_package \\\
1584 ' >> $BUILD_ROOT/root/.rpmmacros
1587 if [ -n "$BUILD_JOBS" ]; then
1588 cat >> $BUILD_ROOT/root/.rpmmacros <<-EOF
1590 %_smp_mflags -j$BUILD_JOBS
1593 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
1594 # extract optflags from configuration
1595 getoptflags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_ROOT/root/.rpmrc
1596 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
1597 # case arm, extract changetarget
1598 # this is restricted to arm to make sure it doesn't interfere with x86
1599 if [ "$BUILD_ARCH" != "${BUILD_ARCH#arm}" ]; then
1600 echo "changing targetarch"
1601 chmod a+x $BUILD_DIR/getchangetarget || cleanup_and_exit 1
1602 CHANGETARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" )
1603 echo "NEW TARGET: $CHANGETARGET"
1606 if test -f $BUILD_ROOT/.spec.new ; then
1607 if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
1608 echo -----------------------------------------------------------------
1609 echo I have the following modifications for $SPECFILE:
1610 sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE > $BUILD_ROOT/.spec.t1
1611 sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2
1612 diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
1613 rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
1614 mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE
1616 rm -f $BUILD_ROOT/.spec.new
1620 if test "$BUILDTYPE" = dsc ; then
1621 rm -rf $BUILD_ROOT$TOPDIR/BUILD
1622 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
1623 test $BUILD_USER = abuild && chown -R ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT$TOPDIR
1625 DEB_SOURCEDIR=$TOPDIR/SOURCES
1626 DEB_DSCFILE=$SPECFILE
1627 for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
1628 test -f $f && DEB_TRANSFORM=true
1630 if test -n "$DEB_TRANSFORM" ; then
1631 echo "running debian transformer..."
1632 if ! debtransform $CHANGELOGARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
1633 echo "debian transforming failed."
1636 DEB_SOURCEDIR=$TOPDIR/SOURCES.DEB
1637 for DEB_DSCFILE in $BUILD_ROOT/$DEB_SOURCEDIR/*.dsc ; do : ; done
1638 DEB_DSCFILE="${DEB_DSCFILE##*/}"
1640 chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
1643 if test $BUILD_USER = abuild ; then
1644 chown -R ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT$TOPDIR/*
1646 chown -R root:root $BUILD_ROOT$TOPDIR/*
1648 cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
1650 echo -----------------------------------------------------------------
1651 if test "$BUILD_USER" = root ; then
1652 echo ----- building $SPECFILE
1654 echo ----- building $SPECFILE "(user $BUILD_USER)"
1656 echo -----------------------------------------------------------------
1657 echo -----------------------------------------------------------------
1658 if [ -n "$RUNNING_IN_VM" ]; then
1659 if [ -x /sbin/ip ]; then
1660 ip addr add 127.0.0.1/8 dev lo
1663 ifconfig lo 127.0.0.1 up
1665 if [ -n "$MYHOSTNAME" ]; then
1666 hostname "$MYHOSTNAME"
1670 BUILD_SUCCEEDED=false
1672 if test -n "$OVERLAY" ; then
1673 if -d "$OVERLAY"; then
1675 echo "Copying overlay to BUILD_ROOT"
1676 tar -cpf - . | (cd $BUILD_ROOT ; tar -xvf -)
1679 echo "OVERLAY ($OVERLAY) is no directory - skipping"
1683 if test -n "$RSYNCSRC" ; then
1684 if test -n "$RSYNCDEST"; then
1685 if test -d "$RSYNCSRC"; then
1686 if ! test -d "$BUILD_ROOT/$RSYNCDEST"; then
1687 echo "ATTENTION! Creating target directory ($BUILD_ROOT/$RSYNCDEST) as its not there."
1688 mkdir -p $BUILD_ROOT/$RSYNCDEST
1690 echo "Running rsync ..."
1691 rsync -av $RSYNCSRC/* $BUILD_ROOT/$RSYNCDEST/
1692 chown -R ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT/$RSYNCDEST
1696 echo "RSYNCSRC is no directory - skipping"
1699 echo "RSYNCSRC given, but not RSYNCDEST - skipping"
1703 if test "$BUILDTYPE" = spec ; then
1704 test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
1706 # XXX: move _srcdefattr to macro file?
1707 rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--define" "_srcdefattr (-,root,root)")
1708 if [ -n "$ABUILD_TARGET_ARCH" ]; then
1709 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET_ARCH"
1711 if [ -n "$DISTURL" ]; then
1712 rpmbopts[${#rpmbopts[@]}]='--define'
1713 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
1715 if test -s "$BUILD_ROOT/usr/lib/rpm/mandriva/macros" ; then
1716 rpmbopts[${#rpmbopts[@]}]='--eval'
1717 rpmbopts[${#rpmbopts[@]}]="%undefine _enable_debug_packages"
1719 if [ -n "$BUILD_DEBUG" ]; then
1720 rpmbopts[${#rpmbopts[@]}]='--eval'
1721 rpmbopts[${#rpmbopts[@]}]="%suse_insert_debug_package"
1723 if [ -n "$CHANGETARGET" ]; then
1724 rpmbopts[${#rpmbopts[@]}]='--target'
1725 rpmbopts[${#rpmbopts[@]}]="$CHANGETARGET"
1727 if [ -n "$RSYNCDONE" ] ; then
1728 rpmbopts[${#rpmbopts[@]}]='--define'
1729 rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
1734 test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
1735 # su involves a shell which would require even more
1736 # complicated quoting to bypass than this
1737 toshellscript $rpmbuild \
1738 "${definesnstuff[@]}" \
1740 "$TOPDIR/SOURCES/$SPECFILE" \
1741 > $BUILD_ROOT/.build.command
1742 chmod 755 $BUILD_ROOT/.build.command
1744 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
1747 if test "$BUILDTYPE" = dsc ; then
1748 # Checks to see if a build script should be used
1749 # this allows the build environment to be manipulated
1750 # and alternate build commands can be used
1751 DSC_BUILD_CMD="dpkg-buildpackage -us -uc -rfakeroot-tcp"
1752 if test -e $BUILD_ROOT/$TOPDIR/SOURCES/build.script ; then
1753 echo "Sourcing build.script to build - it should normally run 'dpkg-buildpackage -us -uc -rfakeroot-tcp'"
1754 DSC_BUILD_CMD="source $TOPDIR/SOURCES/build.script"
1755 chmod +x $BUILD_ROOT/$TOPDIR/SOURCES/build.script
1757 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && $DSC_BUILD_CMD" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
1759 mkdir -p $BUILD_ROOT/$TOPDIR/DEBS
1760 for DEB in $BUILD_ROOT/$TOPDIR/*.deb ; do
1761 test -e "$DEB" && mv "$DEB" "$BUILD_ROOT/$TOPDIR/DEBS"
1764 ln $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE $BUILD_ROOT/$TOPDIR/DEBS/
1766 ln $BUILD_ROOT/$DEB_SOURCEDIR/$f $BUILD_ROOT/$TOPDIR/DEBS/
1767 done < <(sed -ne '/^Files:/,$s/^ ................................ [0-9][0-9]* //p' < $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE)
1770 if test "$BUILDTYPE" = kiwi ; then
1771 . $BUILD_DIR/build_kiwi.sh
1775 test "$BUILD_SUCCEEDED" = true || cleanup_and_exit 1
1776 test -d "$SRCDIR" && cd "$SRCDIR"
1779 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
1780 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
1782 if test -n "$RPMS" -a -n "$BUILD_USER_ABUILD_USED" ; then
1783 echo "... checking for files with abuild user/group"
1785 while read un gn fn ; do
1786 if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
1790 done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
1791 if test -n "$BADFILE" ; then
1792 echo "please fix your filelist (e.g. add defattr)"
1797 if test -n "$RPMS" -a -d "$BUILD_ROOT/usr/lib/build/checks" ; then
1799 export DO_RPM_REMOVE=true
1800 for SRPM in $BUILD_ROOT/$TOPDIR/SRPMS/*src.rpm ; do
1801 test -f "$SRPM" && PNAME=`rpm --nodigest --nosignature -qp --qf "%{NAME}" $SRPM`
1803 for CHECKSCRIPT in $BUILD_ROOT/usr/lib/build/checks/* ; do
1804 echo "... running `basename $CHECKSCRIPT`"
1805 $CHECKSCRIPT || cleanup_and_exit 1
1809 if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_ROOT/opt/testing/bin/rpmlint" -a -d "$BUILD_ROOT/$TOPDIR/RPMS" ; then
1810 LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
1811 \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
1812 -o -name "*-32bit-*" -o -name "*-64bit-*" \
1813 -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
1814 -o -type f -name '*.rpm' -print))
1815 SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
1817 echo "RPMLINT report:"
1818 echo "==============="
1819 chroot $BUILD_ROOT /opt/testing/bin/rpmlint --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} ${SRPM_FILE_LIST[*]#$BUILD_ROOT} || cleanup_and_exit 1
1822 if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS" -a \( -d "$BUILD_ROOT/$TOPDIR/RPMS" -o -d "$BUILD_ROOT/$TOPDIR/DEBS" \) ; then
1823 # $BUILD_DIR is set to /.build when using a vm. So we need to
1824 # hardcode /usr/lib/build instead of $BUILD_DIR to prefer
1825 # mkbaselibs from the distro.
1826 # (and force distro version if CREATE_BASELIBS=internal)
1827 if test -f $BUILD_ROOT/usr/lib/build/mkbaselibs -o "$CREATE_BASELIBS" != internal ; then
1828 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1833 # IMPLEMENT ME: place code for creating binary package deltas here
1835 if test -n "$RUNNING_IN_VM" -a -n "$VM_SWAP"; then
1836 echo "... saving built packages"
1838 args="--padstart 512 --padend 512 -v"
1839 case "$BUILDTYPE" in
1841 computeblocklists $args $TOPDIR/RPMS/*/*.rpm $TOPDIR/SRPMS/* > "$VM_SWAP"
1844 computeblocklists $args $TOPDIR/DEBS/*.deb $TOPDIR/SOURCES.DEB/* > "$VM_SWAP"
1847 computeblocklists $args $TOPDIR/KIWI/* > "$VM_SWAP"
1849 esac || cleanup_and_exit 1
1852 if test -n "$RPMS" -a -d "$BUILD_ROOT/$TOPDIR/RPMS" -a -d "$BUILD_ROOT/.build.oldpackages" -a -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
1853 echo "... comparing built packages with the former built"
1854 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1855 # exit with 2, if packages built successfull, but have no changes to former built packages.
1856 if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
1862 echo "$HOST finished \"build $SPECFILE\" at `date`."