]> TLD Linux GIT Repositories - packages/rpm-build-tools.git/blobdiff - builder.sh
- move setting pkgrev right after package is built
[packages/rpm-build-tools.git] / builder.sh
index bbeb418625bbeb9c5e97b839fa344a112441a999..40e0ff48d25613a16b8c7f06d3e26f8ee02b646f 100755 (executable)
@@ -38,9 +38,10 @@ APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
 VERSION="v0.35"
 VERSIONSTRING="\
 Build package utility from PLD Linux Packages repository
-$VERSION (C) 1999-2016 Free Penguins".
+$VERSION (C) 1999-2020 Free Penguins".
 
-CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
+# Clean PATH without /usr/local or user paths
+CLEAN_PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin"
 
 # required rpm-build-macros
 RPM_MACROS_VER=1.534
@@ -121,6 +122,7 @@ WGET_RETRIES=${MAX_WGET_RETRIES:-0}
 
 # rsync repository with git refs of packages
 PKGREVS_URL="http://pkgrevs.tld-linux.org"
+SETPKGREV="false"
 
 # TLD git/df config
 TLD_GIT_SERVER="git://git.tld-linux.org"
@@ -496,6 +498,26 @@ Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version]  [
 "
 }
 
+is_rpmorg() {
+       local v
+
+       v=$(LC_ALL=C LANG=C rpm --version 2>&1)
+       v=${v#RPM version } # rpm 4
+       v=${v#rpm \(RPM\) } # rpm 5
+
+       case "$v" in
+               4.5|5.*)
+                       return 1
+                       ;;
+               4.*)
+                       return 0;
+                       ;;
+               *)
+                       echo "ERROR: unsupported RPM version $v" >&2
+                       exit 1
+       esac
+}
+
 # create tempfile. as secure as possible
 tempfile() {
        local prefix=builder.$PACKAGE_NAME${1:+.$1}
@@ -709,7 +731,8 @@ EOF
 %_sourcedir ./
 EOF
        fi
-       if rpm --version 2>&1 | grep -qE '5\.[0-9]+\.[0-9]+'; then
+       if ! is_rpmorg; then
+               local safe_macrofiles
                safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
                eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
        else
@@ -718,14 +741,20 @@ EOF
 }
 
 cache_rpm_dump() {
+       local SPEC_PATH
        if [ -n "$DEBUG" ]; then
                set -x
                set -v
        fi
 
+       if [ ! -z "$1" ]; then
+               SPEC_PATH="$1"
+       else
+               SPEC_PATH="$PACKAGE_DIR/$SPECFILE"
+       fi
        if [ -x /usr/bin/rpm-specdump ]; then
                update_shell_title "cache_rpm_dump using rpm-specdump command"
-               rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
+               rpm_dump_cache=$(eval rpm-specdump $TARGET_SWITCH $BCOND $RPMOPTS --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPEC_PATH)
        else
                update_shell_title "cache_rpm_dump using rpmbuild command"
                local rpm_dump
@@ -788,7 +817,7 @@ parse_spec() {
        get_icons
 
        cd $PACKAGE_DIR
-       cache_rpm_dump
+       cache_rpm_dump "$1"
 
        if rpm_dump | grep -qEi ":.*nosource.*1"; then
                FAIL_IF_NO_SOURCES="no"
@@ -1079,7 +1108,10 @@ get_spec() {
                local _rev=$(get_pkgrev "$CVSTAG")
                echo "$_rev" | grep -q -E "^ERROR$" || CVSTAG="$_rev"
                if git rev-parse --verify -q "$CVSTAG" >/dev/null; then
-                       git checkout "$CVSTAG" --
+                       # checkout only if differs, so this will not trash git reflog
+                       if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
+                               git checkout "$CVSTAG" --
+                       fi
                elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
                        git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
                fi
@@ -1386,6 +1418,7 @@ get_files() {
                                                ${GETURI} "$target" "$url"
                                        fi
 
+
                                        if [ -s "$target" ]; then
                                                cvsignore_df $target
                                        else
@@ -1527,6 +1560,7 @@ get_pkgrev() {
 
 set_pkgrev() {
        local _tag
+       parse_spec "$1"
        if [ "$TAG_VERSION" = "yes" ]; then
                _tag=`make_tagver`
        fi
@@ -1724,9 +1758,23 @@ build_package() {
 
        local specdir=$(insert_gitlog $SPECFILE)
        ulimit -c unlimited
+       # If required exclude directories with systemd related files from package contents
+       if grep -q -E 'systemd(unitdir|userunitdir|tmpfilesdir)' $specdir/$SPECFILE; then
+               sed -i -e '/^%exclude_systemd_files/d; /^%files/s/$/\n%exclude_systemd_files/g;' $specdir/$SPECFILE
+       fi
+       # Enable/disable distro wide bconds based on ~/.distbcond
+       process_distbcond "$specdir/$SPECFILE"
+       # Add %tld macro to release to allow release control
+       sed -i -r -e '/^Release:/s/%\{\?tld\}//g; s/^Release:\s+(.*)$/Release:\t\1%{?tld}/;' $specdir/$SPECFILE
        # FIXME: eval here is exactly why?
        PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${TIME_COMMAND} ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE
        retval=$?
+
+       # Set pkgrev if requested and build status is OK
+       if [ ! -z "$SETPKGREV" ] && [ "$SETPKGREV" = "true" ] && [ "$retval" -eq "0" ]; then
+               set_pkgrev "$specdir/$SPECFILE"
+       fi
+
        rm -r $specdir
 
        if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
@@ -1821,6 +1869,51 @@ process_bcondrc() {
        update_shell_title "parse ~/.bcondrc: DONE!"
 }
 
+process_distbcond() {
+       # apply bconds from ~/.distbcond to spec
+       # The file structure is like gentoo's package.use:
+       # ---
+       # * -selinux
+       # samba -mysql -pgsql
+       # w32codec-installer license_agreement
+       # php +mysqli
+       # ---
+       if [ -f $HOME/.distbcond ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.distbcond ]); then
+               :
+       else
+               return
+       fi
+
+       SN=${SPECFILE%%\.spec}
+
+       local distbcond=$HOME/.distbcond
+       [ -n $HOME_ETC ] && [ -f $HOME_ETC/.distbcond ] && distbcond=$HOME_ETC/.distbcond
+
+       local bcond_avail=$(find_spec_bcond $SPECFILE)
+
+       while read pkg flags; do
+               # ignore comments
+               [[ "$pkg" == \#* ]] && continue
+
+               # any package or current package?
+               if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
+                       for flag in $flags; do
+                               local opt=${flag#[+-]}
+
+                               # use only flags which are in this package.
+                               if [[ $bcond_avail = *${opt}* ]]; then
+                                       if [[ $flag = -* ]]; then
+                                               sed -i -r -e '/^%bcond_(with|without)\s+'$opt'/s/^%bcond_(with|without)/%bcond_with/g;' "$1"
+                                       elif [[ $flag = +* ]]; then
+                                               sed -i -r -e '/^%bcond_(with|without)\s+'$opt'/s/^%bcond_(with|without)/%bcond_without/g;' "$1"
+                                       fi
+                               fi
+                       done
+               fi
+       done < $distbcond
+       update_shell_title "parse ~/.distbcond: DONE!"
+}
+
 set_bconds_values() {
        update_shell_title "set bcond values"
 
@@ -1847,7 +1940,7 @@ set_bconds_values() {
                without_*)
                        bcond=${opt#without_}
                        case "$BCOND" in
-                       *--without?${bcond}*)
+                       *--without?${bcond}\ *|*--without?${bcond})
                                AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
                                ;;
                        *)
@@ -1858,7 +1951,7 @@ set_bconds_values() {
                with_*)
                        bcond=${opt#with_}
                        case "$BCOND" in
-                       *--with?${bcond}*)
+                       *--with?${bcond}\ *|*--with?${bcond})
                                AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
                                ;;
                        *)
@@ -1915,7 +2008,7 @@ run_sub_builder() {
 # this requires following sudo rules:
 # - poldek --noask --caplookup -ug
 poldek_install() {
-       LANG=C $POLDEK_CMD --noask --caplookup --uniq -ug "$@"
+       LC_ALL=C LANG=C $POLDEK_CMD --noask --caplookup --uniq -ug "$@"
 }
 
 # install packages
@@ -2044,7 +2137,7 @@ _rpm_cnfl_check() {
                DEPS=$(cat)
        fi
 
-       LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
+       LC_ALL=C LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
 }
 
 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
@@ -2441,7 +2534,8 @@ while [ $# -gt 0 ]; do
                        DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
                        ;;
                --pkgrev)
-                       COMMAND="set_pkgrev"
+                       SETPKGREV="true"
+                       COMMAND="build-source"
                        shift;;
                -lp)
                        COMMAND="list_pkgrev"
@@ -2792,17 +2886,6 @@ case "$COMMAND" in
        "version" )
                echo "$VERSIONSTRING"
                ;;
-       "set_pkgrev" )
-               init_builder
-               if [ -z "$SPECFILE" ]; then
-                       Exit_error err_no_spec_in_cmdl
-               fi
-               get_spec > /dev/null
-               parse_spec
-               set_bconds_values
-               display_bconds
-               set_pkgrev
-               ;;
        "list_pkgrev" )
                init_builder
                if [ -z "$SPECFILE" ]; then