]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
builder: use abs paths for --noinit fully to work
[packages/rpm-build-tools.git] / builder.sh
index 6cb8678116764c9506475d891d07fef627e4dbfe..0c7c8aa8a268a72d1481c2c6664beaa98a9b87a8 100755 (executable)
@@ -423,6 +423,8 @@ Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version]  [
 -np <patchnumber>,
 --nopatch <patchnumber>
                     - abort instead of applying patch <patchnumber>
+--noinit
+                    - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
 --show-bconds       - show available conditional builds, which can be used
                     - with --with and/or --without switches.
 --show-bcond-args   - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
@@ -463,12 +465,25 @@ insert_gitlog() {
        # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c#l31
        # 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 | while read sha1; do
+       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'
        done > $gitlog
-       LC_ALL=C gawk '/^\* /{printf("* %s %s\n", strftime("%a %b %d %Y", $2), substr($0, length($1)+length($2)+length($3)+4)); next}{print}' $gitlog > $speclog
+
+       # add link to full git logs
+       local giturl="http://git.pld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
+       if [ -n "$CVSTAG" ]; then
+               giturl="$giturl;h=$CVSTAG"
+       fi
+       local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
+       LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
+               printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
+               print;
+               exit
+       }' > $speclog
+
+       LC_ALL=C gawk '/^\* /{printf("* %s %s\n", strftime("%a %b %d %Y", $2), substr($0, length($1)+length($2)+length($3)+4)); next}{print}' $gitlog >> $speclog
        sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
                        a%changelog
                        r $speclog
@@ -521,9 +536,9 @@ update_shell_title() {
 # set TARGET from BuildArch: from SPECFILE
 set_spec_target() {
        if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
-               tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
+               local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
                if [ "$tmp" ]; then
-                               target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
+                               local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
                                TARGET="$tmp"
                                case "$RPMBUILD" in
                                "rpmbuild")
@@ -614,7 +629,7 @@ cache_rpm_dump() {
 
        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 $SPECFILE)
+               rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
        else
                update_shell_title "cache_rpm_dump using rpmbuild command"
                local rpm_dump
@@ -772,6 +787,9 @@ Exit_error() {
                        remove_build_requires
                        echo >&2 "Error: problem with remote (${2})"
                        exit 13 ;;
+               "err_no_checkut" )
+                       echo >&2 "Error: cannot checkout $2"
+                       exit 14 ;;
                "err_not_implemented" )
                        remove_build_requires
                        echo >&2 "Error: functionality not yet imlemented"
@@ -859,18 +877,14 @@ get_spec() {
        fi
 
        cd "$REPO_DIR"
-       if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
-               # XXX: still needed?
-               SPECFILE=$(basename $SPECFILE)
-       fi
 
        if [ "$NOCVSSPEC" != "yes" ]; then
                if [ -z "$DEPTH" ]; then
-                       if [ -d "$ASSUMED_NAME/.git" ]; then
+                       if [ -d "$PACKAGE_DIR/.git" ]; then
                                git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
                        elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
-                               if [ ! -r "$ASSUMED_NAME/$SPECFILE" ]; then
-                                       echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
+                               if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
+                                       echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
                                        exit 101
                                fi
                                Exit_error err_not_implemented
@@ -879,7 +893,7 @@ get_spec() {
                                        unset GIT_WORK_TREE
                                        git clone  -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
                                                # softfail if new package, i.e not yet added to PLD rep
-                                               [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo
+                                               [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
                                                echo "Warning: package not in CVS - assuming new package"
                                                NOCVSSPEC="yes"
                                        }
@@ -888,9 +902,9 @@ get_spec() {
                                )
                        fi
                else
-                       if [ ! -d "$ASSUMED_NAME/.git" ]; then
-                               if [ ! -d "$ASSUMED_NAME" ]; then
-                                       mkdir $ASSUMED_NAME
+                       if [ ! -d "$PACKAGE_DIR/.git" ]; then
+                               if [ ! -d "$PACKAGE_DIR" ]; then
+                                       install -d $PACKAGE_DIR
                                fi
                                git init
                                git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
@@ -914,43 +928,50 @@ 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\),*,g')
+                       local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\|TARGET\),*,g')
                        if [ "$logfile" ]; then
                                cvsignore_df "$logfile"
                        fi
                fi
 
                # create symlinks for tools
-               if [ "$SYMLINK_TOOLS" != "no" -a -d "$ASSUMED_NAME" ]; then
+               if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
                        for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
                                # skip tools that don't exist in top dir
                                [ -f $a ] || continue
                                # skip tools that already exist
-                               [ -f $ASSUMED_NAME/$a ] && continue
-                               ln -s ../$a $ASSUMED_NAME
+                               [ -f $PACKAGE_DIR/$a ] && continue
+                               ln -s ../$a $PACKAGE_DIR
                                cvsignore_df $a
                        done
                fi
        fi
 
        if [ -n "$CVSTAG" ]; then
-               git checkout "$CVSTAG" -- 2>/dev/null || git checkout -t "${REMOTE_PLD}/$CVSTAG" > /dev/null || exit
-               git symbolic-ref -q HEAD > /dev/null &&
-                       git merge '@{u}'
+               if git rev-parse --verify -q "$CVSTAG"; then
+                       git checkout "$CVSTAG" --
+               elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
+                       git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
+               fi
+               if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
+                       Exit_error "err_no_checkut" "$CVSTAG"
+               fi
+                       git merge --ff-only '@{u}'
+               git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
                if [ -n "$CVSDATE" ]; then
                        git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
                fi
        fi
 
-       if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
+       if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
                Exit_error err_no_spec_in_repo
        fi
 
        if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
-               chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE
+               chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
        fi
        unset OPTIONS
-       [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE
+       [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
 
        set_spec_target
 }
@@ -959,7 +980,7 @@ find_mirror() {
        cd "$REPO_DIR"
        local url="$1"
        if [ ! -f "mirrors"  ] ; then
-               ln -s rpm-build-tools/mirrors .
+               ln -s ../rpm-build-tools/mirrors .
        fi
 
        IFS="|"
@@ -1222,10 +1243,6 @@ get_files() {
                                                update_shell_title "${GETLOCAL%% *}: $url"
                                                ${GETLOCAL} $url $target
                                        else
-                                               if [ -z "$NOMIRRORS" ]; then
-                                                       url=$(find_mirror "$url")
-                                               fi
-
                                                local uri=${url}
                                                # make shorter message for distfiles urls
                                                if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
@@ -1248,9 +1265,6 @@ get_files() {
                                                        update_shell_title "${GETLOCAL%% *}: $url_attic"
                                                        ${GETLOCAL} $url_attic $target
                                                else
-                                                       if [ -z "$NOMIRRORS" ]; then
-                                                               url_attic=$(find_mirror "$url_attic")
-                                                       fi
                                                        update_shell_title "${GETURI%% *}: $url_attic"
                                                        ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
                                                        if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
@@ -1800,7 +1814,7 @@ display_bconds() {
 
 display_branches() {
        echo -n "Available branches: "
-       git branch -r | grep "^  ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
+       git branch -r 2>/dev/null | grep "^  ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
 }
 
 # checks a given list of packages/files/provides agains current rpmdb.
@@ -2490,12 +2504,15 @@ case "$COMMAND" in
                # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
                if [ -n "$TEST_TAG" ]; then
                        local TAGVER=`make_tagver`
-                       tag_exist $TAGVER
+                       tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
                        # check also tags created in CVS
-                       tag_exist $(echo $TAGVER | tr '[.@]' '[_#]')
+                       local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
+                       local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
+                       tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
+                               || Exit_error err_tag_exists $TAGVER_CVS
                        # - do not allow to build from HEAD when XX-branch exists
                        TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
-                       if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
+                       if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a  "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
                                TAG_BRANCH="${TREE_PREFIX}-branch"
                                if [ -n "$DEPTH" ]; then
                                        cmd_branches="git ls-remote --heads"
This page took 0.063963 seconds and 4 git commands to generate.