X-Git-Url: https://git.tld-linux.org/?p=packages%2Frpm-build-tools.git;a=blobdiff_plain;f=builder.sh;h=9f62964809ea7b71f016c3ccb2e6d6468386b955;hp=b3824f1b1918d15e6fb643c263d076f5d67d9759;hb=6ad2ec22221129d9f81a6a6504a57002102c28d6;hpb=d8b95287a2b506bd9be948a5edef8a7b0646f65b diff --git a/builder.sh b/builder.sh index b3824f1..9f62964 100755 --- a/builder.sh +++ b/builder.sh @@ -39,9 +39,9 @@ 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-2013 Free Penguins". -PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin" +CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin" # required rpm-build-macros RPM_MACROS_VER=1.534 @@ -68,7 +68,7 @@ ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"} USEDIGEST= # user agent when fetching files -USER_AGENT="PLD/Builder($VERSION)" +USER_AGENT="TLD/Builder($VERSION)" # It can be used i.e. in log file naming. # See LOGFILE example. @@ -84,6 +84,10 @@ TARGET=$(rpm -E %{_target}) # Yes, you can use variable name! Note _single_ quotes! LOGFILE='' +# use teeboth Perl wrapper +# temporary option to disable if broken +USE_TEEBOTH=no + LOGDIR="" LOGDIROK="" LOGDIRFAIL="" @@ -115,9 +119,12 @@ PARALLEL_DOWNLOADS=10 WGET_RETRIES=${MAX_WGET_RETRIES:-0} +# rsync repository with git refs of packages +PKGREVS_URL="http://pkgrevs.tld-linux.org" + # TLD git/df config TLD_GIT_SERVER="git://git.tld-linux.org" -TLD_GIT_PUSH="git@git.tld-linux.org" +TLD_GIT_PUSH="git@git.tld-linux.org:7272" TLD_PACKAGES_DIR="packages" TLD_DISTFILES_SERVER="://df.tld-linux.org" TLD_ATTICDISTFILES_SERVER="" @@ -255,6 +262,7 @@ fi POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/" POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask" +# TODO: add teeboth run_poldek() { RES_FILE=$(tempfile) if [ -n "$LOGFILE" ]; then @@ -263,6 +271,7 @@ run_poldek() { echo "LASTLOG=$LOG" > $LASTLOG_FILE fi (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG + # FIXME $exit_pldk undefined return $exit_pldk else (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null @@ -297,6 +306,10 @@ download_lftp() { usage() { if [ -n "$DEBUG" ]; then set -xv; fi +# NOTE: +# to make this output parseable by bash-completion _parse_help() +# if the line contains short and long option, it will take only the long option +# but if you want both being completed, put the short option to separate line echo "\ Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build] [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade] @@ -307,48 +320,55 @@ Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [ [{-Tp|--tag-prefix} ] [{-tt|--test-tag}] [-nu|--no-urls] [-v|--verbose] [--opts ] [--short-circuit] [--show-bconds] [--with/--without ] [--define ] +[--git-pld|--git-tld] [--pkgrev] [-lp] [.spec][:tag] --4 - force ipv4 when transferring files --5, --update-md5 - update md5 comments in spec, implies -nd -ncs --6 - force ipv6 when transferring files --a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs +-4 - force IPv4 when transferring files +-6 - force IPv6 when transferring files +-5, +--update-md5 - update md5 comments in spec, implies -nd -ncs +-a5, +--add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs --all-branches - make shallow fetch of all branches; --depth required -n5, --no-md5 - ignore md5 comments in spec -D, --debug - enable builder script debugging mode, -debug - produce rpm debug package (same as --opts -debug) -V, --version - output builder version string --short-version - output builder short version --a, --add_vcs - try add new package to PLD repo. --b, -ba, --build - get all files from PLD repo or HTTP/FTP and build package +-a - try add new package to PLD repo. +-b, +-ba + - get all files from PLD repo or HTTP/FTP and build package from .spec, --bb, --build-binary - get all files from PLD repo or HTTP/FTP and build binary +-bb - get all files from PLD repo or HTTP/FTP and build binary only package from .spec, --bp, --build-prep - execute the %prep phase of .spec, +-bp - execute the %prep phase of .spec, -bc - execute the %build phase of .spec, -bi - execute the %install phase of .spec -bl - execute the %files phase of .spec --bs, --build-source - get all files from PLD repo or HTTP/FTP and only pack +-bs - get all files from PLD repo or HTTP/FTP and only pack them into src.rpm, --short-circuit - short-circuit build -B, --branch - add branch --c, --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands. +-c, +--clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands. may be used with building process. -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES, SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building. -cf, --cvs-force - use -f when tagging ---define +--define ' ' - define a macro with value , --depth - make shallow fetch --alt_kernel - same as --define 'alt_kernel ' --nodeps - rpm won't check any dependences --g, --get - get .spec and all related files from PLD repo - or HTTP/FTP, +-g +--get - get .spec and all related files from PLD repo -h, --help - this message, --jN, -j N - set %_smp_mflags to propagate concurrent jobs ---ftp, --http - use ftp or http protocol to access distfiles server --l , --logtofile +-j N - set %_smp_mflags to propagate concurrent jobs +--ftp - use FTP protocol to access distfiles server +--http - use HTTP protocol to access distfiles server +-l , --logtofile= - log all to file, -ncs, --no-cvs-specs - don't pull from PLD repo @@ -358,7 +378,7 @@ Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [ -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 --pN, -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS) +-p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS) -pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES --no-init - don't initialize builder paths (SPECS and SOURCES) @@ -370,8 +390,7 @@ Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [ --date yyyy-mm-dd - build package using resources from specified date, -r , --cvstag - build package using resources from specified branch/tag, --A - build package using master branch as any sticky - tags/branch/date being reset. +-A - build package using master branch as any sticky tags/branch/date being reset. -R, --fetch-build-requires - fetch what is BuildRequired, -RB, --remove-build-requires @@ -381,33 +400,32 @@ Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [ - remove all you fetched with -R or --fetch-build-requires remember, this option works without confirmation, -sd, --source-distfiles - - list sources available from distfiles (intended for - offline operations; does not work when Icon field is - present but icon file is absent), + - list sources available from distfiles (intended for offline + operations; does not work when Icon field is present + but icon file is absent), -sc, --source-cvs - list sources available from PLD repo -sdp, --source-distfiles-paths - list sources available from distfiles - - paths relative to distfiles directory (intended for - offline operations; does not work when Icon field is - present but icon file is absent), + paths relative to distfiles directory (intended for offline + operations; does not work when Icon field is present + but icon file is absent), -sf, --source-files - list sources - bare filenames (intended for offline operations; does not work when Icon field is present but icon file is absent), -lsp, --source-paths - - list sources - filenames with full local paths (intended - for offline operations; does not work when Icon field is - present but icon file is absent), + - list sources - filenames with full local paths (intended for + offline operations; does not work when Icon field is present + but icon file is absent), -su, --source-urls - list urls - urls to sources and patches - intended for copying urls with spec with lots of macros - in urls + intended for copying urls with spec with lots of macros in urls -T , --tag - add git tag for files, -Tvs, --tag-version-stable - add git tags STABLE and NAME-VERSION-RELEASE for files, -Ts, --tag-stable - add git tag STABLE for files, --Tv, --tag-version - - add git tag NAME-VERSION-RELEASE for files, +-Tv, +--tag-version - add git tag NAME-VERSION-RELEASE for files, -Tp, --tag-prefix - add to NAME-VERSION-RELEASE tags, -tt, --test-tag @@ -420,24 +438,27 @@ Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [ - as above, but allow float version php-pear-Services_Digg/ --upgrade-version - upgrade to specified version in try-upgrade --U, --update - refetch sources, don't use distfiles, and update md5 - comments +-U, --update - refetch sources, don't use distfiles, and update md5 comments -Upi, --update-poldek-indexes - refresh or make poldek package index files. --sp, --skip-patch +-sp , +--skip-patch - don't apply . may be repeated. --np, --nopatch +-np , +--nopatch - abort instead of applying patch +--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. In other words, the output is - parseable by scripts. +--show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script. + In other words, the output is parseable by scripts. --show-avail-bconds - show available bconds ---with/--without +--with , +--without - conditional build package depending on %_with_/ %_without_ macro switch. You may now use - --with feat1 feat2 --without feat3 feat4 --with feat5 + --with feat1 feat2 feat3 --without feat4 feat5 --with feat6 constructions. Set GROUP_BCONDS to yes to make use of it. --target , --target= - build for platform . @@ -445,16 +466,19 @@ Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [ --git-pld - force use of PLD git and distfiles --git-tld - force use of TLD git and distfiles (note: it will fall back to PLD git/df if package doesn't exist in TLD git) +--pkgrev - save git revision of package being built into pkgrevs + (note: only official TLD source builders are allowed to do so) +-lp - list pkgrevs for specified package " } # create tempfile. as secure as possible tempfile() { - mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$ + mktemp --tmpdir -t builder.$PACKAGE_NAME.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$ } tempdir() { - mktemp -d builder.XXXXXX + mktemp --tmpdir -d builder.$PACKAGE_NAME.XXXXXX } # inserts git log instead of %changelog @@ -468,15 +492,28 @@ 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 9370900 - git rev-list -${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 1>/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 - 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.tld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log" + if [ -n "$CVSTAG" ]; then + giturl="$giturl;h=$CVSTAG" + fi + local gitauthor="TLD Linux " + 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 @@ -486,6 +523,29 @@ insert_gitlog() { echo $specdir } +# @param string logfile +# @param varargs... commands to execute +teeboth() { + local rc + # use teeboth from toys/cleanbuild, if available and enabled + if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then + $APPDIR/teeboth "$@" + rc=$? + else + local efile rc logfile=$1; shift + if [ "$logfile" ]; then + efile=$(tempfile) + { "$@" 2>&1; echo $? > $efile; } | tee $logfile + rc=$(< $efile) + rm -f $efile + else + "$@" + rc=$? + fi + fi + return $rc +} + # change dependency to specname # common changes: # - perl(Package::Name) -> perl-Package-Name @@ -529,9 +589,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") @@ -569,6 +629,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 @@ -611,7 +672,7 @@ EOF %_sourcedir ./ EOF fi - eval $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1 + eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1 } cache_rpm_dump() { @@ -622,7 +683,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 @@ -780,6 +841,15 @@ 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_pkgrev_set" ) + echo >&2 "Error: failed to set package revision for tag ${2}" + exit 15 ;; + "err_pkgrev_get" ) + echo >&2 "Error: failed to get package revision for tag ${2}" + exit 16 ;; "err_not_implemented" ) remove_build_requires echo >&2 "Error: functionality not yet imlemented" @@ -817,7 +887,7 @@ init_builder() { export GIT_WORK_TREE=$PACKAGE_DIR export GIT_DIR=$PACKAGE_DIR/.git - if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ]; then + if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then CVSTAG=${CVSTAG#refs/heads/} if [ "$CVSTAG" != "master" ]; then @@ -850,7 +920,7 @@ create_git_repo() { exit 101 fi [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes - # ssh $GIT_SERVER create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed + ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed 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} \ @@ -867,18 +937,14 @@ get_spec() { fi cd "$REPO_DIR" - if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then - # XXX: still needed? - SPECFILE=$(basename $SPECFILE) - fi - + SPECFILE=$(basename $SPECFILE) 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 @@ -887,20 +953,23 @@ 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" } + git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*' git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} ) 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 + 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 remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} CVSTAG=${CVSTAG:-"master"} fi local refs='' @@ -919,43 +988,52 @@ 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" ]; then - for a in dropin md5 adapter builder {relup,compile,repackage,pearize}.sh pldnotify.awk; do + 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}' + local _rev=$(get_pkgrev "$CVSTAG") + echo "$_rev" | grep -q -E "^ERROR$" || CVSTAG="$_rev" + 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 } @@ -964,7 +1042,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="|" @@ -1004,15 +1082,16 @@ src_md5() { cd $PACKAGE_DIR local md5 - if [ -f additional-md5sums ]; then - md5=$(grep -s -v '^#' additional-md5sums | \ - grep -E "[ ]$(basename "$1")([ ,]|\$)" | \ + # use "sources" file from package dir, like vim + if [ -f sources ]; then + md5=$(grep -s -v '^#' sources | \ + grep -E "[ *]$(basename "$1")([ ,]|\$)" | \ sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \ grep -E '^[0-9a-f]{32}$') if [ "$md5" ]; then if [ $(echo "$md5" | wc -l) != 1 ] ; then - echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2 + echo "$SPECFILE: more then one entry in sources for $1" 1>&2 fi echo "$md5" | tail -n 1 return @@ -1227,10 +1306,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 @@ -1253,9 +1328,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 @@ -1340,14 +1412,20 @@ get_files() { } tag_exist() { +# If tag exists and points to other commit exit with error +# If it existsts and points to HEAD return 1 +# If it doesn't exist return 0 local _tag="$1" + local sha1=$(git rev-parse HEAD) echo "Searching for tag $_tag..." if [ -n "$DEPTH" ]; then - local ref=`git ls-remote $REMOTE_PLD "refs/tags/$_tag"` - [ -n "$ref" ] && echo "$ref" && Exit_error err_tag_exists "$_tag" + local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40) else - git show-ref "refs/tags/$_tag" && Exit_error err_tag_exists "$_tag" + local ref=$(git show-ref -s "refs/tags/$_tag") fi + [ -z "$ref" ] && return 0 + [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag" + return 1 } make_tagver() { @@ -1376,8 +1454,6 @@ make_tagver() { } tag_files() { - TAG_FILES="$@" - if [ -n "$DEBUG" ]; then set -x set -v @@ -1386,34 +1462,65 @@ tag_files() { echo "Version: $PACKAGE_VERSION" echo "Release: $PACKAGE_RELEASE" - local TAGVER + local _tag if [ "$TAG_VERSION" = "yes" ]; then - TAGVER=`make_tagver` - echo "tag: $TAGVER" + _tag=`make_tagver` fi if [ -n "$TAG" ]; then - echo "tag: $TAG" + _tag="$TAG" fi + echo "tag: $_tag" local OPTIONS="tag $CVS_FORCE" - local _tag=$TAG - if [ "$TAG_VERSION" = "yes" ]; then - _tag=$TAGVER - fi; - cd "$PACKAGE_DIR" + if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then + update_shell_title "tag sources: $_tag" + git $OPTIONS $_tag || exit + git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD + else + echo "Tag $_tag already exists and points to the same commit" + fi +} + +get_pkgrev() { + [ -z "$1" ] && return 1 + local _tmp=$(mktemp /tmp/.builder-XXXX) + rm $_tmp 2>/dev/null + $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/get/$1 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1" + local result=$(cat $_tmp) + rm $_tmp 2>/dev/null + echo -n "$result" +} + +set_pkgrev() { + local _tag if [ "$TAG_VERSION" = "yes" ]; then - update_shell_title "tag sources: $TAGVER" - git $OPTIONS $TAGVER || exit - git push $CVS_FORCE $REMOTE_PLD tag $TAGVER || Exit_error err_remote_problem $REMOTE_PLD + _tag=`make_tagver` fi if [ -n "$TAG" ]; then - update_shell_title "tag sources: $TAG" - git $OPTIONS $TAG $chunk || exit - git push $CVS_FORCE $REMOTE_PLD tag $TAG || Exit_error err_remote_problem $REMOTE_PLD - fi + _tag="$TAG" + fi + echo "Writing git revision for tag $_tag" + local _tmp=$(mktemp /tmp/.builder-XXXX) + rm $_tmp 2>/dev/null + local _rev=$(git rev-parse HEAD) + $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/set/$_rev/$_tag 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1" + local result=$(cat $_tmp) + rm $_tmp 2>/dev/null + [ "$(get_pkgrev "$_tag")" = "$CVSTAG" ] && return 0 + echo "$result" | grep -q -E "^OK$" && return 0 + echo "$result" | grep -q -E "^EXISTS$" && Exit_error err_tag_exists "$_tag" + Exit_error err_pkgrev_set +} + +list_pkgrev() { + local _tmp=$(mktemp /tmp/.builder-XXXX) + rm $_tmp 2>/dev/null + $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/list/$PACKAGE_NAME 1>/dev/null 2>&1 + cat $_tmp + rm $_tmp 2>/dev/null } branch_files() { @@ -1549,36 +1656,34 @@ build_package() { esac update_shell_title "build_package: $COMMAND" + local logfile retval if [ -n "$LOGFILE" ]; then - LOG=`eval echo $LOGFILE` - if [ -d "$LOG" ]; then - echo "Log file $LOG is a directory." + logfile=`eval echo $LOGFILE` + if [ -d "$logfile" ]; then + echo "Log file $logfile is a directory." echo "Parse error in the spec?" Exit_error err_build_fail fi if [ -n "$LASTLOG_FILE" ]; then - echo "LASTLOG=$LOG" > $LASTLOG_FILE + echo "LASTLOG=$logfile" > $LASTLOG_FILE fi - RES_FILE=$(tempfile) - local specdir=$(insert_gitlog $SPECFILE) - - (time eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG - RETVAL=`cat $RES_FILE` - rm -r $RES_FILE $specdir - if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then - if [ "$RETVAL" -eq "0" ]; then - mv $LOG $LOGDIROK - else - mv $LOG $LOGDIRFAIL - fi + fi + + 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 + retval=$? + rm -r $specdir + + if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then + if [ "$retval" -eq "0" ]; then + mv $logfile $LOGDIROK + else + mv $logfile $LOGDIRFAIL fi - else - local specdir=$(insert_gitlog $SPECFILE) - eval ${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 fi - if [ "$RETVAL" -ne "0" ]; then + + if [ "$retval" -ne "0" ]; then if [ -n "$TRY_UPGRADE" ]; then echo "\nUpgrade package to new version failed." if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then @@ -1809,7 +1914,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. @@ -2061,9 +2166,13 @@ init_rpm_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; do - ln -s ../rpm-build-tools/${a}.sh $a + 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 } @@ -2073,7 +2182,7 @@ mr_proper() { DONT_PRINT_REVISION="yes" # remove spec and sources - $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 } @@ -2199,7 +2308,7 @@ while [ $# -gt 0 ]; do -pm | --prefer-mirrors ) PREFMIRRORS="yes" shift;; - --no-init ) + --noinit | --no-init ) NOINIT="yes" shift;; --opts ) @@ -2386,6 +2495,12 @@ while [ $# -gt 0 ]; do DISTFILES_SERVER=${TLD_DISTFILES_SERVER} ATTICDISTFILES_SERVER=${TLD_ATTICDISTFILES_SERVER} ;; + --pkgrev) + COMMAND="set_pkgrev" + shift;; + -lp) + COMMAND="list_pkgrev" + shift;; -*) Exit_error err_invalid_cmdline "$1" ;; @@ -2404,7 +2519,7 @@ done # Check if given package exists in TLD git if ! git ls-remote --heads ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME} 1>/dev/null 2>&1; then - # Nope, we don't have it in TLD, switch for PLD repositories + # Nope, we don't have it in TLD, switch to PLD repositories GIT_SERVER=${PLD_GIT_SERVER} GIT_PUSH=${PLD_GIT_PUSH} PACKAGES_DIR=${PLD_PACKAGES_DIR} @@ -2523,13 +2638,17 @@ 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 + local TAGVER=` + make_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" @@ -2538,8 +2657,8 @@ case "$COMMAND" in cmd_branches="git show-ref" ref_prefix=refs/remotes/${REMOTE_PLD} fi - TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$") - if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != "$CVSTAG" ]; then + TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40') + if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then Exit_error err_branch_exists "$TAG_STATUS" fi fi @@ -2553,7 +2672,7 @@ case "$COMMAND" in case $? in 0) get_files $SOURCES $PATCHES - check_md5 $SOURCES + check_md5 $SOURCES $PATCHES ;; *) NODIST="yes" get_files $SOURCES $PATCHES @@ -2594,8 +2713,7 @@ case "$COMMAND" in fi done git add $SPECFILE - git commit -m 'Initial commit' - git push --dry-run $REMOTE_PLD master || Exit_error err_cvs_add_failed + echo "When you are ready commit your changes and run git push origin master" else echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}" fi @@ -2658,13 +2776,13 @@ case "$COMMAND" in done ;; "list-sources-urls" ) - init_builder + init_builder >&2 NOCVSSPEC="yes" DONT_PRINT_REVISION="yes" - get_spec - parse_spec + get_spec >&2 + parse_spec >&2 SAPS="$SOURCES $PATCHES" - for SAP in $SAPS ; do + for SAP in $SAPS; do echo $SAP done ;; @@ -2726,6 +2844,26 @@ case "$COMMAND" in "version" ) echo "$VERSIONSTRING" ;; + "set_pkgrev" ) + init_builder + if [ -z "$SPECFILE" ]; then + Exit_error err_no_spec_in_cmdl + fi + get_spec > /dev/null + parse_spec + set_bconds_values + display_bconds + set_pkgrev + ;; + "list_pkgrev" ) + init_builder + if [ -z "$SPECFILE" ]; then + Exit_error err_no_spec_in_cmdl + fi + get_spec > /dev/null + parse_spec + list_pkgrev + ;; esac if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"