]> git.pld-linux.org Git - projects/cleanbuild.git/blobdiff - cleanbuild
run findbr inside container
[projects/cleanbuild.git] / cleanbuild
index dc071dbcb186be466c69034a5945e11d9651c3af..e7da70a158ea725fe5793fc3d5f339b8051c089b 100755 (executable)
@@ -1,14 +1,29 @@
 #!/usr/bin/sudo /bin/sh
 
-USER="sparky"
 RPMS_FROM="$HOME/rpm/cleanRPMS.repo"
 DEST="th"
-SRC="-n th -n th-ready"
+SRC="-n th-x86_64-test"
 SUFFIX=""
 CACHEDIR="$PWD/poldekcache"
+RPMMACROS=""
+BUILDERRC=""
 IGNORE=""
+CHROOTSIZE="4G"
+ignore() { IGNORE="$IGNORE $*"; }
+NODEBUG=true
+CLEANAFTER=false
+FORCE_UMOUNT=false
+NOREBUILDDB=true
+MULTILIB=false
+# Whatever you set here as value, consider that it may not be shorter than
+# /usr/lib/debug (or /usr/src/debug) for debuginfo to work.
+# You get "Only dest dir longer than base dir not supported" error otherwise.
+BUILDDIR=/usr/src/BUILD
+
+[ -r .cleanbuildrc ] && . ./.cleanbuildrc
 
-[ -r .cleanbuildrc ] && . .cleanbuildrc
+[ -z "$USER" ] && echo "USER not defined" && exit 1
+[ "$USER" = "root" ] && echo "USER must not be root" && exit 1
 
 export LC_ALL=C
 unset LANGUAGE
@@ -25,7 +40,11 @@ usage() {
        echo ""
        echo "cleanbuild options:"
        echo " -32, -64, -th-i486  - select architecture"
-       echo " -a, -b, -c, -d      - select chroot directory"
+       echo " --cleanafter | -ca  - clean after build"
+       echo " --forceumount | -fu - force umount tmpfs"
+       echo " --debug             - enable debug"
+       echo " --network           - allow build to use networking"
+       echo " -a, -b, -c, -d, -e  - select alternative chroot directory"
        exit 1
 }
 
@@ -33,8 +52,8 @@ FETCH=false
 CLEAN=false
 CREATE=false
 BUILD=false
+NETWORK=false
 INSTALL=false
-CLEANAFTER=false
 
 case "$0" in
        *clean)
@@ -70,6 +89,8 @@ while [ $# -gt 0 ]; do
                -64)    OPT="-th-x86_64" ;;
                -th-32) OPT="-th-i686" ;;
                -th-64) OPT="-th-x86_64" ;;
+               -ti-32) OPT="-ti-i686" ;;
+               -ti-64) OPT="-ti-x86_64" ;;
                -ac)    OPT="-ac-amd64" ;;
                -ac-32) OPT="-ac-i586" ;;
                -ac-64) OPT="-ac-amd64" ;;
@@ -79,16 +100,40 @@ while [ $# -gt 0 ]; do
        case "$OPT" in
                -th-i[46]86 | -th-x86_64)
                        DEST="$V"
-                       SRC="-n $V -n $V-ready -n th-noarch -n th-noarch-ready"
+                       SRC="-n $V-ready"
                        ;;
-               -ac-amd64 | -ac-i[356]86 | -ac-athlon)
+               -th-i[46]86-test | -th-x86_64-test)
+                       DEST="$V"
+                       SRC="-n $V"
+                       ;;
+               -ti-i[56]86 | -ti-x86_64)
+                       DEST="$V"
+                       SRC="-n $V-ready"
+                       ;;
+               -ti-i[56]86-test | -ti-x86_64-test)
                        DEST="$V"
                        SRC="-n $V"
                        ;;
+               -ac-amd64 | -ac-i[356]86 | -ac-athlon)
+                       DEST="$V"
+                       SRC="-n $V-ready"
+                       ;;
+               -[1-9]G | -[1-9][0-9]G )
+                       CHROOTSIZE="$V"
+                       ;;
                --cleanafter | -ca)
                        CLEANAFTER=true
                        ;;
-               -[a-z])
+               --debug)
+                       NODEBUG=false
+                       ;;
+               --network)
+                       NETWORK=true
+                       ;;
+               --forceumount | -fu)
+                       FORCE_UMOUNT=true
+                       ;;
+               -[a-e])
                        SUFFIX="$OPT"
                        ;;
                -~*)
@@ -104,11 +149,16 @@ done
 if $BUILD; then
        [ $# -ne 0 ] || usage
        build_pkg="${1}"
+       build_pkg="${build_pkg%/}"
+       build_pkg="${build_pkg%.spec}"
+       build_pkg="${build_pkg#*/}"
        shift
 
        builder_options="$*"
 fi
 
+$NODEBUG || set -x
+
 CHNAME="chroot-$DEST$SUFFIX"
 CHDIR="$PWD/$CHNAME"
 CHHOME="/home/users/$USER"
@@ -171,40 +221,49 @@ for D in installed buildlogs $CACHEDIR; do
        fi
 done
 
-poldek_options="-O keep_downloads=yes -O suggests=no -O ignore=vserver-packages -O unique_package_names=yes -O particle_install=no"
-
-ignore() { IGNORE="$IGNORE $*"; }
 ignore \
-       vserver-packages \
        upstart\* \
+       upstart \
+       compat-\* \
+       systemd-init \
+       hhvm \
+       vserver-packages \
        xorg-driver-video-fglrx\* xorg-driver-video-nvidia\* xorg-xserver-xgl-libGL \
+       xorg-driver-video-vboxvideo \
        xorg-data-xbitmaps \
        compat-gcc\* \
        libpng1\* \
+       libjpeg libjpeg-devel \
+       freetype1-devel-* \
        anacron fcron hc-cron \
        masqmail msmtp-sendmail omta postfix sendmail ssmtp nail-mail nullmailer \
        ghostscript-esp \
-       \*-multilib-\* \
-       stfl-python \
-       perl-PathTools perl-MIME-Base64 \
-       gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher \
-       phonon-backend-xine \
-       xemacs-extras \
-       freetype1-devel \
-       kde-icons-actions kipi-plugins \
+       perl-Scalar-List-Utils \
+       perl-ExtUtils-Install \
+       phonon-backend-mplayer phonon-backend-vlc \
+       libgcj libgcj-devel \
+       icedtea6-jre icedtea6-jdk \
+       icedtea7-jre icedtea7-jdk \
+       java-sun-jre java-sun-jdk \
+       java5-sun-jre java5-sun-jdk \
+       oracle-java7-jre oracle-java7-jdk \
        gnome-menus \
-       java-sun-jre
+       gnome-speech-driver-festival gnome-speech-driver-speech-dispatcher
 
+if ! $MULTILIB; then
+       ignore '*-multilib-*'
+fi
 
 rebuilddb()
 {
-       rpm --root=$CHDIR --rebuilddb
+       $NOREBUILDDB || rpm --root=$CHDIR --rebuilddb
 }
 
 poldek()
 {
+       $NODEBUG || set -x
        rebuilddb
-       /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" $poldek_options "$@"
+       /usr/bin/poldek $SRC -s "$RPMS_FROM" -r "$CHDIR" "--cachedir=$CACHEDIR" --conf=$PWD/poldekconf/poldek.conf "$@"
 }
 
 
@@ -217,7 +276,16 @@ build_umount()
 
 build_remove_root()
 {
-       umount $CHDIR
+       $NODEBUG || set -x
+       if $FORCE_UMOUNT; then
+               # safety checks.
+               [ "$CHDIR" ] || exit 1
+               [ -d "$CHDIR" ] || exit 1
+               rm -rf $CHDIR/*
+               umount -l $CHDIR
+       else
+               umount $CHDIR
+       fi
        rmdir $CHDIR
 }
 
@@ -233,40 +301,67 @@ build_prepare_root()
 {
        title "preparing chroot"
        set -e
+       $NODEBUG || set -x
        mkdir $CHDIR
-       mount -t tmpfs -o size=8G /dev/null $CHDIR
+       mount -t tmpfs -o size=$CHROOTSIZE,relatime /dev/null $CHDIR
        echo $$ > $CHDIR/.pid
 
-       rpm --root=$CHDIR --initdb 
+       rpmversion=$(rpm -E '%(v=%{_rpmversion}; IFS=.; set -- $v; echo $1)')
+       rpmversion=${rpmversion:-4}
+
+       if [ "$rpmversion" -ge 5 ]; then
+               rpm --root=$CHDIR -qa
+       else
+               rpm --root=$CHDIR --initdb
+       fi
        poldek --up || :
-       poldek -O "ignore=$IGNORE" -u rpm-build
+       poldek -O "ignore=$IGNORE" -u rpm-build pwdutils coreutils time util-linux git-core gawk
+       echo Poldek exit: $?
 
        for DIR in dev proc sys; do
+               # We need to create these directories manually, because they are marked
+               # as netsharedpath in cleanbuild poldek.conf
+               mkdir $CHDIR/$DIR
                mount -o bind /$DIR $CHDIR/$DIR
        done
 
-       chroot $CHDIR useradd -m $USER -u$(getent passwd $USER | cut -d: -f3)
+       # group 'users' may already exist, so ignore errors
+       chroot $CHDIR groupadd $(id $USER -gn) -g$(id $USER -g) || :
+       chroot $CHDIR useradd -m $USER -u$(id $USER -u) -g $(id $USER -gn)
+
+       # replicate files which already belong to $USER
+       # so they will have correct owner and permissions
        cp -a $CHDIR/$CHHOME/{tmp,rpm}
-       cp -a $CHDIR/$CHHOME/tmp $CHDIR/BUILD
+       cp -a $CHDIR/$CHHOME/tmp $CHDIR$BUILDDIR
+
        cp -a $CHDIR/$CHHOME/{.bashrc,.rpmmacros}
-       cat <<-'EOM' > $CHDIR/$CHHOME/.rpmmacros
-       %_builddir              /BUILD
+       cat <<-EOM > $CHDIR/$CHHOME/.rpmmacros
+       %_builddir              $BUILDDIR
        %buildroot              %{_builddir}/%{name}-%{version}-root-%(id -u -n)
-       %_rpmdir                %{_topdir}/cleanRPMS
+       %_rpmdirname    cleanRPMS
+       %_rpmdir                %{expand:%%global _rpmdir %([ -d %{_topdir}/../%{_rpmdirname} ] && (cd %{_topdir}/../%{_rpmdirname}; pwd) || echo %{_topdir}/%{_rpmdirname})}%_rpmdir
        %distribution   CleanPLD
        %_binary_payload        w1.gzdio
 EOM
+       [ -z "$RPMMACROS" ] || echo "$RPMMACROS" >> $CHDIR/$CHHOME/.rpmmacros
+
+       cp -a $CHDIR/$CHHOME/{.bashrc,.builderrc}
        cat <<-'EORC' > $CHDIR/$CHHOME/.builderrc
        TITLECHANGE=no
 EORC
+       [ -z "$BUILDERRC" ] || echo "$BUILDERRC" >> $CHDIR/$CHHOME/.builderrc
+
        set +e
 }
 
 build_mount_home()
 {
+       $NODEBUG || set -x
        mount -o bind $HOME/rpm $CHDIR/$CHHOME/rpm
-}
 
+       # ensure RPMS dir is available
+       chroot $CHDIR su $USER -c 'mkdir -p $(rpm -E %_rpmdir)'
+}
 
 print_installed()
 {
@@ -283,6 +378,8 @@ addlist()
        LIST="$1"
 
        print_installed info
+
+       return
        echo "*** $build_pkg $(date --rfc-3339=seconds) ***" >> $LIST
        print_installed echo >> $LIST
 }
@@ -305,7 +402,7 @@ builddie()
 LAST_INSTALL=""
 poldek_install()
 {
-       I="$1";
+       local I="$1" ret
        # Nothing to install
        [ -n "$I" ] || return 1
        # Installing same packets second time
@@ -328,7 +425,9 @@ poldek_install()
        [ -n "$ret" ] && return $ret
 
        # try harder
+       info "Poldek install failed, retry without ignore"
        poldek -u $I && return 0
+       info "Poldek install failed, retry once more without ignore"
        poldek -u $I && return 0
        warn "Poldek:" "Could not install" $I
        return 1
@@ -339,21 +438,23 @@ maybe_call()
        local cond="$1"; shift
        local func="$1"; shift
 
-       [ $cond == "false" ] && return
-       $func "$@"
-       [ $cond == "exit_after" ] && exit
+       [ $cond = "false" ] && return
+       "$func" "$@"
+       [ $cond = "exit_after" ] && exit
 }
 
 fetch()
 {
        info "Fetching $build_pkg"
        title "fetch"
+       $NODEBUG || set -x
        su $USER -c "$HOME/rpm/packages/builder -g $build_pkg $builder_options" \
                || die 11 "Fetch failed"
 }
 
 create()
 {
+       $NODEBUG || set -x
        su $USER -c "poldek -s $RPMS_FROM --mkidx"
 
        if [ ! -d $CHDIR ]; then
@@ -364,6 +465,9 @@ create()
 }
 
 
+info "Configured Poldek sources"
+poldek -l
+
 maybe_call $FETCH fetch
 
 check_running
@@ -376,6 +480,8 @@ echo $$ > $CHDIR/.pid
 
 maybe_call $INSTALL poldek_install "$*"
 
+maybe_call $NETWORK cp -bf /etc/resolv.conf $CHDIR/etc/
+
 $BUILD || exit
 
 if [ -p /tmp/fixfreq ]; then
@@ -385,6 +491,8 @@ fi
 while true; do
        info "Building $build_pkg in $CHNAME"
        rebuilddb
+       find $CHDIR/usr/lib{,64} -name "*.la" -print0 | \
+               xargs -0 -r sed -i -e "s@dependency_libs=.*@dependency_libs=' '@"
        buildlog="buildlogs/$build_pkg"
        if [ -r $buildlog ]; then
                i=1
@@ -394,11 +502,10 @@ while true; do
                info "moving $buildlog to $buildlog.$i"
                mv $buildlog $buildlog.$i
        fi
+       ./findunusedbr -c $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
        title "building"
-       { chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn -bb $build_pkg $builder_options" 2>&1; echo $? > ecode; } | tee $buildlog
-
-       ECODE=$(< ecode)
-       rm -f ecode
+       ./teeboth $buildlog chroot $CHDIR su $USER -c "$CHHOME/rpm/packages/builder -nn --define '_enable_debug_packages 0' -bb $build_pkg $builder_options"
+       ECODE=$?
 
        if grep -q "error: Failed build dependencies:" $buildlog; then
                SEARCH=$(cat $buildlog | awk '/^Error:/ { p = 0 }; { if ( p ) { f="p"; if ( $1 ~ /^\// ) f="f"; printf "search -%c %s; ", f, $1; } }; /error: Failed build dependencies:/ { p = 1 }')
@@ -413,7 +520,7 @@ while true; do
                fi
        fi
 
-       ./findbr $CHDIR/BUILD $buildlog > $$.installed
+       ./findbr $CHDIR/$BUILDDIR $buildlog > $$.installed
        installed_something=false
        while read pkg msg; do
                if poldek_install $pkg; then
@@ -431,6 +538,7 @@ while true; do
        if [ $ECODE -eq 0 ]; then
                $CLEANAFTER && clean
                addlist BUILT_OK
+               ./findunusedbr $CHDIR $HOME/rpm/packages/$build_pkg/$build_pkg.spec
                info "$build_pkg built OK !"
                title "OK !"
                exit 0
This page took 0.117668 seconds and 4 git commands to generate.