]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder_.sh
- escape some regexp characters in file name, so grep has a chance to find line with...
[packages/rpm-build-tools.git] / builder_.sh
index 45dfc64e1cf88374ce5d25e95a792c0de3c81ebe..e6890684a03c68779db92ae43a61bdaf6d66863b 100644 (file)
 #      100 - Unknown error (should not happen)
 
 # Notes (todo/bugs):
-# - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
 # - when Icon: field is present, -5 and -a5 doesn't work
 # - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
 # - does not respect NoSource: X, and tries to cvs up such files [ example: VirtualBox-bin.spec and its Source0 ]
 # TODO:
 # - ability to do ./builder -bb foo.spec foo2.spec foo3.spec
-
-RCSID='$Id$'
-r=${RCSID#* * }
-rev=${r%% *}
+# - funny bug, if source-md5 is set then builder will download from distfiles even if there is no url present:
+#   Source10:  forwardfix.pl
+#   # Source10-md5:    8bf85f7368933a4e0cb4f875bac28733
+# - builder --help:
+#      basename: missing operand
+#      Try `basename --help' for more information.
+#      -- and the normal usage info --
+
+PROGRAM=${0##*/}
+APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
+RCSID='$Id$' r=${RCSID#* * } rev=${r%% *}
 VERSION="v0.35/$rev"
 VERSIONSTRING="\
 Build package utility from PLD Linux CVS repository
-$VERSION (C) 1999-2009 Free Penguins".
+$VERSION (C) 1999-2010 Free Penguins".
 
 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
 
+# required rpm-build-macros
+RPM_MACROS_VER=1.534
+
 COMMAND="build"
 TARGET=""
 
@@ -202,6 +211,15 @@ else
        RPMBUILD="rpmbuild"
 fi
 
+#
+# sanity checks
+#
+if [ -d $HOME/rpm/SOURCES ]; then
+       echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
+       echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
+       exit 1
+fi
+
 #
 # are we using cvs-nserver ?
 #
@@ -358,6 +376,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 --show-bcond-args   - show active bconds, from ~/.bcondrc. this is used by
                       ./repackage.sh script. in other words, the output is
                       parseable by scripts.
+--show-avail-bconds - show available bconds
 --with/--without <feature>
                     - conditional build package depending on %_with_<feature>/
                       %_without_<feature> macro switch.  You may now use
@@ -382,13 +401,13 @@ depspecname() {
 update_shell_title() {
        [ -t 1 ] || return
        local len=${COLUMNS:-80}
-       local msg=$(echo "$*" | cut -c-$len)
+       local msg="$(echo "$*" | cut -c-$len)"
 
        if [ -n "$BE_VERBOSE" ]; then
                echo >&2 "$(date +%s.%N) $*"
        fi
 
-       if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then
+       if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
                local pkg
                if [ -n "$PACKAGE_NAME" ]; then
                        pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
@@ -438,6 +457,7 @@ minirpm() {
 %x8664 x86_64 amd64 ia32e
 %alt_kernel %{nil}
 %_alt_kernel %{nil}
+%bootstrap_release() %{1}
 %requires_releq_kernel_up(s:n:) %{nil}
 %requires_releq_kernel_smp(s:n:) %{nil}
 %requires_releq_kernel(s:n:) %{nil}
@@ -445,6 +465,7 @@ minirpm() {
 %pyrequires_eq() %{nil}
 %requires_eq() %{nil}
 %requires_eq_to() %{nil}
+%requires_ge() %{nil}
 %releq_kernel_up(n:) ERROR
 %releq_kernel_smp(n:) ERROR
 %releq_kernel(n:) ERROR
@@ -480,6 +501,8 @@ minirpm() {
 %remove_etc_shells(p) %{p:<lua>}
 %lua_add_etc_shells()  %{nil}
 %lua_remove_etc_shells() %{nil}
+%required_jdk %{nil}
+%buildrequires_jdk %{nil}
 EOF
        if [ "$NOINIT" = "yes" ] ; then
                cat >> $BUILDER_MACROS <<'EOF'
@@ -542,7 +565,7 @@ rpm_dump() {
 
 get_icons() {
        update_shell_title "get icons"
-       ICONS=$(awk '/^Icon:/ {print $2}' ${ASSUMED_NAME}/${SPECFILE})
+       ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
        if [ -z "$ICONS" ]; then
                return
        fi
@@ -662,8 +685,19 @@ init_builder() {
 
        if [ "$NOINIT" != "yes" ] ; then
                TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
-               REPO_DIR=$TOP_DIR
-               PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
+
+               local macros_ver=$(rpm -E %?rpm_build_macros)
+               if [ -z "$macros_ver" ]; then
+                       REPO_DIR=$TOP_DIR/packages
+                       PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
+               else
+                       if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
+                               echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
+                               exit 1
+                       fi
+                       REPO_DIR=$TOP_DIR
+                       PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
+               fi
        else
                REPO_DIR="."
                PACKAGE_DIR="."
@@ -704,7 +738,7 @@ get_spec() {
 
                        # create symlinks for tools
                        if [ "$SYMLINK_TOOLS" != "no" ]; then
-                               for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh; do
+                               for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
                                        [ -f $a ] || continue
                                        ln -s ../$a $ASSUMED_NAME
                                        cvsignore_df $a
@@ -737,7 +771,7 @@ find_mirror() {
        local origin mirror name rest ol prefix
        while read origin mirror name rest; do
                # skip comments and empty lines
-               if [ -z "$origin" ] || [[ $origin == \#* ]]; then
+               if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
                        continue
                fi
                ol=$(echo -n "$origin" | wc -c)
@@ -787,7 +821,7 @@ src_md5() {
                fi
        fi
 
-       source_md5=`grep -i "#[         ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://'`
+       source_md5=`grep -i "^#[        ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://'`
        if [ -n "$source_md5" ]; then
                echo $source_md5
        else
@@ -797,7 +831,7 @@ src_md5() {
                else
                        # we have empty SourceX-md5, but it is still possible
                        # that we have NoSourceX-md5 AND NoSource: X
-                       nosource_md5=`grep -i "#[        ]*NoSource$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
+                       nosource_md5=`grep -i "^#[       ]*NoSource$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
                        if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[     ]*$no$" $SPECFILE`" ] ; then
                                echo $nosource_md5
                        fi
@@ -1357,41 +1391,65 @@ check_buildarch() {
        fi
 }
 
-build_package() {
-       update_shell_title "build_package"
-       if [ -n "$DEBUG" ]; then
-               set -x
-               set -v
-       fi
+# from relup.sh
+set_release() {
+       local specfile="$1"
+       local rel="$2"
+       local newrel="$3"
+       sed -i -e "
+               s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
+               s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
+       " $specfile
+}
 
-       cd "$PACKAGE_DIR"
+set_version() {
+       local specfile="$1"
+       local ver="$2"
+       local newver="$3"
+       sed -i -e "
+               s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
+               s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
+       " $specfile
+}
 
+try_upgrade() {
        if [ -n "$TRY_UPGRADE" ]; then
+               local TNOTIFY TNEWVER TOLDVER
                update_shell_title "build_package: try_upgrade"
+
+               cd "$PACKAGE_DIR"
+               
                if [ -n "$FLOAT_VERSION" ]; then
-                       TNOTIFY=$(./pldnotify.awk $SPECFILE -n) || exit 1
+                       TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
                else
-                       TNOTIFY=$(./pldnotify.awk $SPECFILE) || exit 1
+                       TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
                fi
 
                TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
 
                if [ -n "$TNEWVER" ]; then
                        TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
-                       echo "New version found, updating spec file to version " $TNEWVER
+                       echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
                        if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
                                cp -f $SPECFILE $SPECFILE.bak
                        fi
                        chmod +w $SPECFILE
-                       eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
-                       eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
+                       set_release $SPECFILE $PACKAGE_RELEASE 1
+                       set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
                        parse_spec
-                       NODIST="yes" get_files $SOURCES $PATCHES
-                       update_md5 $SOURCES
-
-                       unset TOLDVER TNEWVER TNOTIFY
+                       return 1
                fi
        fi
+       return 0
+}
+
+build_package() {
+       update_shell_title "build_package"
+       if [ -n "$DEBUG" ]; then
+               set -x
+               set -v
+       fi
+
        cd "$PACKAGE_DIR"
 
        case "$COMMAND" in
@@ -1441,10 +1499,12 @@ build_package() {
        fi
        if [ "$RETVAL" -ne "0" ]; then
                if [ -n "$TRY_UPGRADE" ]; then
-                       echo "\n!!! Package with new version cannot be built automagically\n"
+                       echo "\nUpgrade package to new version failed."
                        if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
+                               echo "Restoring old spec file."
                                mv -f $SPECFILE.bak $SPECFILE
                        fi
+                       echo ""
                fi
                Exit_error err_build_fail
        fi
@@ -1546,19 +1606,25 @@ set_bconds_values() {
                case "$opt" in
                without_*)
                        bcond=${opt#without_}
-                       if [[ "$BCOND" = *--without?${bcond}* ]]; then
+                       case "$BCOND" in
+                       *--without?${bcond}*)
                                AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
-                       else
+                               ;;
+                       *)
                                AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
-                       fi
+                               ;;
+                       esac
                        ;;
                with_*)
                        bcond=${opt#with_}
-                       if [[ "$BCOND" = *--with?${bcond}* ]]; then
+                       case "$BCOND" in
+                       *--with?${bcond}*)
                                AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
-                       else
+                               ;;
+                       *)
                                AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
-                       fi
+                               ;;
+                       esac
                        ;;
                *)
                        echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
@@ -1645,19 +1711,24 @@ remove_build_requires() {
 display_bconds() {
        if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
                if [ "$BCOND" ]; then
-                       echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
-                       echo -ne "$BCOND"
+                       echo ""
+                       echo "Building $SPECFILE with the following conditional flags:"
+                       echo -n "$BCOND"
                else
-                       echo -ne "\nNo conditional flags passed"
+                       echo ""
+                       echo "No conditional flags passed"
                fi
-               echo -ne "\n\nfrom available:\n"
-               echo -ne "--with   :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
+               echo ""
+               echo "from available:"
+               echo "--with   :\t$AVAIL_BCONDS_WITH"
+               echo "--without:\t$AVAIL_BCONDS_WITHOUT"
+               echo ""
        fi
 }
 
 display_branches() {
        if [ "$NOCVSSPEC" != "yes" ]; then
-               echo -ne "Available branches: "
+               echo -n "Available branches: "
                $CVS_COMMAND status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
        fi
 }
@@ -1753,10 +1824,12 @@ fetch_build_requires()
        fi
 
                # XXX is this ugliest code written in human history still needed?
-               echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
-               echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
-               echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
-               echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
+               echo "All packages installed by fetch_build_requires() are written to:"
+               echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
+               echo ""
+               echo "If anything fails, you may get rid of them by executing:"
+               echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
+               echo ""
                echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
                for package_item in $(cat $SPECFILE | grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'|sed -e s,perl\(,perl-,g -e s,::,-,g -e s,\(.*\),,g -e s,%{,,g -e s,},,g|grep -v OpenGL-devel|sed -e s,sh-utils,coreutils,g -e s,fileutils,coreutils,g -e s,textutils,coreutils,g -e s,kgcc_package,gcc,g -e s,\),,g)
                do
@@ -1829,11 +1902,11 @@ fetch_build_requires()
                                                for package_name in `cat ".$package-req.txt"|grep -v ^#`
                                                do
                                                        if [ "$package_name" = "$package" ]; then
-                                                               echo -ne "Installing BuildRequired package:\t$package_name\n"
+                                                               echo "Installing BuildRequired package:\t$package_name"
                                                                update_shell_title "Installing BuildRequired package: ${package_name}"
                                                                install_required_packages $package
                                                        else
-                                                               echo -ne "Installing (sub)Required package:\t$package_name\n"
+                                                               echo "Installing (sub)Required package:\t$package_name"
                                                                update_shell_title "Installing (sub)Required package: ${package_name}"
                                                                install_required_packages $package_name
                                                        fi
@@ -1844,7 +1917,7 @@ fetch_build_requires()
                                                                        ;;
                                                                *)
                                                                        echo "Attempting to run spawn sub - builder..."
-                                                                       echo -ne "Package installation failed:\t$package_name\n"
+                                                                       echo "Package installation failed:\t$package_name"
                                                                        run_sub_builder $package_name
                                                                        if [ $? -eq 0 ]; then
                                                                                install_required_packages $package_name
@@ -1864,7 +1937,7 @@ fetch_build_requires()
                                                rm -f ".$package-req.txt"
                                        else
                                                echo "Attempting to run spawn sub - builder..."
-                                               echo -ne "Package installation failed:\t$package\n"
+                                               echo "Package installation failed:\t$package"
                                                run_sub_builder $package
                                                if [ $? -eq 0 ]; then
                                                        install_required_packages $package
@@ -1899,7 +1972,7 @@ init_rpm_dir() {
        TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
        CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
 
-       echo "Initialising rpm directories to $TOP_DIR from $CVSROOT"
+       echo "Initializing rpm directories to $TOP_DIR from $CVSROOT"
        mkdir -p $TOP_DIR/{RPMS,BUILD,SRPMS}
        cd $TOP_DIR
        $CVS_COMMAND -d $CVSROOT co packages/{.cvsignore,rpm.groups,dropin,mirrors,md5,adapter{,.awk},fetchsrc_request,builder,{relup,compile,repackage}.sh}
@@ -2211,6 +2284,10 @@ while [ $# -gt 0 ]; do
                        COMMAND="show_bcond_args"
                        shift
                        ;;
+               --show-avail-bconds)
+                       COMMAND="show_avail_bconds"
+                       shift
+                       ;;
                --nodeps)
                        shift
                        RPMOPTS="${RPMOPTS} --nodeps"
@@ -2289,6 +2366,33 @@ case "$COMMAND" in
                        set_bconds_values
                        echo "$BCOND"
                fi
+               ;;
+       "show_avail_bconds")
+               init_builder
+               if [ -n "$SPECFILE" ]; then
+                       get_spec > /dev/null
+                       parse_spec
+                       local bcond_avail=$(find_spec_bcond $SPECFILE)
+                       local opt bcond bconds
+                       for opt in $bcond_avail; do
+                               case "$opt" in
+                               without_*)
+                                       bcond=${opt#without_}
+                                       bconds="$bconds $bcond"
+                                       ;;
+                               with_*)
+                                       bcond=${opt#with_}
+                                       bconds="$bconds $bcond"
+                                       ;;
+                               *)
+                                       echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
+                                       exit 1
+                                       ;;
+                               esac
+                       done
+                       echo $bconds
+               fi
+
                ;;
        "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
                init_builder
@@ -2339,8 +2443,17 @@ case "$COMMAND" in
                        if [ -n "$NOSOURCE0" ] ; then
                                SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
                        fi
-                       get_files $SOURCES $PATCHES
-                       check_md5 $SOURCES
+                       try_upgrade
+                       case $? in
+                               0)
+                                       get_files $SOURCES $PATCHES
+                                       check_md5 $SOURCES
+                                       ;;
+                               *)
+                                       NODIST="yes" get_files $SOURCES $PATCHES
+                                       update_md5 $SOURCES
+                                       ;;
+                       esac
                        build_package
                        if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
                                run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
This page took 0.052171 seconds and 4 git commands to generate.