]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- man.szczecin.pl unresponsive
[packages/rpm-build-tools.git] / builder.sh
index 5bbbfc9bf1147dc43faa256809c9d875efd30de1..a1937f784bb5a77a06db0a254df607858a9e831b 100755 (executable)
@@ -39,7 +39,7 @@ RCSID='$Id: builder,v 1.645 2011/02/13 17:54:10 glen Exp $' r=${RCSID#* * } rev=
 VERSION="v0.35/$rev"
 VERSIONSTRING="\
 Build package utility from PLD Linux Packages repository
-$VERSION (C) 1999-2012 Free Penguins".
+$VERSION (C) 1999-2014 Free Penguins".
 
 CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
 
@@ -77,11 +77,12 @@ DATE=`date +%Y-%m-%d_%H-%M-%S`
 # target arch, can also be used for log file naming
 TARGET=$(rpm -E %{_target})
 
+# Note the *single* quotes, this allows using shell variables expanded at build time
 # Example: LOGFILE='../log.$PACKAGE_NAME'
 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
 # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
 # Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
-# Yes, you can use variable name! Note _single_ quotes!
+# Example: LOGFILE='.log.$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.$TARGET.$DATE'
 LOGFILE=''
 
 # use teeboth Perl wrapper
@@ -468,13 +469,13 @@ insert_gitlog() {
        # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
        # otherwise i'd use --date=iso here
        # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
-       # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c#l31
+       # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
        # NOTE: changelog date is always in UTC for rpmbuild
        # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
        git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
                local logfmt='%B%n'
-               git notes list $sha1 > /dev/null 2>&1 && logfmt=%N
-               git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n${logfmt}%n" --date=raw | sed '/^$/q'
+               git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
+               git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
        done > $gitlog
 
        # add link to full git logs
@@ -511,11 +512,11 @@ teeboth() {
                local efile rc logfile=$1; shift
                if [ "$logfile" ]; then
                        efile=$(tempfile)
-                       { "$@" < /dev/null 2>&1; echo $? > $efile; } | tee -a $logfile
+                       { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile
                        rc=$(< $efile)
                        rm -f $efile
                else
-                       "$@" < /dev/null
+                       "$@"
                        rc=$?
                fi
        fi
@@ -581,10 +582,7 @@ set_spec_target() {
 
 # runs rpm with minimal macroset
 minirpm() {
-       # we reset macros not to contain macros.build as all the %() macros are
-       # executed here, while none of them are actually needed.
-       # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
-       safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
+       safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
 
        # TODO: move these to /usr/lib/rpm/macros
        cat > $BUILDER_MACROS <<'EOF'
@@ -605,6 +603,7 @@ minirpm() {
 %releq_kernel_up(n:) ERROR
 %releq_kernel_smp(n:) ERROR
 %releq_kernel(n:) ERROR
+%py_postclean(x:) ERROR
 %kgcc_package ERROR
 %_fontsdir ERROR
 %ruby_version ERROR
@@ -850,8 +849,10 @@ init_builder() {
                        PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
                fi
        else
-               REPO_DIR="."
-               PACKAGE_DIR="."
+               TOP_DIR=$(pwd)
+               PACKAGE_DIR=$TOP_DIR
+               REPO_DIR=$PACKAGE_DIR
+               RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
        fi
        export GIT_WORK_TREE=$PACKAGE_DIR
        export GIT_DIR=$PACKAGE_DIR/.git
@@ -906,7 +907,7 @@ get_spec() {
        fi
 
        cd "$REPO_DIR"
-
+       SPECFILE=$(basename $SPECFILE)
        if [ "$NOCVSSPEC" != "yes" ]; then
                if [ -z "$DEPTH" ]; then
                        if [ -d "$PACKAGE_DIR/.git" ]; then
@@ -957,7 +958,7 @@ get_spec() {
                # add default log format to .gitignore if it is relative to package dir
                if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
                        # substitute known "macros" to glob
-                       local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\|TARGET\),*,g')
+                       local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g')
                        if [ "$logfile" ]; then
                                cvsignore_df "$logfile"
                        fi
@@ -1052,7 +1053,7 @@ src_md5() {
        # use "sources" file from package dir, like vim
        if [ -f sources ]; then
                md5=$(grep -s -v '^#' sources | \
-               grep -E "[      ]$(basename "$1")([     ,]|\$)" | \
+               grep -E "[      *]$(basename "$1")([    ,]|\$)" | \
                sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
                grep -E '^[0-9a-f]{32}$')
 
@@ -1510,50 +1511,61 @@ set_version() {
        " $specfile
 }
 
+# try to upgrade .spec to new version
+# if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
+#
+# return 1: if .spec was updated
+# return 0: no changes to .spec
+# exit 1 in case of error
 try_upgrade() {
-       if [ -n "$TRY_UPGRADE" ]; then
-               local TNOTIFY TNEWVER TOLDVER
-               update_shell_title "build_package: try_upgrade"
+       if [ -z "$TRY_UPGRADE" ]; then
+               return 0
+       fi
 
-               cd "$PACKAGE_DIR"
-               
-               if [ "$UPGRADE_VERSION" ]; then
-                       TNEWVER=$UPGRADE_VERSION
-               else
-                       if [ -n "$FLOAT_VERSION" ]; then
-                               TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
-                       else
-                               TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
-                       fi
+       local TNOTIFY TNEWVER TOLDVER
+       update_shell_title "build_package: try_upgrade"
 
-                       # pldnotify.awk does not set exit codes, but it has match for ERROR
-                       # in output which means so.
-                       if [[ "$TNOTIFY" = *ERROR* ]]; then
-                               echo >&2 "$TNOTIFY"
-                               exit 1
-                       fi
+       cd "$PACKAGE_DIR"
 
-                       TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
+       if [ "$UPGRADE_VERSION" ]; then
+               TNEWVER=$UPGRADE_VERSION
+               echo "Updating spec file to version $TNEWVER"
+       else
+               if [ -n "$FLOAT_VERSION" ]; then
+                       TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
+               else
+                       TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
                fi
 
-               if [ -n "$TNEWVER" ]; then
-                       TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
-                       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
-                       set_release $SPECFILE $PACKAGE_RELEASE 1
-                       set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
-                       parse_spec
-                       if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
-                               echo >&2 "Upgrading version failed, you need to update spec yourself"
-                               exit 1
-                       fi
-                       return 1
+               # pldnotify.awk does not set exit codes, but it has match for ERROR
+               # in output which means so.
+               if [[ "$TNOTIFY" = *ERROR* ]]; then
+                       echo >&2 "$TNOTIFY"
+                       exit 1
                fi
+
+               TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
+               echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
+
+               TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
+       fi
+
+       if [ -z "$TNEWVER" ]; then
+               return 0
+       fi
+
+       if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
+               cp -f $SPECFILE $SPECFILE.bak
+       fi
+       chmod +w $SPECFILE
+       set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
+       set_release $SPECFILE $PACKAGE_RELEASE 1
+       parse_spec
+       if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
+               echo >&2 "Upgrading version failed, you need to update spec yourself"
+               exit 1
        fi
-       return 0
+       return 1
 }
 
 build_package() {
@@ -1599,7 +1611,7 @@ build_package() {
 
        local specdir=$(insert_gitlog $SPECFILE)
        # FIXME: eval here is exactly why?
-       PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE
+       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=$?
        rm -r $specdir
 
@@ -1752,13 +1764,13 @@ run_sub_builder() {
        package_name="${1}"
        update_shell_title "run_sub_builder $package_name"
        #
-       # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
-       # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
+       # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
+       # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
        # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
        # jakby nie bylo tego kawalka kodu.
        #
-       # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
-       #         Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
+       # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
+       #         Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
        #
        #
        # y0shi.
@@ -2080,23 +2092,36 @@ fetch_build_requires()
                fi
 }
 
+init_repository() {
+       local remoterepo=$1
+       local localrepo=$2
+
+       if [ ! -e $localrepo ]; then
+               git clone -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
+               git --git-dir=$localrepo/.git remote set-url --push  $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
+       fi
+}
+
 init_rpm_dir() {
        local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
        local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
        local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
        local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
+       local TEMPLATES=template-specs
        local tmp
 
        echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
        mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
 
        cd "$TOP_DIR"
-       if [ ! -e ../rpm-build-tools ]; then
-               git clone  ${GIT_SERVER}/${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
-       fi
-       for a in adapter builder fetchsrc_request; do
+       init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
+       init_repository projects/$TEMPLATES ../$TEMPLATES
+       for a in adapter builder fetchsrc_request compile repackage; do
                ln -sf ../rpm-build-tools/${a}.sh $a
        done
+       for a in md5; do
+               ln -sf ../rpm-build-tools/${a} $a
+       done
        ln -sf ../rpm-build-tools/mirrors mirrors
        init_builder
 }
@@ -2107,7 +2132,7 @@ mr_proper() {
        DONT_PRINT_REVISION="yes"
 
        # remove spec and sources
-       PATH=$CLEAN_PATH $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $PACKAGE_DIR/$SPECFILE
+       PATH=$CLEAN_PATH $RPMBUILD --clean --rmsource --rmspec --nodeps --define "__urlgetfile() %nil" --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $PACKAGE_DIR/$SPECFILE
        rm -rf $PACKAGE_DIR/{.git,.gitignore}
        rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
 }
@@ -2450,6 +2475,9 @@ else
        NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
 fi
 
+# see time(1) for output format that could be used
+TIME_COMMAND="time -p"
+
 update_shell_title "$COMMAND"
 case "$COMMAND" in
        "show_bconds")
@@ -2564,7 +2592,7 @@ case "$COMMAND" in
                case $? in
                        0)
                                get_files $SOURCES $PATCHES
-                               check_md5 $SOURCES
+                               check_md5 $SOURCES $PATCHES
                                ;;
                        *)
                                NODIST="yes" get_files $SOURCES $PATCHES
This page took 0.046585 seconds and 4 git commands to generate.