From: Elan Ruusamäe Date: Tue, 4 Mar 2014 21:40:47 +0000 (+0200) Subject: doc for try_upgrade, try make it more readable X-Git-Tag: auto/th/rpm-build-tools-4.6-3~6 X-Git-Url: http://git.pld-linux.org/gitweb.cgi?p=packages%2Frpm-build-tools.git;a=commitdiff_plain;h=52a2ef00e8fec0d74192471b727d8f67c8338131 doc for try_upgrade, try make it more readable --- diff --git a/builder.sh b/builder.sh index b997716..72c5f66 100755 --- a/builder.sh +++ b/builder.sh @@ -1510,50 +1510,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 - return 0 + 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 1 } build_package() {