]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
- cleanup as SPECFILE is filename always
[packages/rpm-build-tools.git] / builder.sh
index f7811c7084c811357a04e8bf8b3f3dd0fe3b865d..a379799be718371f338266fa06f3b9466b43e3c7 100644 (file)
 # - 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%% *}
-VERSION="v0.23/$rev"
+VERSION="v0.35/$rev"
 VERSIONSTRING="\
 Build package utility from PLD Linux CVS repository
-$VERSION (C) 1999-2008 Free Penguins".
+$VERSION (C) 1999-2009 Free Penguins".
 
 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
 
@@ -68,6 +69,8 @@ DATE=`date +%Y-%m-%d_%H-%M-%S`
 
 # 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!
 LOGFILE=''
 
@@ -83,6 +86,9 @@ RPMBUILDOPTS=""
 BCOND=""
 GROUP_BCONDS="no"
 
+# create symlinks for tools in PACKAGE_DIR, see get_spec()
+SYMLINK_TOOLS="yes"
+
 PATCHES=""
 SOURCES=""
 ICONS=""
@@ -95,7 +101,7 @@ WGET_RETRIES=${MAX_WGET_RETRIES:-0}
 
 CVS_COMMAND=${CVS_COMMAND:-cvs}
 CVS_FORCE=""
-CVSIGNORE_DF="no"
+CVSIGNORE_DF="yes"
 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
 CVS_SERVER="cvs.pld-linux.org"
 CVSTAG=""
@@ -206,8 +212,7 @@ $CVS_COMMAND --version 2>&1 | grep -q 'CVS-nserver'
 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
 
-run_poldek()
-{
+run_poldek() {
        RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM)
        if [ -n "$LOGFILE" ]; then
                LOG=`eval echo $LOGFILE`
@@ -226,8 +231,7 @@ run_poldek()
 #---------------------------------------------
 # functions
 
-usage()
-{
+usage() {
        if [ -n "$DEBUG" ]; then set -xv; fi
        echo "\
 Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|-ba|--build]
@@ -286,7 +290,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 -nd, --no-distfiles - don't download from distfiles
 -nm, --no-mirrors   - don't download from mirror, if source URL is given,
 -nu, --no-urls      - don't try to download from FTP/HTTP location,
--ns, --no-srcs      - don't download Sources
+-ns, --no-srcs      - don't download Sources/Patches
 -ns0, --no-source0  - don't download Source0
 -nn, --no-net       - don't download anything from the net
 -pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES
@@ -371,7 +375,7 @@ Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|
 depspecname() {
        local package="$1"
 
-       package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g}')
+       package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
        echo "$package"
 }
 
@@ -408,7 +412,7 @@ update_shell_title() {
 # set TARGET from BuildArch: from SPECFILE
 set_spec_target() {
        if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
-               tmp=$(awk '/^BuildArch:/ { print $NF}' $ASSUMED_NAME/$SPECFILE)
+               tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
                if [ "$tmp" ]; then
                                target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
                                TARGET="$tmp"
@@ -536,8 +540,7 @@ rpm_dump() {
        echo "$rpm_dump_cache"
 }
 
-get_icons()
-{
+get_icons() {
        update_shell_title "get icons"
        ICONS=$(awk '/^Icon:/ {print $2}' ${ASSUMED_NAME}/${SPECFILE})
        if [ -z "$ICONS" ]; then
@@ -547,8 +550,7 @@ get_icons()
        rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
 }
 
-parse_spec()
-{
+parse_spec() {
        update_shell_title "parsing specfile"
        if [ -n "$DEBUG" ]; then
                set -x
@@ -561,16 +563,16 @@ parse_spec()
        cd $PACKAGE_DIR
        cache_rpm_dump
 
-       if [ "$NOSRCS" != "yes" ]; then
-               SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
-       fi
-
        if (rpm_dump | grep -qEi ":.*nosource.*1"); then
                FAIL_IF_NO_SOURCES="no"
        fi
 
-       PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
-       ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
+       if [ "$NOSRCS" != "yes" ]; then
+               SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
+               PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
+               ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
+       fi
+
        PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
        PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
        PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
@@ -599,8 +601,7 @@ parse_spec()
        update_shell_title "parse_spec: OK!"
 }
 
-Exit_error()
-{
+Exit_error() {
        if [ -n "$DEBUG" ]; then
                set -x
                set -v
@@ -653,8 +654,7 @@ Exit_error()
        exit 100
 }
 
-init_builder()
-{
+init_builder() {
        if [ -n "$DEBUG" ]; then
                set -x
                set -v
@@ -672,8 +672,7 @@ init_builder()
        __PWD=$(pwd)
 }
 
-get_spec()
-{
+get_spec() {
 
        update_shell_title "get_spec"
 
@@ -684,7 +683,8 @@ get_spec()
 
        cd "$REPO_DIR"
        if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
-               SPECFILE="$(basename $SPECFILE .spec).spec"
+               # XXX: still needed?
+               SPECFILE=$(basename $SPECFILE)
        fi
        if [ "$NOCVSSPEC" != "yes" ]; then
 
@@ -697,6 +697,19 @@ get_spec()
                        cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
                else
                        cvsup -c -d $ASSUMED_NAME "packages/$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
+
+                       # remove Entries.Static -- so 'cvs up' would update all files in a repo
+                       rm "$ASSUMED_NAME/CVS/Entries.Static"
+                       cvsignore_df .cvsignore
+
+                       # create symlinks for tools
+                       if [ "$SYMLINK_TOOLS" != "no" ]; then
+                               for a in dropin md5 adapter builder {relup,compile,repackage,rsync}.sh; do
+                                       [ -f $a ] || continue
+                                       ln -s ../$a $ASSUMED_NAME
+                                       cvsignore_df $a
+                               done
+                       fi
                fi
        fi
 
@@ -713,8 +726,7 @@ get_spec()
        set_spec_target
 }
 
-find_mirror()
-{
+find_mirror() {
        cd "$REPO_DIR"
        local url="$1"
        if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
@@ -740,8 +752,7 @@ find_mirror()
 }
 
 # Warning: unpredictable results if same URL used twice
-src_no ()
-{
+src_no() {
        cd $PACKAGE_DIR
        rpm_dump | \
        grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
@@ -749,8 +760,7 @@ src_no ()
        head -n 1 | xargs
 }
 
-src_md5()
-{
+src_md5() {
        [ "$NO5" = "yes" ] && return
        no=$(src_no "$1")
        [ -z "$no" ] && return
@@ -795,47 +805,42 @@ src_md5()
        fi
 }
 
-distfiles_path ()
-{
+distfiles_path() {
        echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
 }
 
-distfiles_url ()
-{
+distfiles_url() {
        echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
 }
 
-distfiles_attic_url ()
-{
+distfiles_attic_url() {
        echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
 }
 
-good_md5 ()
-{
+good_md5() {
        md5=$(src_md5 "$1")
        [ "$md5" = "" ] || \
        [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
 }
 
-good_size ()
-{
+good_size() {
        size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
        [ -n "$size" -a "$size" -gt 0 ]
 }
 
-cvsignore_df ()
-{
+cvsignore_df() {
        if [ "$CVSIGNORE_DF" != "yes" ]; then
                return
        fi
        cvsignore=${PACKAGE_DIR}/.cvsignore
-       if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
+
+       # add only if not yet there
+       if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
                echo "$1" >> $cvsignore
        fi
 }
 
-cvsup()
-{
+cvsup() {
        update_shell_title "cvsup"
        local OPTIONS="up "
 
@@ -884,8 +889,7 @@ cvsup()
 }
 
 # returns true if "$1" is ftp, http or https protocol url
-is_url()
-{
+is_url() {
        case "$1" in
        ftp://*|http://*|https://*)
                return 0
@@ -894,8 +898,7 @@ is_url()
        return 1
 }
 
-update_md5()
-{
+update_md5() {
        if [ $# -eq 0 ]; then
                return
        fi
@@ -957,8 +960,7 @@ update_md5()
        done
 }
 
-check_md5()
-{
+check_md5() {
        [ "$NO5" = "yes" ] && return
 
        update_shell_title "check md5"
@@ -974,8 +976,7 @@ check_md5()
        done
 }
 
-get_files()
-{
+get_files() {
        update_shell_title "get_files"
 
        if [ -n "$DEBUG" ]; then
@@ -1015,13 +1016,13 @@ get_files()
                                if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
                                        echo "Warning: no URL given for $i"
                                fi
+                               target="$fp"
 
                                if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
                                        if good_md5 "$i" && good_size "$i"; then
                                                echo "$fp having proper md5sum already exists"
                                                continue
                                        fi
-                                       target="$fp"
 
                                        # optionally prefer mirror over distfiles if there's mirror
                                        # TODO: build url list and then try each url from the list
@@ -1073,6 +1074,7 @@ get_files()
                                                                update_shell_title "${GETURI2%% *}: $url_attic"
                                                                ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
                                                        fi
+                                                       test -s "$target" || rm -f "$target"
                                                fi
                                        fi
 
@@ -1099,11 +1101,12 @@ get_files()
                                                im="$i"
                                        fi
                                        update_shell_title "${GETURI%% *}: $im"
-                                       ${GETURI} "$im" || \
+                                       ${GETURI} "$im" ${OUTFILEOPT} "$target" || \
                                        if [ "`echo $im | grep -E 'ftp://'`" ]; then
                                                update_shell_title "${GETURI2%% *}: $im"
-                                               ${GETURI2} "$im"
+                                               ${GETURI2} "$im" ${OUTFILEOPT} "$target"
                                        fi
+                                       test -s "$target" || rm -f "$target"
                                fi
 
                                if [ "$cvsup" = 1 ]; then
@@ -1208,8 +1211,7 @@ is_tag_a_branch() {
        return $?
 }
 
-tag_files()
-{
+tag_files() {
        TAG_FILES="$@"
 
        if [ -n "$DEBUG" ]; then
@@ -1290,8 +1292,7 @@ tag_files()
        fi
 }
 
-branch_files()
-{
+branch_files() {
        TAG=$1
        echo "CVS branch tag: $TAG"
        shift
@@ -1347,9 +1348,7 @@ check_buildarch() {
        fi
 }
 
-
-build_package()
-{
+build_package() {
        update_shell_title "build_package"
        if [ -n "$DEBUG" ]; then
                set -x
@@ -1443,19 +1442,16 @@ build_package()
        unset BUILD_SWITCH
 }
 
-nourl()
-{
+nourl() {
        echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
 }
 
-install_required_packages()
-{
+install_required_packages() {
        run_poldek -vi $1
        return $?
 }
 
-find_spec_bcond() {
-       # originally from /usr/lib/rpm/find-spec-bcond
+find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
        local SPEC="$1"
        awk -F"\n" '
        /^%changelog/ { exit }
@@ -1563,8 +1559,7 @@ set_bconds_values() {
        done
 }
 
-run_sub_builder()
-{
+run_sub_builder() {
        package_name="${1}"
        update_shell_title "run_sub_builder $package_name"
        #
@@ -1599,8 +1594,7 @@ run_sub_builder()
        NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
 }
 
-spawn_sub_builder()
-{
+spawn_sub_builder() {
        package_name="${1}"
        update_shell_title "spawn_sub_builder $package_name"
 
@@ -1621,8 +1615,7 @@ spawn_sub_builder()
        ./builder ${sub_builder_opts} "$@"
 }
 
-remove_build_requires()
-{
+remove_build_requires() {
        if [ "$INSTALLED_PACKAGES" != "" ]; then
                case "$REMOVE_BUILD_REQUIRES" in
                        "force")
@@ -1640,8 +1633,7 @@ remove_build_requires()
        fi
 }
 
-display_bconds()
-{
+display_bconds() {
        if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
                if [ "$BCOND" ]; then
                        echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
@@ -1654,8 +1646,7 @@ display_bconds()
        fi
 }
 
-display_branches()
-{
+display_branches() {
        if [ "$NOCVSSPEC" != "yes" ]; then
                echo -ne "Available branches: "
                $CVS_COMMAND status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
@@ -1665,8 +1656,7 @@ display_branches()
 # checks a given list of packages/files/provides agains current rpmdb.
 # outputs all dependencies which current rpmdb doesn't satisfy.
 # input can be either STDIN or parameters
-_rpm_prov_check()
-{
+_rpm_prov_check() {
        local DEPS
 
        if [ $# -gt 0 ]; then
@@ -1687,8 +1677,7 @@ _rpm_prov_check()
 # checks if given package/files/provides exists in rpmdb.
 # input can be either stdin or parameters
 # returns packages which are present in the rpmdb
-_rpm_cnfl_check()
-{
+_rpm_cnfl_check() {
        local DEPS
 
        if [ $# -gt 0 ]; then
@@ -1904,7 +1893,7 @@ init_rpm_dir() {
        echo "Initialising rpm directories to $TOP_DIR from $CVSROOT"
        mkdir -p $TOP_DIR/{RPMS,BUILD,SRPMS}
        cd $TOP_DIR
-       $CVS_COMMAND -d $CVSROOT co packages/{.cvsignore,dropin,mirrors,md5,adapter{,.awk},fetchsrc_request,builder,{relup,compile,repackage}.sh}
+       $CVS_COMMAND -d $CVSROOT co packages/{.cvsignore,rpm.groups,dropin,mirrors,md5,adapter{,.awk},fetchsrc_request,builder,{relup,compile,repackage}.sh}
 
        init_builder
 
@@ -1912,7 +1901,7 @@ init_rpm_dir() {
        echo "- run cvs co SPECS"
 
        echo "To checkout *all* packages:"
-       echo "- run cvs up in $TOP_DIR/packages dir"
+       echo "- run cvs up -dP in $TOP_DIR/packages dir"
 
        echo ""
        echo "To commit with your developer account:"
@@ -2224,19 +2213,21 @@ while [ $# -gt 0 ]; do
                        Exit_error err_invalid_cmdline "$1"
                        ;;
                *)
-                       SPECFILE="${1}"
+                       SPECFILE=$1; shift
                        # check if specname was passed as specname:cvstag
                        if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
                                CVSTAG="${SPECFILE##*:}"
                                SPECFILE="${SPECFILE%%:*}"
                        fi
+                       # always have SPECFILE ending with .spec extension
+                       SPECFILE=${SPECFILE%%.spec}.spec
                        ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
-                       shift
        esac
 done
 
-if [ -f CVS/Entries ] && [ -z "$CVSTAG" ]; then
-       CVSTAG=$(awk -vSPECFILE=$(basename ${SPECFILE%.spec}.spec) -F/ '$2 == SPECFILE && $6 ~ /^T/{print substr($6, 2)}' CVS/Entries)
+[ -d "$ASSUMED_NAME" ] && CVS_ENTRIES="$ASSUMED_NAME/CVS/Entries" || CVS_ENTRIES="CVS/Entries"
+if [ -f "$CVS_ENTRIES" ] && [ -z "$CVSTAG" ]; then
+       CVSTAG=$(awk -vSPECFILE=$(basename $SPECFILE) -F/ '$2 == SPECFILE && $6 ~ /^T/{print substr($6, 2)}' ${CVS_ENTRIES})
        if [ "$CVSTAG" ]; then
                echo >&2 "builder: Sticky tag $CVSTAG active. Use -r TAGNAME to override."
        fi
This page took 0.074156 seconds and 4 git commands to generate.