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 recipe file.
6 # BUILD_ROOT here the packages will be built
8 ################################################################
10 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License version 2 or 3 as
14 # published by the Free Software Foundation.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program (see the file COPYING); if not, write to the
23 # Free Software Foundation, Inc.,
24 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 ################################################################
28 # some VMs do not allow to specify the init process...
29 if test "$0" = /sbin/init ; then
30 exec /.build/build "$@"
33 test -z "$BUILD_DIR" -a -e /.build/build.data -a -z "$BUILD_IGNORE_2ND_STAGE" && BUILD_DIR=/.build
34 test -z "$BUILD_DIR" && BUILD_DIR=/usr/lib/build
35 test -z "$BUILD_ROOT" && BUILD_ROOT=/var/tmp/build-root
36 test -z "$CONFIG_DIR" && CONFIG_DIR="$BUILD_DIR/configs"
38 export BUILD_ARCH BUILD_HOST_ARCH BUILD_ROOT BUILD_RPMS BUILD_DIR BUILD_DEBUG
47 . "$BUILD_DIR/build-vm"
49 # slurp in recipe support
50 . "$BUILD_DIR/build-recipe"
52 # slurp in package binary support
53 . "$BUILD_DIR/build-pkg"
55 # need to restore build root owner for non-root builds
58 # Default uid:gid for the build user
67 NO_TOPDIR_CLEANUP=false
99 CACHE_DIR=/var/cache/build
103 # This is for insserv
104 export YAST_IS_RUNNING=instsys
114 Some comments for build
115 -----------------------
117 With build you can create binary packages. They will be built in a chroot
118 system. This chroot system will be setup automatically. Normally you can
119 simply call build with a spec file as parameter - nothing else has to be
122 If you want to set the directory were the chroot system will be setup
123 (at the moment it uses $BUILD_ROOT),
124 simply set the the environment variable BUILD_ROOT.
128 export BUILD_ROOT=/var/tmp/mybuildroot
131 Normally build builds the complete package including src.rpm (rpmbuild -ba).
132 If you want let build only make the binary package, simply set
134 export BUILD_RPM_BUILD_STAGE=-bb
136 (or -bc, -bp, -bi, ... see "Maximum RPM" for more details [*]).
138 When the build command succeeds, the rpm files can be found under
139 $BUILD_ROOT/usr/src/packages/RPMS/
144 --help You already got it :)
146 --kill Instead of starting a build kill the one currently
149 --shell Instead of starting a build start a root shell in
152 --clean Delete old build root before initializing it
154 --no-init Skip initialization of build root and start with build
157 --no-checks Do not run checks (postbuild and %check)
159 --lint Run rpmlint after build.
162 Capture build output to logfile. Defaults to
163 .build.log in the build root for non-VM builds.
166 Use package repository at PATH_OR_URL. Supported formats
167 are rpm-md, yast2, debian, and arch linux.
168 Alternatively zypp://NAME specifies the zypp
169 repository NAME. The repo must be refreshed with zypp
170 so package meta data is available locally. With emtpy
171 NAME all enabled repositories are used.
173 --rpms path1:path2:...
174 Specify path where to find the RPMs for the build system
176 --arch arch1:arch2:...
177 Specify what architectures to select from the RPMs
179 --verify Run verify when initializing the build root
183 Also install package 'pack'
186 Use 'rootdir' to setup chroot environment
189 Use 'cachedir' to cache remote repo's packages. The
190 default cache dir is /var/cache/build, every repo
191 given by --repo corresponds to a subdir named
192 as md5sum of its repo url, for example:
193 /var/cache/build/3e8ea9b47808629414a0cebc33ea285e
195 --oldpackages oldpackagesdir
196 Define a directory with a former build
198 --baselibs Create -32bit/-64bit/-x86 rpms for other architectures
201 List rpms that would be used to create a fresh build root.
202 Does not create the build root or perform a build.
208 Enable feature X for build
211 Disable feature X for build
214 Define macro X with value Y
217 Override Release in spec file
220 Set stage for rpmbuild. Defaults to -ba.
223 Set target platform for rpmbuild
225 --jobs N Use N parallel processes during build.
226 Sets %jobs and %_smp_mflags macros and
227 defines the number of CPUs to use for
230 --threads N sets number of threads for VM
233 Use ccache to speed up rebuilds
236 Use N parallel build jobs with icecream
239 Copy overlay filesystem to buildroot after installing
240 all RPMs. This must be a valid directory.
243 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
244 inside the buildroot using rsync.
245 It will "%define RSYNCDONE 1" for handling %setup in your
249 %setup -n aaa_base -T -D -b 5 -b 7
251 %setup -n aaa_base -b 5 -b 7
254 --rsync-dest RSYNCDEST
255 Copy overlay folder (RSYNCSRC) to a folder (RSYNCDEST)
256 inside the buildroot using rsync.
259 Specify the uid and gid to use for the abuild user.
260 This is useful if you are hacking in the buildroot.
261 This must be set to the same value if the buildroot is re-used.
264 monitor used resources during build inside VM
267 Use KVM to secure build process. Your hardware needs to support
271 Use XEN to secure build process, you to run in a XEN Dom0 environment.
274 Use Linux Containers to isolate the process. This may not be 100% safe.
283 Use any generic emulator to isolate the build process. You need to write
284 an emulator/emulator.sh script and put it next to the build script sources.
286 --emulator-script SCRIPT
287 specify another emulator instead of emulator.sh
290 Use virtual machine instead of chroot
291 TYPE is one of xen|kvm|uml|qemu|lxc|zvm|openstack|ec2
294 GUEST is a z/VM build worker controlled by the controlling
298 Each worker in z/VM needs a uniq number. This is needed to
299 calculate uniq device addresses for root and swap device.
302 EC2 only: defines amazon control server
305 openstack only: defines control server name
308 Use FILE as disk for virtual machine.
309 Defaults to \$BUILD_ROOT.img if unset
312 Use FILE as swap space for virtual machine. The swap space is
313 also used for retrieving packages from the VM so its size must
314 be sufficiently large
316 --vm-disk-size SIZEINMB
317 --vm-swap-size SIZEINMB
318 --vm-disk-filesystem TYPE
319 Defaults for automatic setup of VM root/swap files
322 Set amount of RAM for VMs
324 --vm-hugetlbfs HUGETLBFSPATH
325 Use hugetlb for memory management, path to mounted hugetlbfs.
329 Kernel and initrd to use for VM (kvm and qemu only)
332 Enable creation of a debuginfo package
334 Remember to have fun!
336 [*] Maximum RPM: http://www.rpm.org/max-rpm/
341 echo "Usage: `basename $0` [--no-init|--clean|--rpms path|--verify|--help] [dir-to-build|recipe-to-build]"
347 # return values: 0 -> success, new packages built
348 # 1 -> error, build failed
349 # 2 -> successfull build, but no changes to former built packages
350 # 3 -> something wrong with build host
352 cleanup_and_exit () {
354 test -z "$1" && set 0
355 rm -f $BUILD_ROOT/.repo.config
356 rm -f $BUILD_ROOT/exit
357 if test "$1" -eq 1 -a -x /bin/df ; then
358 # okay, it failed, but maybe because disk space?
359 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
363 if test -n "$RUNNING_IN_VM" ; then
364 echo "$1" > /.build/_exitcode
365 test -n "$browner" && chown "$browner" $BUILD_ROOT
368 umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
369 umount -n $BUILD_ROOT/proc 2>/dev/null || true
372 umount -n $BUILD_ROOT/dev/pts 2>/dev/null
373 if test $? -ne 0; then
378 umount -n $BUILD_ROOT/dev/shm 2>/dev/null || true
379 umount -n $BUILD_ROOT/sys 2>/dev/null || true
380 test -n "$VM_IMAGE" -a "$VM_IMAGE" != 1 && umount $BUILD_ROOT 2>/dev/null || true
381 test -n "$VM_TYPE" && vm_cleanup
400 # create a shell script from command line. Used for preserving arguments
410 if test -n "$CCACHE" ; then
411 if mkdir -p $BUILD_ROOT/var/lib/build/ccache/bin; then
412 for i in $(ls $BUILD_ROOT/usr/bin | grep -E '^(cc|gcc|[cg][+][+])([-]?[234][.]?[0-9])*$'); do
413 # ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
414 rm -f $BUILD_ROOT/var/lib/build/ccache/bin/$i
415 test -e $BUILD_ROOT/usr/bin/$i || continue
416 echo '#! /bin/sh' > $BUILD_ROOT/var/lib/build/ccache/bin/$i
417 echo "test -e /usr/bin/$i || exit 1" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
418 echo 'export PATH=/usr/lib/icecc/bin:/opt/icecream/bin:/usr/bin:$PATH' >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
419 echo "ccache $i \"\$@\"" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
420 chmod 755 $BUILD_ROOT/var/lib/build/ccache/bin/$i
421 echo "Installed ccache wrapper as $BUILD_ROOT/var/lib/build/ccache/bin/$i"
424 mkdir -p "$BUILD_ROOT/.ccache"
425 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/.ccache"
426 echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
427 echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
429 rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
435 local icecreamdir="/var/run/icecream"
436 if test `readlink "$BUILD_ROOT/var/run"` = '/run' ; then
437 icecreamdir="/run/icecream"
439 if [ "$icecream" -eq 0 ]; then
440 rm -rf "$BUILD_ROOT$icecreamdir"
441 rm -f "$BUILD_ROOT/etc/profile.d/build_icecream.sh"
445 if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then
446 echo "*** icecream package not installed ***"
450 echo "using icecream with $icecream jobs"
452 if test -z "$CCACHE" ; then
453 echo 'export PATH=/usr/lib/icecc/bin:/opt/icecream/bin:$PATH' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
455 echo 'export CCACHE_PATH=/usr/lib/icecc/bin:/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
458 local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT$icecreamdir/*.tar.{bz2,gz}`)
459 icecc_vers=${icecc_vers//$BUILD_ROOT/}
461 # XXX use changelog like autobuild does instead?
462 # only run create-env if compiler or glibc changed
463 if test -z "$icecc_vers" \
464 -o ! -e "$BUILD_ROOT/$icecc_vers" \
465 -o "$BUILD_ROOT/usr/bin/gcc" -nt "$BUILD_ROOT/$icecc_vers" \
466 -o "$BUILD_ROOT/usr/bin/g++" -nt "$BUILD_ROOT/$icecc_vers" \
467 -o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
468 -o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers"
470 rm -rf "$BUILD_ROOT$icecreamdir"
471 mkdir -p "$BUILD_ROOT$icecreamdir"
472 if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
473 createenv=/usr/bin/create-env
474 elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
475 createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
476 elif [ -e "$BUILD_ROOT"/usr/lib64/icecc/icecc-create-env ]; then
477 createenv="/usr/lib64/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
479 echo "create-env not found"
482 echo "creating new env in '$icecreamdir'"
483 chroot $BUILD_ROOT bash -c "cd $icecreamdir; $createenv" || cleanup_and_exit 1
484 icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/$icecreamdir/*.tar.{bz2,gz}`)
485 icecc_vers=${icecc_vers//$BUILD_ROOT/}
486 echo "created icecream environment $icecc_vers"
488 echo "reusing existing icecream environment $icecc_vers"
490 if test -n "$icecc_vers" ; then
491 echo "export ICECC_VERSION=$icecc_vers" >> "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
496 if test -n "$VM_IMAGE" -o -n "$RUNNING_IN_VM" ; then
505 eval "limit=\$(($2/3*4))"
509 eval "limit=\$(($2/3*4+$limit))"
512 done < <(cat /proc/meminfo) # cat for proc stuff
515 echo "Memory limit set to ${limit}KB"
524 if test "$BUILDTYPE" == arch ; then
527 if test "$BUILDTYPE" == dsc ; then
530 if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
531 BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
533 if test -e $BUILD_ROOT/usr/lib/build/baselibs_global.conf; then
534 BASELIBS_GLOBAL="-c /usr/lib/build/baselibs_global.conf"
539 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
540 # don't use -R as extracted sources, build root etc might be below $TOPDIR
541 chown "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"/* "$BUILD_ROOT$TOPDIR"/RPMS/* || true
543 local mkbaselibs="/usr/lib/build/mkbaselibs"
545 # $BUILD_DIR is set to /.build when using a vm. So we need to
546 # hardcode /usr/lib/build instead of $BUILD_DIR to prefer
547 # mkbaselibs from the distro.
548 if test -f $BUILD_ROOT$mkbaselibs; then
549 if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
550 BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
553 if test "$CREATE_BASELIBS" = 'internal'; then
554 echo "Warning: mkbaselibs missing in build root, skipping baselibs"
557 # use external version
558 whichone=" (external)"
559 mkbaselibs="/.mkbaselibs/mkbaselibs"
560 rm -rf "$BUILD_ROOT/.mkbaselibs"
561 mkdir -p "$BUILD_ROOT/.mkbaselibs"
562 cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs/
563 if test "$BUILDTYPE" == "dsc" ; then
564 cp -f $BUILD_DIR/baselibs_global-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
565 cp -f $BUILD_ROOT$TOPDIR/SOURCES/baselibs-deb.conf $BUILD_ROOT/.mkbaselibs/baselibs-deb.conf
566 BASELIBS_CFG="-c /.mkbaselibs/baselibs-deb.conf"
568 cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs/baselibs_g.conf
569 if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf; then
570 cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf
571 BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf"
574 if test -e $BUILD_ROOT/.mkbaselibs/baselibs_g.conf; then
575 BASELIBS_GLOBAL="-c /.mkbaselibs/baselibs_g.conf"
578 echo "... creating baselibs$whichone"
581 chroot $BUILD_ROOT su -c "$mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG $line" - $BUILD_USER || cleanup_and_exit 1
582 done < <(IFS=$'\n'; echo "${pkgs[*]#$BUILD_ROOT}" | xargs -n 1024)
583 rm -rf "$BUILD_ROOT/.mkbaselibs"
590 test -z "$RUNNING_IN_VM" || return 0
591 if test -z "$old_packages" ; then
592 rm -rf "$BUILD_ROOT"/.build.oldpackages*
595 for d in "${old_packages[@]}"; do
596 dest="$BUILD_ROOT/.build.oldpackages"
597 test "$i" = 0 || dest="$dest$i"
598 if test -d "$d" -a "$d" != "$dest" ; then
607 become_root_or_fail() {
608 if test ! -w /root ; then
609 echo "You have to be root to use $0" >&2
616 # strip trailing slash
617 test "$BUILD_ROOT" != / && BUILD_ROOT="${BUILD_ROOT%/}"
618 if test -d "$BUILD_ROOT" ; then
619 # check if it is owned by root
620 if test -z "$RUNNING_IN_VM" -a \! -O "$BUILD_ROOT" -a "`stat -c %u $BUILD_ROOT`" -ne 0 ; then
621 echo "BUILD_ROOT=$BUILD_ROOT must be owned by root. Exit..."
625 test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
626 if ! mkdir $BUILD_ROOT ; then
627 echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
632 if test ! -w "$BUILD_ROOT" ; then
633 echo "Error: BUILD_ROOT=$BUILD_ROOT not writeable, try --clean."
637 rm -rf "$BUILD_ROOT/.build.packages"
638 if test -z "$VM_TYPE" -a -z "$RUNNING_IN_VM" ; then
639 # don't touch this in VM
640 rm -rf "$BUILD_ROOT/.build"
641 mkdir -p "$BUILD_ROOT/.build"
646 if test -d "$OVERLAY"; then
648 echo "Copying overlay to BUILD_ROOT"
649 tar -cpf - . | (cd $BUILD_ROOT ; tar -xvf -)
652 echo "OVERLAY ($OVERLAY) is no directory - skipping"
657 if test -n "$RSYNCDEST" ; then
658 if test -d "$RSYNCSRC" ; then
659 if ! test -d "$BUILD_ROOT/$RSYNCDEST" ; then
660 echo "ATTENTION! Creating missing target directory ($BUILD_ROOT/$RSYNCDEST)."
661 mkdir -p $BUILD_ROOT/$RSYNCDEST
663 echo "Running rsync ..."
664 rsync -av $RSYNCSRC/* $BUILD_ROOT/$RSYNCDEST/
665 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/$RSYNCDEST"
669 echo "RSYNCSRC is not a directory - skipping"
672 echo "RSYNCSRC given, but not RSYNCDEST - skipping"
680 rm -f $BUILD_ROOT/.repo.config
681 for i in "${repos[@]}"; do
682 if [ "$i" == "--repo" -o "$i" == "--repository" ]; then
685 echo $i |grep -E "^http[s]?:\/\/[^\/]*\/?" >/dev/null && echo $i >> $BUILD_ROOT/.repo.config
686 j=$(echo $i | sed -e "s#://[^@]*@#://#")
701 export PATH=$BUILD_DIR:/sbin:/usr/sbin:/bin:/usr/bin:$PATH
703 if vm_detect_2nd_stage ; then
704 set "/.build-srcdir/$RECIPEFILE"
705 export PATH=/.build:$PATH
708 . $BUILD_DIR/common_functions || exit 1
713 if test -z "$ARG" ; then
714 echo "$PARAM needs an agrument" >&2
719 while test -n "$1"; do
722 test "$ARG" = "${ARG#-}" || ARG=
728 set -- "----noarg=$PARAM" "$@"
731 case ${PARAM/#--/-} in
742 -nochecks|-no-checks)
746 CLEAN_BUILD='--clean'
762 export VERIFY_BUILD_SYSTEM=true
779 -extrapacks|-extra-packs|-X)
781 BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
791 CREATE_BASELIBS=internal
794 KEEP_PACKS="--keep-packs"
808 old_packages=("${old_packages[@]}" "$ARG")
838 NO_TOPDIR_CLEANUP=true
841 USEUSEDFORBUILD="--useusedforbuild"
851 -define|-with|-without)
853 PARAM="-${PARAM/#--/-}"
854 definesnstuff[${#definesnstuff[@]}]="$PARAM"
855 definesnstuff[${#definesnstuff[@]}]="$ARG"
860 repos[${#repos[@]}]="--repository"
861 repos[${#repos[@]}]="$ARG"
867 test "$icecream" -gt 0 && BUILD_JOBS="$ARG"
913 if test -n "${ABUILD_ID//[0-9:]/}" ; then
914 echo "--uid argument must be uid:gid"
917 ABUILD_UID=${ABUILD_ID%:*}
918 ABUILD_GID=${ABUILD_ID#*:}
923 RPMLIST="--rpmlist $ARG"
935 DLNOSIGNATURE="--nosignature"
938 echo "$ARG does not take an argument"
942 USEHIGHERDEPS="--use-higher-deps"
945 if vm_parse_options "$@" ; then
946 set -- "${nextargs[@]}"
947 elif recipe_parse_options "$@" ; then
948 set -- "${nextargs[@]}"
950 echo "Unknown option '$PARAM'. Exit."
955 RECIPEFILES[${#RECIPEFILES[@]}]="$PARAM"
960 if [ "$SHORT_CIRCUIT" = true -a -z "$BUILD_RPM_BUILD_STAGE" ]; then
961 echo "--short-circuit needs a stage (use --stage)"
965 if test -n "$KILL" ; then
966 test -z "$SRCDIR" || usage
967 if test -n "$VM_IMAGE" -a -n "$VM_SWAP" -a -n "$VM_TYPE"; then
968 # mark job as failed so that we don't extract packages
969 if test "$VM_TYPE" != zvm ; then
970 echo -n "BUILDSTATUS1" >"$VM_SWAP"
973 (set -C; > "$BUILD_ROOT/exit" 2>/dev/null || true)
974 if test -n "$VM_TYPE" ; then
977 if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
978 echo "could not kill build in $BUILD_ROOT"
985 if test -n "$CLEAN_BUILD" ; then
989 if test -n "$VM_TYPE" -a -z "$RUNNING_IN_VM" ; then
993 if test -z "$RPMLIST" -a -z "$RUNNING_IN_VM" ; then
994 if test -z "$repos" -a -z "$BUILD_RPMS" ; then
995 repos=(--repository 'zypp://')
1003 expand_recipe_directories
1005 if test -n "$LIST_STATE" ; then
1006 BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
1007 test -d "$BUILD_ROOT" || cleanup_and_exit 3
1008 RECIPEFILE=$RECIPEFILES # only one specified anyways
1009 if test "$RECIPEFILE" != "${RECIPEFILE%.src.rpm}" ; then
1010 MYSRCDIR="$BUILD_ROOT/usr/src/packages/SOURCES"
1011 recipe_unpack_srcrpm
1012 RECIPEFILE="$MYSRCDIR/$RECIPEFILE"
1014 init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" --list-state "${definesnstuff[@]}" "${repos[@]}" $DLNOSIGNATURE $KEEP_PACKS $USEHIGHERDEPS $USEUSEDFORBUILD $RECIPEFILE $BUILD_EXTRA_PACKS
1016 rm -rf "$BUILD_ROOT"
1017 cleanup_and_exit $ERR
1020 # do vm setup if needed
1021 if test -z "$RUNNING_IN_VM" -a -n "$VM_TYPE" -a -n "$VM_IMAGE" ; then
1028 if test "$BUILD_ROOT" = / ; then
1029 browner="$(stat -c %u /)"
1032 rm -f $BUILD_ROOT/exit
1034 if test -w /root ; then
1035 mkdir -p $BUILD_ROOT/proc
1036 mkdir -p $BUILD_ROOT/sys
1037 mkdir -p $BUILD_ROOT/dev/pts
1038 mount -n -tproc none $BUILD_ROOT/proc || true
1039 mount -n -tdevpts -omode=0620,gid=5 none $BUILD_ROOT/dev/pts
1042 if test -z "$VM_IMAGE" -a -z "$LOGFILE" ; then
1043 LOGFILE="$BUILD_ROOT/.build.log"
1046 if test -n "$LOGFILE" -a -z "$RUN_SHELL" ; then
1047 echo "logging output to $LOGFILE..."
1050 # set start time, to be substracted for build log timestamps
1051 STARTTIME=`perl -e 'print time()'`
1053 if test -n "$RUNNING_IN_VM" ; then
1054 # no additional timestamps in inner vm build system
1055 exec 1> >(exec -a 'build logging' tee -a $LOGFILE) 2>&1
1056 elif test -n "$VM_IMAGE" ; then
1057 # external run of virtualization build
1058 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
1061 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
1070 test -z "$HOST" && HOST=`hostname`
1072 if test -z "$RUNNING_IN_VM" ; then
1073 echo Using BUILD_ROOT=$BUILD_ROOT
1074 test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
1075 echo Using BUILD_ARCH=$BUILD_ARCH
1076 test -n "$VM_TYPE" && echo "Doing $VM_TYPE build${VM_IMAGE:+ in $VM_IMAGE}"
1080 test "$BUILD_ARCH" = all && BUILD_ARCH=
1081 BUILD_USER_ABUILD_USED=
1083 for RECIPEFILE in "${RECIPEFILES[@]}" ; do
1085 SRCDIR="${RECIPEFILE%/*}"
1086 RECIPEFILE="${RECIPEFILE##*/}"
1088 recipe_set_buildtype
1090 if test -z "$RUNNING_IN_VM" ; then
1092 echo "$HOST started \"build $RECIPEFILE\" at `date --utc`."
1094 test -n "$REASON" && echo "$REASON"
1096 TIME_START_TIME=`date +%s` # for statistics
1100 # first setup building directory...
1103 if ! test -s "$RECIPEFILE" ; then
1104 echo "$RECIPEFILE is empty. This should not happen..."
1109 # special hack to build from a .src.rpm
1110 test "$RECIPEFILE" != "${RECIPEFILE%.src.rpm}" && recipe_unpack_srcrpm
1112 echo "processing recipe $MYSRCDIR/$RECIPEFILE ..."
1115 test -z "$BUILD_EXTRA_PACKS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
1116 test -z "$CREATE_BASELIBS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
1117 test -z "$CCACHE" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
1118 test "$icecream" = 0 || ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
1119 test -z "$DO_LINT" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
1120 test "$VMDISK_FILESYSTEM" = xfs && ADDITIONAL_PACKS="$ADDITIONAL_PACKS libblkid1"
1121 test "$VM_TYPE" = zvm && ADDITIONAL_PACKS="$ADDITIONAL_PACKS udev libcap2"
1123 # we need to do this before the vm is started
1124 if test -n "$CHANGELOG" -a -z "$RUNNING_IN_VM" ; then
1125 rm -f $BUILD_ROOT/.build-changelog
1127 *.dsc) CFFORMAT=debian ;;
1130 echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$RECIPEFILE"
1131 if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$RECIPEFILE" > $BUILD_ROOT/.build-changelog ; then
1132 rm -f $BUILD_ROOT/.build-changelog
1136 if test -n "$VM_TYPE" -a -z "$RUNNING_IN_VM"; then
1141 if test "$DO_INIT" = true ; then
1142 start_time=`date +%s`
1144 # create legacy .buildenv file
1146 test -z "$INCARNATION" && INCARNATION=0
1147 echo "BUILD_INCARNATION=$INCARNATION" > $BUILD_ROOT/.buildenv
1148 CREATE_BUILD_BINARIES=
1149 test "$BUILDTYPE" = preinstallimage && mkdir -p $BUILD_ROOT/.preinstall_image
1150 egrep '^#[ ]*needsbinariesforbuild[ ]*$' >/dev/null <$MYSRCDIR/$RECIPEFILE && CREATE_BUILD_BINARIES=--create-build-binaries
1151 test "$BUILDTYPE" = mock && CREATE_BUILD_BINARIES=--create-build-binaries
1152 test "$BUILDTYPE" = debootstrap && CREATE_BUILD_BINARIES=--create-build-binaries
1153 test "$BUILDTYPE" = livebuild && CREATE_BUILD_BINARIES=--create-build-binaries
1154 set -- init_buildsystem --configdir "$CONFIG_DIR" --cachedir "$CACHE_DIR" "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $DLNOSIGNATURE $KEEP_PACKS $USEHIGHERDEPS $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$RECIPEFILE" $ADDITIONAL_PACKS
1156 start_time=`date +%s`
1157 "$@" || cleanup_and_exit 1
1159 TIME_INSTALL=$(( `date +%s` - $start_time ))
1161 # arbitrary limit of 10MB
1162 if test $((`stat -f -c "%a*%S/1024/1024" $BUILD_ROOT`)) -lt 10; then
1163 # ensure that old stat is not failing (RHEL4)
1164 if df $BUILD_ROOT 2>/dev/null | grep -q "100%"; then
1166 echo "build does not work on a completely full filesystem"
1170 mount -n -tproc none $BUILD_ROOT/proc || true
1171 mount -n -tdevpts -omode=0620,gid=5 none $BUILD_ROOT/dev/pts
1176 # hack to process preinstallimages early
1177 if test "$BUILDTYPE" = preinstallimage ; then
1182 if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
1183 read BUILD_DIST < $BUILD_ROOT/.guessed_dist
1187 # install dummy sign program if needed
1189 test -f $BUILD_ROOT/usr/bin/sign_installed && mv $BUILD_ROOT/usr/bin/sign_installed $BUILD_ROOT/usr/bin/sign
1190 if test -n "$SIGNDUMMY" ; then
1191 test -f $BUILD_ROOT/usr/bin/sign && mv $BUILD_ROOT/usr/bin/sign $BUILD_ROOT/usr/bin/sign_installed
1192 cp $BUILD_DIR/signdummy $BUILD_ROOT/usr/bin/sign
1193 chmod 755 $BUILD_ROOT/usr/bin/sign
1197 # check if we want to build with the abuild user
1200 if test -x $BUILD_ROOT/bin/rpm ; then
1201 SUSE_VERSION=`chroot $BUILD_ROOT /bin/rpm --eval '%{?suse_version}' 2>/dev/null`
1202 test -n "$SUSE_VERSION" -a "${SUSE_VERSION:-0}" -le 1020 && BUILD_USER=root
1204 if test "$BUILD_USER" = abuild ; then
1205 egrep '^#[ ]*needsrootforbuild[ ]*$' >/dev/null <$RECIPEFILE && BUILD_USER=root
1207 egrep '^#[ ]*norootforbuild[ ]*$' >/dev/null <$RECIPEFILE && BUILD_USER=abuild
1209 test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
1211 # appliance builds must run as root
1212 if test "$BUILDTYPE" = kiwi ; then
1213 imagetype=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $RECIPEFILE imagetype)
1214 test "$imagetype" = product || BUILD_USER=root
1217 # fixup passwd/group
1218 if test $BUILD_USER = abuild ; then
1219 if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1220 echo "abuild:x:${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_ROOT/etc/passwd
1221 echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed on Mandriva 2009
1222 echo 'abuild:*::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu
1223 echo "abuild:x:${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
1224 mkdir -p $BUILD_ROOT/home/abuild
1225 chown "$ABUILD_UID:$ABUILD_GID" $BUILD_ROOT/home/abuild
1227 if ! egrep "^abuild:x?:${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_ROOT/etc/passwd ; then
1228 sed -i '/^abuild:/d' $BUILD_ROOT/etc/passwd
1229 sed -i '/^abuild:/d' $BUILD_ROOT/etc/group
1230 echo "abuild:x:${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash" >>$BUILD_ROOT/etc/passwd
1231 echo "abuild:x:${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
1232 chown "$ABUILD_UID:$ABUILD_GID" $BUILD_ROOT/home/abuild -R
1235 if test -f $BUILD_ROOT/etc/shadow ; then
1236 sed -i -e "s@^root::@root:*:@" $BUILD_ROOT/etc/shadow
1238 if test -f $BUILD_ROOT/etc/gshadow ; then
1239 sed -i -e "s@^root::@root:*:@" $BUILD_ROOT/etc/gshadow
1241 BUILD_USER_ABUILD_USED=true
1246 if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1247 rm -rf "$BUILD_ROOT/home/abuild"
1248 sed -i -e '/^abuild:/d' $BUILD_ROOT/etc/passwd
1249 sed -i -e '/^abuild:/d' $BUILD_ROOT/etc/group
1250 if test -f $BUILD_ROOT/etc/shadow ; then
1251 sed -i -e '/^abuild:/d' $BUILD_ROOT/etc/shadow
1253 if test -f $BUILD_ROOT/etc/gshadow ; then
1254 sed -i -e '/^abuild:/d' $BUILD_ROOT/etc/gshadow
1259 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1260 mount -n -tdevpts -omode=0620,gid=5 none $BUILD_ROOT/dev/pts 2> /dev/null
1261 # needed for POSIX semaphores
1262 test -d $BUILD_ROOT/dev/shm || rm -f $BUILD_ROOT/dev/shm
1263 mkdir -p $BUILD_ROOT/dev/shm
1264 mount -n -ttmpfs none $BUILD_ROOT/dev/shm 2> /dev/null
1266 if test -n "$RUNNING_IN_VM" ; then
1267 if test -x /sbin/ip ; then
1268 ip addr add 127.0.0.1/8 dev lo
1269 ip addr add ::1/128 dev lo
1272 ifconfig lo 127.0.0.1 up
1273 ifconfig lo add ::1/128
1275 if test -n "$MYHOSTNAME" ; then
1276 hostname "$MYHOSTNAME"
1283 # fill build directories with sources. Also sets TOPDIR
1286 # strip prefix from autogenerated files of source services.
1287 for i in $BUILD_ROOT$TOPDIR/SOURCES/_service\:* ; do
1288 mv "$i" "${i%/*}/${i##*:}"
1290 RECIPEFILE="${RECIPEFILE##*:}"
1292 # create .build.packages link
1293 rm -f $BUILD_ROOT/.build.packages
1294 ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
1296 # nasty hack to prevent rpath on known paths
1297 # FIXME: do this only for suse
1298 if test -d "$BUILD_ROOT/etc/profile.d" ; then
1299 echo "export SUSE_IGNORED_RPATHS=/etc/ld.so.conf" > "$BUILD_ROOT/etc/profile.d/buildsystem.sh"
1302 # get rid of old src dir, it is no longer needed and just wastes space
1303 test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
1309 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
1311 cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
1313 echo -----------------------------------------------------------------
1314 if test "$BUILD_USER" = root ; then
1315 echo ----- building $RECIPEFILE
1317 echo ----- building $RECIPEFILE "(user $BUILD_USER)"
1319 echo -----------------------------------------------------------------
1320 echo -----------------------------------------------------------------
1321 BUILD_SUCCEEDED=false
1323 if test -n "$OVERLAY" ; then
1327 if test -n "$RSYNCSRC" ; then
1331 start_time=`date +%s`
1333 if test "$DO_STATISTICS" = 1; then
1334 mkdir -p $TOPDIR/OTHER
1335 echo "TIME_main_build: $(( `date +%s` - $start_time ))" >> $TOPDIR/OTHER/_statistics
1339 test "$BUILD_SUCCEEDED" = true || cleanup_and_exit 1
1340 test -d "$SRCDIR" && cd "$SRCDIR"
1343 if test -n "$RUNNING_IN_VM" -a -n "$DO_STATISTICS" ; then
1344 touch /.build/_statistics.exit
1347 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
1348 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
1350 if test -n "$RPMS" -a -n "$BUILD_USER_ABUILD_USED" ; then
1351 recipe_check_file_owners
1354 if test -n "$RPMS" -a -d "$BUILD_ROOT/usr/lib/build/checks" ; then
1355 export DO_RPM_REMOVE=true
1358 for SRPM in $BUILD_ROOT/$TOPDIR/SRPMS/*src.rpm ; do
1359 test -f "$SRPM" && PNAME=`rpm --nodigest --nosignature -qp --qf "%{NAME}" $SRPM`
1361 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1362 for CHECKSCRIPT in $BUILD_ROOT/usr/lib/build/checks/* ; do
1363 echo "... running ${CHECKSCRIPT##*/}"
1364 $CHECKSCRIPT || cleanup_and_exit 1
1366 umount -n $BUILD_ROOT/proc 2>/dev/null || true
1369 # checkscripts may have deleted some binaries
1370 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm" 2>/dev/null || true`
1371 DEBS=`find $BUILD_ROOT/$TOPDIR/DEBS -type f -name "*.deb" 2>/dev/null || true`
1373 if test -n "$RPMS" -a "$DO_CHECKS" != false ; then
1377 if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS"; then
1384 # TODO: don't hardcode. instead run scripts in a directory as it's done for the checks
1385 if test -n "$RPMS" -a -d "$BUILD_ROOT/.build.oldpackages" ; then
1386 recipe_compare_oldpackages
1387 # no need to create deltas if the build is the same
1388 if test ! -e $BUILD_ROOT/.build/.same_result_marker ; then
1389 recipe_create_deltarpms
1393 if test -n "$RUNNING_IN_VM" ; then
1394 vm_wrapup_build $(recipe_resultdirs) OTHER
1398 echo "$HOST finished \"build $RECIPEFILE\" at `date --utc`."
1401 cleanup_and_exit "$exitcode"