]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - builder.sh
builder: install deps with -g -R as well
[packages/rpm-build-tools.git] / builder.sh
index 4e3748fc86a04a1e9c9c8bb03cc2fb2d8bd59424..2d577eb7847b0fccbcf693c5a563d8fc60606478 100755 (executable)
@@ -38,7 +38,7 @@ 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-2015 Free Penguins".
+$VERSION (C) 1999-2016 Free Penguins".
 
 CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
 
@@ -447,7 +447,8 @@ Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version]  [
                       constructions. Set GROUP_BCONDS to yes to make use of it.
 --target <platform>, --target=<platform>
                     - build for platform <platform>.
---init-rpm-dir      - initialize ~/rpm directory structure
+--init-rpm-dir, --init
+                    - initialize ~/rpm directory structure
 "
 }
 
@@ -463,7 +464,7 @@ tempdir() {
 }
 
 # inserts git log instead of %changelog
-# outputs name of modified file created by tempfile
+# @output directory containing modified specfile
 insert_gitlog() {
        local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
 
@@ -483,7 +484,7 @@ insert_gitlog() {
        done > $gitlog
 
        # add link to full git logs
-       local giturl="http://git.pld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
+       local giturl="http://git.pld-linux.org/?p=packages/${SPECFILE%.spec}.git;a=log"
        if [ -n "$CVSTAG" ]; then
                giturl="$giturl;h=$CVSTAG"
        fi
@@ -554,7 +555,7 @@ depspecname() {
 }
 
 update_shell_title() {
-       [ -t 1 ] || return
+       [ -t 2 ] || return
        local len=${COLUMNS:-80}
        local msg="$(echo "$*" | cut -c-$len)"
 
@@ -656,7 +657,7 @@ minirpm() {
 %remove_etc_shells(p) %{p:<lua>}
 %lua_add_etc_shells()  %{nil}
 %lua_remove_etc_shells() %{nil}
-%required_jdk %{nil}
+%required_jdk jdk
 %buildrequires_jdk %{nil}
 %pear_package_print_optionalpackages %{nil}
 EOF
@@ -805,7 +806,11 @@ Exit_error() {
                        exit 2 ;;
                "err_no_spec_in_repo" )
                        remove_build_requires
-                       echo >&2 "Error: spec file not stored in PLD repo."
+                       echo >&2 "Error: spec file not stored in repository."
+                       if [ -n "$2" ]; then
+                               echo >&2 "Tried: $2"
+                       fi
+
                        exit 3 ;;
                "err_no_source_in_repo" )
                        remove_build_requires
@@ -918,10 +923,17 @@ create_git_repo() {
        fi
        [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
        ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
+       (
+       set -e
        git init
-       git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git && \
-               git remote set-url --push  $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} \
-               || Exit_error err_remote_problem $REMOTE_PLD
+       git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
+       git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
+
+       git config --local push.default current
+       git config --local branch.master.remote $REMOTE_PLD
+       git config --local branch.master.merge refs/heads/master
+       )
+       test $? = 0 || Exit_error err_remote_problem $REMOTE_PLD
 }
 
 get_spec() {
@@ -954,7 +966,10 @@ get_spec() {
                                                echo "Warning: package not in CVS - assuming new package"
                                                NOCVSSPEC="yes"
                                        }
-                                       git config --local --add "remote.$REMOTE_PLD.fetch"  'refs/notes/*:refs/notes/*'
+                                       git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
+                                       git config --local --add "remote.$REMOTE_PLD.push" 'refs/notes/*:refs/notes/*'
+                                       git config --local --add "remote.$REMOTE_PLD.push" HEAD
+                                       git config --local push.default current
                                        git remote set-url --push  $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
                                )
                        fi
@@ -965,7 +980,10 @@ get_spec() {
                                fi
                                git init
                                git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
-                               git config --local --add "remote.$REMOTE_PLD.fetch"  'refs/notes/*:refs/notes/*'
+                               git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
+                               git config --local --add "remote.$REMOTE_PLD.push" 'refs/heads/*:refs/remotes/origin/*'
+                               git config --local --add "remote.$REMOTE_PLD.push" HEAD
+                               git config --local push.default current
                                git remote set-url --push  $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
                                CVSTAG=${CVSTAG:-"master"}
                        fi
@@ -993,7 +1011,7 @@ get_spec() {
 
                # create symlinks for tools
                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
+                       for a in dropin md5 builder {relup,compile,repackage,rsync,pearize}.sh; do
                                # skip tools that don't exist in top dir
                                [ -f $a ] || continue
                                # skip tools that already exist
@@ -1021,7 +1039,7 @@ get_spec() {
        fi
 
        if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
-               Exit_error err_no_spec_in_repo
+               Exit_error err_no_spec_in_repo "$PACKAGE_DIR/$SPECFILE"
        fi
 
        if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
@@ -1033,15 +1051,22 @@ get_spec() {
        set_spec_target
 }
 
+# find mirrors in this order. first match wins:
+# - package dir (~/rpm/packages/foo)
+# - repository dir (~/rpm/packages)
+# - tools dir dir (~/rpm/packages/rpm-build-tools)
 find_mirror() {
-       cd "$REPO_DIR"
        local url="$1"
-       if [ ! -f "mirrors"  ] ; then
-               ln -s ../rpm-build-tools/mirrors .
-       fi
 
-       IFS="|"
+       update_shell_title "find_mirror[$url][$REPO_DIR]"
+
+       # NOTE: as while loop runs in subshell,
+       # we use exit 2 to indicate  that the match was found
+       # otherwise we end up outputing mirror url and origin url.
+
        local origin mirror name rest ol prefix
+       IFS="|"
+       cat "$PACKAGE_DIR/mirrors" "$REPO_DIR/mirrors" "$REPO_DIR/../rpm-build-tools/mirrors" /dev/null 2>/dev/null | \
        while read origin mirror name rest; do
                # skip comments and empty lines
                if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
@@ -1052,10 +1077,9 @@ find_mirror() {
                if [ "$prefix" = "$origin" ] ; then
                        suffix=$(echo "$url" | cut -b $((ol+1))-)
                        echo -n "$mirror$suffix"
-                       return 0
+                       exit 2
                fi
-       done < mirrors
-       echo "$url"
+       done && echo "$url"
 }
 
 # Warning: unpredictable results if same URL used twice
@@ -1138,7 +1162,7 @@ cvsignore_df() {
        if [ "$CVSIGNORE_DF" != "yes" ]; then
                return
        fi
-       cvsignore=${PACKAGE_DIR}/.gitignore
+       local cvsignore=${PACKAGE_DIR}/.git/info/exclude
 
        # add only if not yet there
        if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
@@ -1559,12 +1583,12 @@ try_upgrade() {
                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
+                       TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
                else
-                       TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
+                       TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
                fi
 
-               # pldnotify.awk does not set exit codes, but it has match for ERROR
+               # pldnotify does not set exit codes, but it has match for ERROR
                # in output which means so.
                if [[ "$TNOTIFY" = *ERROR* ]]; then
                        echo >&2 "$TNOTIFY"
@@ -1636,6 +1660,17 @@ build_package() {
                fi
        fi
 
+       # unset these, should not be exposed to builder shell!
+       unset GIT_WORK_TREE GIT_DIR
+       # these are set by jenkins
+       unset GIT_PREVIOUS_COMMIT GIT_URL GIT_PREVIOUS_SUCCESSFUL_COMMIT GIT_BRANCH GIT_COMMIT
+       # this may be set by user
+       unset GIT_SSH
+       # may be set by user
+       unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
+       # fail if something still set
+       env | grep ^GIT_ && Exit_error err_build_fail
+
        local specdir=$(insert_gitlog $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
@@ -1828,7 +1863,7 @@ run_sub_builder() {
 # this requires following sudo rules:
 # - poldek --noask --caplookup -uG
 poldek_install() {
-       LANG=C $POLDEK_CMD --noask --caplookup -uG "$@"
+       LANG=C $POLDEK_CMD --noask --caplookup --uniq -uG "$@"
 }
 
 # install packages
@@ -1928,21 +1963,21 @@ display_branches() {
 # outputs all dependencies which current rpmdb doesn't satisfy.
 # input can be either STDIN or parameters
 _rpm_prov_check() {
-       local DEPS
+       local deps out
 
        if [ $# -gt 0 ]; then
-               DEPS="$@"
+               deps="$@"
        else
-               DEPS=$(cat)
+               deps=$(cat)
        fi
 
-       DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
+       out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1)
 
        # packages
-       echo "$DEPS" | awk '/^no package provides/ { print $NF }'
+       echo "$out" | awk '/^no package provides/ { print $NF }'
 
        # other deps (files)
-       echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
+       echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p'
 }
 
 # checks if given package/files/provides exists in rpmdb.
@@ -1965,21 +2000,21 @@ install_build_requires_rpmdeps() {
        local DEPS CNFL
        if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
                # TODO: Conflicts list doesn't check versions
-               CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
-               DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
+               CNFL=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
+               DEPS=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
        fi
        if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
-               CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
-               DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
+               CNFL=$(eval rpm -q --specsrpm --conflicts $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
+               DEPS=$(eval rpm -q --specsrpm --requires $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
        fi
 
        if [ -n "$CNFL" ]; then
-               echo "Uninstall conflicting packages ($CNFL):"
+               echo "Uninstall conflicting packages: $CNFL"
                uninstall_packages $CNFL
        fi
 
        if [ -n "$DEPS" ]; then
-               echo "Install dependencies ($DEPS):"
+               echo "Install dependencies: $DEPS"
                install_packages $DEPS
        fi
 }
@@ -2023,7 +2058,7 @@ init_rpm_dir() {
        cd "$TOP_DIR"
        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
+       for a in builder fetchsrc_request compile repackage; do
                ln -sf ../rpm-build-tools/${a}.sh $a
        done
        for a in md5; do
@@ -2052,6 +2087,11 @@ if [ $# = 0 ]; then
        exit 1
 fi
 
+# stuff global $BUILDER_OPTS from env as args
+if [ "$BUILDER_OPTS" ]; then
+       set -- "$BUILDER_OPTS" "$@"
+fi
+
 while [ $# -gt 0 ]; do
        case "${1}" in
                -4|-6)
@@ -2285,7 +2325,7 @@ while [ $# -gt 0 ]; do
                -Upi | --update-poldek-indexes )
                        UPDATE_POLDEK_INDEXES="yes"
                        shift ;;
-               --init-rpm-dir)
+               --init-rpm-dir|--init)
                        COMMAND="init_rpm_dir"
                        shift ;;
                -u | --try-upgrade )
@@ -2310,7 +2350,7 @@ while [ $# -gt 0 ]; do
                        ;;
                --alt_kernel)
                        shift
-                       RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
+                       RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\""
                        shift
                        ;;
                --short-circuit)
@@ -2559,6 +2599,7 @@ case "$COMMAND" in
                fi
                get_files $SOURCES $PATCHES
                check_md5 $SOURCES
+               fetch_build_requires
                ;;
        "update_md5" )
                init_builder
This page took 0.076643 seconds and 4 git commands to generate.