3 # This program is free software, distributed under the terms of
4 # the GNU General Public License Version 2.
10 # 2 - no spec file name in cmdl parameters
11 # 3 - spec file not stored in repo
12 # 4 - some source, patch or icon files not stored in repo
13 # 5 - package build failed
14 # 6 - spec file with errors
15 # 7 - wrong source in /etc/poldek.conf
16 # 8 - Failed installing buildrequirements and subrequirements
17 # 9 - Requested tag already exist
18 # 10 - Refused to build fractional release
19 # 100 - Unknown error (should not happen)
20 # 110 - Functions not yet implemented
23 # - when Icon: field is present, -5 and -a5 doesn't work
24 # - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
25 # - does not respect NoSource: X, and tries to cvs up such files [ example: VirtualBox-bin.spec and its Source0 ]
27 # - ability to do ./builder -bb foo.spec foo2.spec foo3.spec
28 # - funny bug, if source-md5 is set then builder will download from distfiles even if there is no url present:
29 # Source10: forwardfix.pl
30 # # Source10-md5: 8bf85f7368933a4e0cb4f875bac28733
32 # basename: missing operand
33 # Try `basename --help' for more information.
34 # -- and the normal usage info --
37 APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
38 RCSID='$Id: builder,v 1.645 2011/02/13 17:54:10 glen Exp $' r=${RCSID#* * } rev=${r%% *}
41 Build package utility from PLD Linux Packages repository
42 $VERSION (C) 1999-2013 Free Penguins".
44 CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
46 # required rpm-build-macros
65 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
67 # use rpm 4.4.6+ digest format instead of comments if non-zero
70 # user agent when fetching files
71 USER_AGENT="PLD/Builder($VERSION)"
73 # It can be used i.e. in log file naming.
74 # See LOGFILE example.
75 DATE=`date +%Y-%m-%d_%H-%M-%S`
77 # target arch, can also be used for log file naming
78 TARGET=$(rpm -E %{_target})
80 # Example: LOGFILE='../log.$PACKAGE_NAME'
81 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
82 # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
83 # Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
84 # Yes, you can use variable name! Note _single_ quotes!
87 # use teeboth Perl wrapper
88 # temporary option to disable if broken
103 # create symlinks for tools in PACKAGE_DIR, see get_spec()
115 # use lftp by default when available
117 lftp --version > /dev/null 2>&1 && USE_LFTP=yes
118 PARALLEL_DOWNLOADS=10
120 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
123 TLD_GIT_SERVER="git://git.tld-linux.org"
124 TLD_GIT_PUSH="git@git.tld-linux.org"
125 TLD_PACKAGES_DIR="packages"
126 TLD_DISTFILES_SERVER="://df.tld-linux.org"
127 TLD_ATTICDISTFILES_SERVER=""
130 PLD_GIT_SERVER="git://git.pld-linux.org"
131 PLD_GIT_PUSH="git@git.pld-linux.org"
132 PLD_PACKAGES_DIR="packages"
133 PLD_DISTFILES_SERVER="://distfiles.pld-linux.org"
134 PLD_ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
139 GIT_SERVER=${TLD_GIT_SERVER}
140 GIT_PUSH=${TLD_GIT_PUSH}
141 PACKAGES_DIR=${TLD_PACKAGES_DIR}
150 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
151 ATTICDISTFILES_SERVER=${TLD_ATTICDISTFILES_SERVER}
156 FAIL_IF_NO_SOURCES="yes"
158 # let get_files skip over files which are present to get those damn files fetched
159 SKIP_EXISTING_FILES="no"
162 # should the specfile be restored if upgrade failed?
163 REVERT_BROKEN_UPGRADE="yes"
165 if rpm --specsrpm 2>/dev/null; then
166 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
167 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
169 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
170 if [ -x /usr/bin/rpm-getdeps ]; then
171 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
173 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
177 UPDATE_POLDEK_INDEXES_OPTS=""
179 # Here we load saved user environment used to
180 # predefine options set above, or passed to builder
182 # This one reads global system environment settings:
183 if [ -f ~/etc/builderrc ]; then
186 # And this one cascades settings using user personal
188 # Example of ~/.builderrc:
190 #UPDATE_POLDEK_INDEXES="yes"
191 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
192 #FETCH_BUILD_REQUIRES="yes"
193 #REMOVE_BUILD_REQUIRES="force"
195 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
199 if [ -n "$HOME_ETC" ]; then
200 USER_CFG="$HOME_ETC/.builderrc"
201 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
203 USER_CFG=~/.builderrc
204 BUILDER_MACROS=~/.builder-rpmmacros
207 [ -f "$USER_CFG" ] && . "$USER_CFG"
209 if [ "$SCHEDTOOL" = "auto" ]; then
210 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
211 SCHEDTOOL="schedtool -B -e"
217 if [ -n "$USE_PROZILLA" ]; then
218 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
221 elif [ -n "$USE_AXEL" ]; then
222 GETURI="axel -a $AXEL_OPTS"
225 elif [ -n "$USE_LFTP" ]; then
230 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
231 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
232 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
233 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
235 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
236 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
242 if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
253 if [ -d $HOME/rpm/SOURCES ]; then
254 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
255 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
259 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
260 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
265 if [ -n "$LOGFILE" ]; then
266 LOG=`eval echo $LOGFILE`
267 if [ -n "$LASTLOG_FILE" ]; then
268 echo "LASTLOG=$LOG" > $LASTLOG_FILE
270 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
271 # FIXME $exit_pldk undefined
274 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
275 return `cat ${RES_FILE}`
280 #---------------------------------------------
284 local outfile=$1 url=$2 retval tmpfile
288 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
289 set ssl:verify-certificate no;
290 set net:max-retries $WGET_RETRIES;
291 set http:user-agent \"$USER_AGENT\";
292 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
296 if [ $retval -eq 0 ]; then
297 mv -f "$tmpfile" "$outfile"
305 if [ -n "$DEBUG" ]; then set -xv; fi
307 # to make this output parseable by bash-completion _parse_help()
308 # if the line contains short and long option, it will take only the long option
309 # but if you want both being completed, put the short option to separate line
311 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
312 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
313 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
314 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
315 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
316 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
317 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
318 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
319 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
320 <package>[.spec][:tag]
322 -4 - force IPv4 when transferring files
323 -6 - force IPv6 when transferring files
325 --update-md5 - update md5 comments in spec, implies -nd -ncs
327 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
328 --all-branches - make shallow fetch of all branches; --depth required
329 -n5, --no-md5 - ignore md5 comments in spec
330 -D, --debug - enable builder script debugging mode,
331 -debug - produce rpm debug package (same as --opts -debug)
332 -V, --version - output builder version string
333 --short-version - output builder short version
334 -a - try add new package to PLD repo.
337 - get all files from PLD repo or HTTP/FTP and build package
339 -bb - get all files from PLD repo or HTTP/FTP and build binary
340 only package from <package>.spec,
341 -bp - execute the %prep phase of <package>.spec,
342 -bc - execute the %build phase of <package>.spec,
343 -bi - execute the %install phase of <package>.spec
344 -bl - execute the %files phase of <package>.spec
345 -bs - get all files from PLD repo or HTTP/FTP and only pack
347 --short-circuit - short-circuit build
348 -B, --branch - add branch
350 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
351 may be used with building process.
352 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
353 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
354 -cf, --cvs-force - use -f when tagging
355 --define '<macro> <value>'
356 - define a macro <macro> with value <value>,
357 --depth <number> - make shallow fetch
358 --alt_kernel <kernel>
359 - same as --define 'alt_kernel <kernel>'
360 --nodeps - rpm won't check any dependences
362 --get - get <package>.spec and all related files from PLD repo
363 -h, --help - this message,
364 -j N - set %_smp_mflags to propagate concurrent jobs
365 --ftp - use FTP protocol to access distfiles server
366 --http - use HTTP protocol to access distfiles server
367 -l <logfile>, --logtofile=<logfile>
370 - don't pull from PLD repo
371 -nd, --no-distfiles - don't download from distfiles
372 -nm, --no-mirrors - don't download from mirror, if source URL is given,
373 -nu, --no-urls - don't try to download from FTP/HTTP location,
374 -ns, --no-srcs - don't download Sources/Patches
375 -ns0, --no-source0 - don't download Source0
376 -nn, --no-net - don't download anything from the net
377 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
378 -pm, --prefer-mirrors
379 - prefer mirrors (if any) over distfiles for SOURCES
380 --no-init - don't initialize builder paths (SPECS and SOURCES)
382 --skip-existing-files
383 - skip existing files in get_files
384 --opts <rpm opts> - additional options for rpm
385 -q, --quiet - be quiet,
386 --date yyyy-mm-dd - build package using resources from specified date,
387 -r <tag>, --cvstag <ref>
388 - build package using resources from specified branch/tag,
389 -A - build package using master branch as any sticky tags/branch/date being reset.
390 -R, --fetch-build-requires
391 - fetch what is BuildRequired,
392 -RB, --remove-build-requires
393 - remove all you fetched with -R or --fetch-build-requires
394 remember, this option requires confirmation,
395 -FRB, --force-remove-build-requires
396 - remove all you fetched with -R or --fetch-build-requires
397 remember, this option works without confirmation,
398 -sd, --source-distfiles
399 - list sources available from distfiles (intended for offline
400 operations; does not work when Icon field is present
401 but icon file is absent),
402 -sc, --source-cvs - list sources available from PLD repo
403 -sdp, --source-distfiles-paths
404 - list sources available from distfiles -
405 paths relative to distfiles directory (intended for offline
406 operations; does not work when Icon field is present
407 but icon file is absent),
408 -sf, --source-files - list sources - bare filenames (intended for offline
409 operations; does not work when Icon field is present
410 but icon file is absent),
412 - list sources - filenames with full local paths (intended for
413 offline operations; does not work when Icon field is present
414 but icon file is absent),
415 -su, --source-urls - list urls - urls to sources and patches
416 intended for copying urls with spec with lots of macros in urls
417 -T <tag> , --tag <tag>
418 - add git tag <tag> for files,
419 -Tvs, --tag-version-stable
420 - add git tags STABLE and NAME-VERSION-RELEASE for files,
422 - add git tag STABLE for files,
424 --tag-version - add git tag NAME-VERSION-RELEASE for files,
425 -Tp, --tag-prefix <prefix>
426 - add <prefix> to NAME-VERSION-RELEASE tags,
427 -tt, --test-tag <prefix>
428 - fail if tag is already present,
429 -ir, --integer-release-only
430 - allow only integer and snapshot releases
431 -v, --verbose - be verbose,
432 -u, --try-upgrade - check version, and try to upgrade package
433 -un, --try-upgrade-with-float-version
434 - as above, but allow float version
435 php-pear-Services_Digg/
436 --upgrade-version - upgrade to specified version in try-upgrade
437 -U, --update - refetch sources, don't use distfiles, and update md5 comments
438 -Upi, --update-poldek-indexes
439 - refresh or make poldek package index files.
441 --skip-patch <patchnumber>
442 - don't apply <patchnumber>. may be repeated.
444 --nopatch <patchnumber>
445 - abort instead of applying patch <patchnumber>
447 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
448 --show-bconds - show available conditional builds, which can be used
449 - with --with and/or --without switches.
450 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
451 In other words, the output is parseable by scripts.
452 --show-avail-bconds - show available bconds
455 - conditional build package depending on %_with_<feature>/
456 %_without_<feature> macro switch. You may now use
457 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
458 constructions. Set GROUP_BCONDS to yes to make use of it.
459 --target <platform>, --target=<platform>
460 - build for platform <platform>.
461 --init-rpm-dir - initialize ~/rpm directory structure
462 --git-pld - force use of PLD git and distfiles
463 --git-tld - force use of TLD git and distfiles (note: it will fall
464 back to PLD git/df if package doesn't exist in TLD git)
468 # create tempfile. as secure as possible
470 mktemp --tmpdir -t builder.$PACKAGE_NAME.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
474 mktemp --tmpdir -d builder.$PACKAGE_NAME.XXXXXX
477 # inserts git log instead of %changelog
478 # outputs name of modified file created by tempfile
480 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
482 # allow this being customized
483 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
485 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
486 # otherwise i'd use --date=iso here
487 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
488 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
489 # NOTE: changelog date is always in UTC for rpmbuild
490 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
491 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
493 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
494 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
497 # add link to full git logs
498 local giturl="http://git.tld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
499 if [ -n "$CVSTAG" ]; then
500 giturl="$giturl;h=$CVSTAG"
502 local gitauthor="TLD Linux <feedback@tld-linux.org>"
503 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
504 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
509 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
510 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
514 " > $specdir/$SPECFILE
515 rm -f $gitlog $speclog
519 # @param string logfile
520 # @param varargs... commands to execute
523 # use teeboth from toys/cleanbuild, if available and enabled
524 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
528 local efile rc logfile=$1; shift
529 if [ "$logfile" ]; then
531 { "$@" 2>&1; echo $? > $efile; } | tee $logfile
542 # change dependency to specname
544 # - perl(Package::Name) -> perl-Package-Name
548 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
552 update_shell_title() {
554 local len=${COLUMNS:-80}
555 local msg="$(echo "$*" | cut -c-$len)"
557 if [ -n "$BE_VERBOSE" ]; then
558 echo >&2 "$(date +%s.%N) $*"
561 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
563 if [ -n "$PACKAGE_NAME" ]; then
564 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
569 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
570 msg=$(echo $msg | tr -d '\n\r')
573 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
576 echo >&2 -ne "\033]0;$msg\007"
582 # set TARGET from BuildArch: from SPECFILE
584 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
585 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
587 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
591 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
593 TARGET_SWITCH="--target=$TARGET" ;;
599 # runs rpm with minimal macroset
601 # we reset macros not to contain macros.build as all the %() macros are
602 # executed here, while none of them are actually needed.
603 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
604 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
606 # TODO: move these to /usr/lib/rpm/macros
607 cat > $BUILDER_MACROS <<'EOF'
608 %x8664 x86_64 amd64 ia32e
611 %bootstrap_release() %{1}
612 %requires_releq_kernel_up(s:n:) %{nil}
613 %requires_releq_kernel_smp(s:n:) %{nil}
614 %requires_releq_kernel(s:n:) %{nil}
615 %requires_releq() %{nil}
616 %pyrequires_eq() %{nil}
617 %requires_eq() %{nil}
618 %requires_eq_to() %{nil}
619 %requires_ge() %{nil}
620 %requires_ge_to() %{nil}
621 %requires_ge() %{nil}
622 %releq_kernel_up(n:) ERROR
623 %releq_kernel_smp(n:) ERROR
624 %releq_kernel(n:) ERROR
625 %py_postclean(x:) ERROR
629 %ruby_ver_requires_eq() %{nil}
630 %ruby_mod_ver_requires_eq() %{nil}
631 %__php_api_requires() %{nil}
632 %php_major_version ERROR
633 %php_api_version ERROR
634 %requires_xorg_xserver_extension %{nil}
635 %requires_xorg_xserver_xinput %{nil}
636 %requires_xorg_xserver_font %{nil}
637 %requires_xorg_xserver_videodrv %{nil}
639 %perl_vendorarch ERROR
640 %perl_vendorlib ERROR
641 # damn. need it here! - copied from /usr/lib/rpm/macros.build
642 %tmpdir %(echo "${TMPDIR:-/tmp}")
643 %patchset_source(f:b:) %(
644 base=%{-b*}%{!-b*:10000};
645 start=$(expr $base + %1);
646 end=$(expr $base + %{?2}%{!?2:%{1}});
647 # we need to call seq twice as it doesn't allow two formats
648 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
649 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
650 paste %{tmpdir}/__ps{1,2};
651 rm -f %{tmpdir}/__ps{1,2};
654 %add_etc_shells(p) %{p:<lua>}
655 %remove_etc_shells(p) %{p:<lua>}
656 %lua_add_etc_shells() %{nil}
657 %lua_remove_etc_shells() %{nil}
659 %buildrequires_jdk %{nil}
660 %pear_package_print_optionalpackages %{nil}
662 if [ "$NOINIT" = "yes" ] ; then
663 cat >> $BUILDER_MACROS <<'EOF'
668 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
672 if [ -n "$DEBUG" ]; then
677 if [ -x /usr/bin/rpm-specdump ]; then
678 update_shell_title "cache_rpm_dump using rpm-specdump command"
679 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
681 update_shell_title "cache_rpm_dump using rpmbuild command"
684 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
685 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
691 ARGS='--nodigest --nosignature --nobuild'
694 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
696 if [ $? -gt 0 ]; then
697 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
699 Exit_error err_build_fail
702 # make small dump cache
703 rpm_dump_cache=`echo "$rpm_dump" | awk '
704 $2 ~ /^SOURCEURL/ {print}
705 $2 ~ /^PATCHURL/ {print}
706 $2 ~ /^nosource/ {print}
707 $2 ~ /^PACKAGE_/ {print}
711 update_shell_title "cache_rpm_dump: OK!"
715 if [ -z "$rpm_dump_cache" ] ; then
716 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
718 echo "$rpm_dump_cache"
722 update_shell_title "get icons"
723 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
724 if [ -z "$ICONS" ]; then
728 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
732 update_shell_title "parsing specfile"
733 if [ -n "$DEBUG" ]; then
738 # icons are needed for successful spec parse
744 if rpm_dump | grep -qEi ":.*nosource.*1"; then
745 FAIL_IF_NO_SOURCES="no"
748 if [ "$NOSRCS" != "yes" ]; then
749 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
750 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
751 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
754 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
755 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
756 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
758 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
759 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
762 if [ -n "$BE_VERBOSE" ]; then
763 echo "- Sources : `nourl $SOURCES`"
764 if [ -n "$PATCHES" ]; then
765 echo "- Patches : `nourl $PATCHES`"
767 echo "- Patches : *no patches needed*"
769 if [ -n "$ICONS" ]; then
770 echo "- Icon : `nourl $ICONS`"
772 echo "- Icon : *no package icon*"
774 echo "- Name : $PACKAGE_NAME"
775 echo "- Version : $PACKAGE_VERSION"
776 echo "- Release : $PACKAGE_RELEASE"
779 update_shell_title "parse_spec: OK!"
783 if [ -n "$DEBUG" ]; then
791 "err_no_spec_in_cmdl" )
792 remove_build_requires
793 echo >&2 "ERROR: spec file name not specified."
795 "err_invalid_cmdline" )
796 echo >&2 "ERROR: invalid command line arg ($2)."
798 "err_no_spec_in_repo" )
799 remove_build_requires
800 echo >&2 "Error: spec file not stored in PLD repo."
802 "err_no_source_in_repo" )
803 remove_build_requires
804 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
806 "err_cvs_add_failed" )
807 echo >&2 "Error: failed to add package to PLD repo."
810 remove_build_requires
811 echo >&2 "Error: package build failed. (${2:-no more info})"
813 "err_no_package_data" )
814 remove_build_requires
815 echo >&2 "Error: couldn't get out package name/version/release from spec file."
818 remove_build_requires
819 echo >&2 "Tag ${2} already exists"
822 remove_build_requires
823 echo >&2 "Release ${2} not integer and not a snapshot."
825 "err_branch_exists" )
826 remove_build_requires
827 echo >&2 "Tree branch already exists (${2})."
830 remove_build_requires
831 echo >&2 "Error: conditions reject building this spec (${2})."
833 "err_remote_problem" )
834 remove_build_requires
835 echo >&2 "Error: problem with remote (${2})"
838 echo >&2 "Error: cannot checkout $2"
840 "err_not_implemented" )
841 remove_build_requires
842 echo >&2 "Error: functionality not yet imlemented"
845 echo >&2 "Unknown error."
850 if [ -n "$DEBUG" ]; then
855 if [ "$NOINIT" != "yes" ] ; then
856 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
858 local macros_ver=$(rpm -E %?rpm_build_macros)
859 if [ -z "$macros_ver" ]; then
860 REPO_DIR=$TOP_DIR/packages
861 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
863 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
864 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
868 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
874 export GIT_WORK_TREE=$PACKAGE_DIR
875 export GIT_DIR=$PACKAGE_DIR/.git
877 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
878 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
879 CVSTAG=${CVSTAG#refs/heads/}
880 if [ "$CVSTAG" != "master" ]; then
881 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
884 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
887 elif [ "$CVSTAG" = "HEAD" ]; then
888 # assume -r HEAD is same as -A
896 update_shell_title "add_package"
898 if [ -n "$DEBUG" ]; then
904 SPECFILE=$(basename $SPECFILE)
905 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
906 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
909 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
910 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
912 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git && \
913 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} \
914 || Exit_error err_remote_problem $REMOTE_PLD
919 update_shell_title "get_spec"
921 if [ -n "$DEBUG" ]; then
927 SPECFILE=$(basename $SPECFILE)
928 if [ "$NOCVSSPEC" != "yes" ]; then
929 if [ -z "$DEPTH" ]; then
930 if [ -d "$PACKAGE_DIR/.git" ]; then
931 git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
932 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
933 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
934 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
937 Exit_error err_not_implemented
941 git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
942 # softfail if new package, i.e not yet added to PLD rep
943 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
944 echo "Warning: package not in CVS - assuming new package"
947 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
948 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
952 if [ ! -d "$PACKAGE_DIR/.git" ]; then
953 if [ ! -d "$PACKAGE_DIR" ]; then
954 install -d $PACKAGE_DIR
957 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
958 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
959 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
960 CVSTAG=${CVSTAG:-"master"}
963 if [ -z "$ALL_BRANCHES" ]; then
964 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
966 git fetch $DEPTH $REMOTE_PLD $refs || {
967 echo >&2 "Error: branch $CVSTAG does not exist"
971 git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*'
973 cvsignore_df .gitignore
975 # add default log format to .gitignore if it is relative to package dir
976 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
977 # substitute known "macros" to glob
978 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\|TARGET\),*,g')
979 if [ "$logfile" ]; then
980 cvsignore_df "$logfile"
984 # create symlinks for tools
985 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
986 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
987 # skip tools that don't exist in top dir
988 [ -f $a ] || continue
989 # skip tools that already exist
990 [ -f $PACKAGE_DIR/$a ] && continue
991 ln -s ../$a $PACKAGE_DIR
997 if [ -n "$CVSTAG" ]; then
998 if git rev-parse --verify -q "$CVSTAG"; then
999 git checkout "$CVSTAG" --
1000 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1001 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1003 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1004 Exit_error "err_no_checkut" "$CVSTAG"
1006 git merge --ff-only '@{u}'
1007 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1008 if [ -n "$CVSDATE" ]; then
1009 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1013 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1014 Exit_error err_no_spec_in_repo
1017 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1018 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1021 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1029 if [ ! -f "mirrors" ] ; then
1030 ln -s ../rpm-build-tools/mirrors .
1034 local origin mirror name rest ol prefix
1035 while read origin mirror name rest; do
1036 # skip comments and empty lines
1037 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1040 ol=$(echo -n "$origin" | wc -c)
1041 prefix=$(echo -n "$url" | head -c $ol)
1042 if [ "$prefix" = "$origin" ] ; then
1043 suffix=$(echo "$url" | cut -b $((ol+1))-)
1044 echo -n "$mirror$suffix"
1051 # Warning: unpredictable results if same URL used twice
1054 # escape some regexp characters if part of file name
1055 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1058 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1059 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1060 head -n 1 | tr OURCEATH ourceath | xargs
1064 [ "$NO5" = "yes" ] && return
1066 [ -z "$no" ] && return
1070 # use "sources" file from package dir, like vim
1071 if [ -f sources ]; then
1072 md5=$(grep -s -v '^#' sources | \
1073 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1074 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1075 grep -E '^[0-9a-f]{32}$')
1078 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1079 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1081 echo "$md5" | tail -n 1
1086 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1087 if [ -n "$source_md5" ]; then
1090 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1091 if [ -n "$source_md5" ]; then
1094 # we have empty SourceX-md5, but it is still possible
1095 # that we have NoSourceX-md5 AND NoSource: X
1096 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1097 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1105 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1109 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1112 distfiles_attic_url() {
1113 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
1118 [ "$md5" = "" ] || \
1119 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1123 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1124 [ -n "$size" -a "$size" -gt 0 ]
1128 if [ "$CVSIGNORE_DF" != "yes" ]; then
1131 cvsignore=${PACKAGE_DIR}/.gitignore
1133 # add only if not yet there
1134 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1135 echo "$1" >> $cvsignore
1139 # returns true if "$1" is ftp, http or https protocol url
1142 ftp://*|http://*|https://*)
1150 if [ $# -eq 0 ]; then
1154 update_shell_title "update md5"
1155 if [ -n "$DEBUG" ]; then
1162 # pass 1: check files to be fetched
1166 local fp=$(nourl "$i")
1167 local srcno=$(src_no "$i")
1168 if [ -n "$ADD5" ]; then
1169 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1170 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1171 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1173 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1175 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1176 need_files="$need_files $i"
1180 # pass 1a: get needed files
1181 if [ "$need_files" ]; then
1182 get_files $need_files
1185 # pass 2: proceed with md5 adding or updating
1187 local fp=$(nourl "$i")
1188 local srcno=$(src_no "$i")
1189 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1190 if [ -z "$md5" ]; then
1191 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1193 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1194 local tag="# $srcno-md5:\t"
1195 if [[ "$md5" == *NoSource* ]]; then
1196 tag="# No$srcno-md5:\t"
1197 elif [ -n "$USEDIGEST" ]; then
1198 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1200 md5=$(md5sum "$fp" | cut -f1 -d' ')
1201 echo "Updating $srcno ($md5: $fp)."
1203 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1204 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1206 $PACKAGE_DIR/$SPECFILE
1213 [ "$NO5" = "yes" ] && return
1215 update_shell_title "check md5"
1219 if ! good_md5 "$i"; then
1220 echo -n "MD5 sum mismatch."
1223 if ! good_size "$i"; then
1224 echo -n "0 sized file."
1228 if [ $bad -eq 1 ]; then
1229 echo " Use -U to refetch sources,"
1230 echo "or -5 to update md5 sums, if you're sure files are correct."
1231 Exit_error err_no_source_in_repo $i
1237 update_shell_title "get_files"
1239 if [ -n "$DEBUG" ]; then
1244 if [ $# -gt 0 ]; then
1248 local get_files_cvs=""
1252 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1253 update_shell_title "$i"
1254 local fp=`nourl "$i"`
1255 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1260 local srcmd5=$(src_md5 "$i")
1262 # we know if source/patch is present in cvs/distfiles
1263 # - has md5 (in distfiles)
1264 # - in cvs... ideas?
1266 # CHECK: local file didn't exist or always cvs up (first) requested.
1267 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1268 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1269 echo "Warning: no URL given for $i"
1273 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1274 if good_md5 "$i" && good_size "$i"; then
1275 echo "$fp having proper md5sum already exists"
1279 # optionally prefer mirror over distfiles if there's mirror
1280 # TODO: build url list and then try each url from the list
1281 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1284 url=$(distfiles_url "$i")
1287 url_attic=$(distfiles_attic_url "$i")
1289 # is $url local file?
1290 if [[ "$url" = [./]* ]]; then
1291 update_shell_title "${GETLOCAL%% *}: $url"
1292 ${GETLOCAL} $url $target
1295 # make shorter message for distfiles urls
1296 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1297 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1298 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1301 update_shell_title "${GETURI%% *}: $uri"
1302 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1303 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1304 update_shell_title "${GETURI2%% *}: $url"
1305 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1310 if [ ! -s "$target" ]; then
1312 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1313 update_shell_title "${GETLOCAL%% *}: $url_attic"
1314 ${GETLOCAL} $url_attic $target
1316 update_shell_title "${GETURI%% *}: $url_attic"
1317 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1318 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1319 update_shell_title "${GETURI2%% *}: $url_attic"
1320 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1322 test -s "$target" || rm -f "$target"
1326 if [ -s "$target" ]; then
1327 cvsignore_df $target
1334 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1335 if [ -z "$NOMIRRORS" ]; then
1336 im=$(find_mirror "$i")
1340 update_shell_title "${GETURI%% *}: $im"
1341 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1342 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1343 update_shell_title "${GETURI2%% *}: $im"
1344 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1346 test -s "$target" || rm -f "$target"
1349 if [ "$cvsup" = 1 ]; then
1355 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1356 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1357 Exit_error err_no_source_in_repo $i
1360 # we check md5 here just only to refetch immediately
1361 if good_md5 "$i" && good_size "$i"; then
1363 elif [ "$FROM_DISTFILES" = 1 ]; then
1364 # wrong md5 from distfiles: remove the file and try again
1366 echo "MD5 sum mismatch. Trying full fetch."
1369 update_shell_title "${GETURI%% *}: $url"
1370 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1371 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1372 update_shell_title "${GETURI2%% *}: $url"
1373 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1375 if [ ! -s "$target" ]; then
1377 update_shell_title "${GETURI%% *}: $url_attic"
1378 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1379 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1380 update_shell_title "${GETURI2%% *}: $url_attic"
1381 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1384 test -s "$target" || rm -f "$target"
1387 SHELL_TITLE_PREFIX=""
1390 if [ "$CHMOD" = "yes" ]; then
1391 CHMOD_FILES=$(nourl "$@")
1392 if [ -n "$CHMOD_FILES" ]; then
1393 chmod $CHMOD_MODE $CHMOD_FILES
1400 # If tag exists and points to other commit exit with error
1401 # If it existsts and points to HEAD return 1
1402 # If it doesn't exist return 0
1404 local sha1=$(git rev-parse HEAD)
1405 echo "Searching for tag $_tag..."
1406 if [ -n "$DEPTH" ]; then
1407 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1409 local ref=$(git show-ref -s "refs/tags/$_tag")
1411 [ -z "$ref" ] && return 0
1412 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1417 if [ -n "$DEBUG" ]; then
1422 # Check whether first character of PACKAGE_NAME is legal for tag name
1423 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1427 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1428 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1430 # Remove @kernel.version_release from TAGVER because tagging sources
1431 # could occur with different kernel-headers than kernel-headers used at build time.
1432 # besides, %{_kernel_ver_str} is not expanded.
1434 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1435 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1442 if [ -n "$DEBUG" ]; then
1447 echo "Version: $PACKAGE_VERSION"
1448 echo "Release: $PACKAGE_RELEASE"
1451 if [ "$TAG_VERSION" = "yes" ]; then
1454 if [ -n "$TAG" ]; then
1459 local OPTIONS="tag $CVS_FORCE"
1463 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1464 update_shell_title "tag sources: $_tag"
1465 git $OPTIONS $_tag || exit
1466 git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1468 echo "Tag $_tag already exists and points to the same commit"
1474 echo "Git branch: $TAG"
1477 if [ -n "$DEBUG" ]; then
1482 local OPTIONS="branch $CVS_FORCE"
1485 git $OPTIONS $TAG || exit
1489 # this function should exit early if package can't be built for this arch
1490 # this avoids unneccessary BR filling.
1493 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1495 if [ $ret -ne 0 ]; then
1507 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1508 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1514 local ver="$2" subver=$ver
1515 local newver="$3" newsubver=$newver
1517 # try handling subver, everything that's not numeric-dotted in version
1518 if grep -Eq '%define\s+subver' $specfile; then
1519 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1521 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1522 newver=${newver%$newsubver}
1525 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1526 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1527 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1532 if [ -n "$TRY_UPGRADE" ]; then
1533 local TNOTIFY TNEWVER TOLDVER
1534 update_shell_title "build_package: try_upgrade"
1538 if [ "$UPGRADE_VERSION" ]; then
1539 TNEWVER=$UPGRADE_VERSION
1541 if [ -n "$FLOAT_VERSION" ]; then
1542 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1544 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1547 # pldnotify.awk does not set exit codes, but it has match for ERROR
1548 # in output which means so.
1549 if [[ "$TNOTIFY" = *ERROR* ]]; then
1554 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1557 if [ -n "$TNEWVER" ]; then
1558 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1559 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1560 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1561 cp -f $SPECFILE $SPECFILE.bak
1564 set_release $SPECFILE $PACKAGE_RELEASE 1
1565 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1567 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1568 echo >&2 "Upgrading version failed, you need to update spec yourself"
1578 update_shell_title "build_package"
1579 if [ -n "$DEBUG" ]; then
1588 BUILD_SWITCH="-ba" ;;
1590 BUILD_SWITCH="-bb" ;;
1592 BUILD_SWITCH="-bs --nodeps" ;;
1594 BUILD_SWITCH="-bp --nodeps" ;;
1596 BUILD_SWITCH="-bc" ;;
1598 BUILD_SWITCH="-bi" ;;
1600 BUILD_SWITCH="-bl" ;;
1604 update_shell_title "build_package: $COMMAND"
1605 local logfile retval
1606 if [ -n "$LOGFILE" ]; then
1607 logfile=`eval echo $LOGFILE`
1608 if [ -d "$logfile" ]; then
1609 echo "Log file $logfile is a directory."
1610 echo "Parse error in the spec?"
1611 Exit_error err_build_fail
1613 if [ -n "$LASTLOG_FILE" ]; then
1614 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1618 local specdir=$(insert_gitlog $SPECFILE)
1619 # FIXME: eval here is exactly why?
1620 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
1624 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1625 if [ "$retval" -eq "0" ]; then
1626 mv $logfile $LOGDIROK
1628 mv $logfile $LOGDIRFAIL
1632 if [ "$retval" -ne "0" ]; then
1633 if [ -n "$TRY_UPGRADE" ]; then
1634 echo "\nUpgrade package to new version failed."
1635 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1636 echo "Restoring old spec file."
1637 mv -f $SPECFILE.bak $SPECFILE
1641 Exit_error err_build_fail
1647 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1650 install_required_packages() {
1655 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1658 /^%changelog/ { exit }
1660 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1661 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1662 gsub(/[ \t]+/, "_", bcond);
1664 }' $SPEC | LC_ALL=C sort -u
1668 # expand bconds from ~/.bcondrc
1669 # The file structure is like gentoo's package.use:
1672 # samba -mysql -pgsql
1673 # w32codec-installer license_agreement
1676 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1682 SN=${SPECFILE%%\.spec}
1684 local bcondrc=$HOME/.bcondrc
1685 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1687 local bcond_avail=$(find_spec_bcond $SPECFILE)
1689 while read pkg flags; do
1691 [[ "$pkg" == \#* ]] && continue
1693 # any package or current package?
1694 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1695 for flag in $flags; do
1696 local opt=${flag#[+-]}
1698 # use only flags which are in this package.
1699 if [[ $bcond_avail = *${opt}* ]]; then
1700 if [[ $flag = -* ]]; then
1701 if [[ $BCOND != *--with?${opt}* ]]; then
1702 BCOND="$BCOND --without $opt"
1705 if [[ $BCOND != *--without?${opt}* ]]; then
1706 BCOND="$BCOND --with $opt"
1713 update_shell_title "parse ~/.bcondrc: DONE!"
1716 set_bconds_values() {
1717 update_shell_title "set bcond values"
1719 AVAIL_BCONDS_WITHOUT=""
1720 AVAIL_BCONDS_WITH=""
1722 if grep -Eq '^# *_with' ${SPECFILE}; then
1723 echo >&2 "ERROR: This spec has old style bconds."
1727 if ! grep -q '^%bcond' ${SPECFILE}; then
1731 local bcond_avail=$(find_spec_bcond $SPECFILE)
1732 process_bcondrc "$SPECFILE"
1734 update_shell_title "parse bconds"
1737 for opt in $bcond_avail; do
1740 bcond=${opt#without_}
1742 *--without?${bcond}*)
1743 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1746 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1754 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1757 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1762 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1771 update_shell_title "run_sub_builder $package_name"
1773 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1774 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1775 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1776 # jakby nie bylo tego kawalka kodu.
1778 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1779 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1783 # kurwa. translate that ^^^^
1787 # Istnieje taki spec? ${package}.spec
1788 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1789 parent_spec_name=${package}.spec
1790 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1791 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1793 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1798 if [ "${parent_spec_name}" != "" ]; then
1799 spawn_sub_builder $parent_spec_name
1801 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1804 spawn_sub_builder() {
1806 update_shell_title "spawn_sub_builder $package_name"
1809 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1810 sub_builder_opts="${sub_builder_opts} -R"
1812 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1813 sub_builder_opts="${sub_builder_opts} -RB"
1814 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1815 sub_builder_opts="${sub_builder_opts} -FRB"
1817 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1818 sub_builder_opts="${sub_builder_opts} -Upi"
1822 ./builder ${sub_builder_opts} "$@"
1825 remove_build_requires() {
1826 if [ "$INSTALLED_PACKAGES" != "" ]; then
1827 case "$REMOVE_BUILD_REQUIRES" in
1829 run_poldek --noask -ve $INSTALLED_PACKAGES
1832 run_poldek --ask -ve $INSTALLED_PACKAGES
1835 echo You may want to manually remove following BuildRequires fetched:
1836 echo $INSTALLED_PACKAGES
1837 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1844 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1845 if [ "$BCOND" ]; then
1847 echo "Building $SPECFILE with the following conditional flags:"
1851 echo "No conditional flags passed"
1854 echo "from available:"
1855 echo "--with :\t$AVAIL_BCONDS_WITH"
1856 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1861 display_branches() {
1862 echo -n "Available branches: "
1863 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1866 # checks a given list of packages/files/provides agains current rpmdb.
1867 # outputs all dependencies which current rpmdb doesn't satisfy.
1868 # input can be either STDIN or parameters
1872 if [ $# -gt 0 ]; then
1878 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1881 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1883 # other deps (files)
1884 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1887 # checks if given package/files/provides exists in rpmdb.
1888 # input can be either stdin or parameters
1889 # returns packages which are present in the rpmdb
1893 if [ $# -gt 0 ]; then
1899 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1902 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1903 install_build_requires_rpmdeps() {
1904 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1905 # TODO: Conflicts list doesn't check versions
1906 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1907 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1909 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1910 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1911 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1914 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1915 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1916 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1917 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1919 if [ -n "$CNFL" ]; then
1920 update_shell_title "uninstall conflicting packages: $CNFL"
1921 echo "Trying to uninstall conflicting packages ($CNFL):"
1922 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1925 while [ "$DEPS" ]; do
1926 update_shell_title "install deps: $DEPS"
1927 echo "Trying to install dependencies ($DEPS):"
1928 local log=.${SPECFILE}_poldek.log
1929 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1930 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1933 if [ -n "$failed" ]; then
1934 for package in $failed; do
1935 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1944 fetch_build_requires()
1946 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1950 update_shell_title "fetch build requires"
1951 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1952 install_build_requires_rpmdeps
1956 # XXX is this ugliest code written in human history still needed?
1957 echo "All packages installed by fetch_build_requires() are written to:"
1958 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1960 echo "If anything fails, you may get rid of them by executing:"
1961 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
1963 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1964 for package_item in $(cat $SPECFILE | grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'|sed -e s,perl\(,perl-,g -e s,::,-,g -e s,\(.*\),,g -e s,%{,,g -e s,},,g|grep -v OpenGL-devel|sed -e s,sh-utils,coreutils,g -e s,fileutils,coreutils,g -e s,textutils,coreutils,g -e s,kgcc_package,gcc,g -e s,\),,g)
1966 package_item=$(echo $package_item|sed -e s,rpmbuild,rpm-build,g |sed -e s,__perl,perl,g |sed -e s,gasp,binutils-gasp,g -e s,binutils-binutils,binutils,g -e s,apxs,apache,g|sed -e s,apache\(EAPI\)-devel,apache-devel,g -e s,kernel-headers\(netfilter\),kernel-headers,g -e s,awk,mawk,g -e s,mmawk,mawk,g -e s,motif,openmotif,g -e s,openopenmotif,openmotif,g)
1968 package=$(basename "$package_item"|sed -e "s/}$//g")
1969 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
1972 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1973 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1974 if [ "$COND_ARCH_TST" != "" ] && [ "`echo $COND_ARCH_TST|sed -e "s/i.86/ix86/g"`" != "`echo $mach|sed -e "s/i.86/ix86/g"`" ]; then
1979 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1982 if `echo $COND_TST|grep -q 'without_'`; then
1983 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1984 if `echo $COND_TST|grep -q !`; then
1989 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1990 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1991 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1997 elif `echo $COND_TST|grep -q 'with_'`; then
1998 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1999 if `echo $COND_TST|grep -q !`; then
2004 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
2005 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
2006 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
2012 RESULT="${COND_STATE}-${COND_ARGV}"
2014 "with-wout" | "wout-with" )
2017 "wout-wout" | "with-with" )
2021 echo "Action '$RESULT' was not defined for package '$package_item'"
2027 if [ "$GO" = "yes" ]; then
2028 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
2029 echo "Testing if $package has subrequirements..."
2030 run_poldek -t -i $package --dumpn=".$package-req.txt"
2031 if [ -f ".$package-req.txt" ]; then
2032 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2034 if [ "$package_name" = "$package" ]; then
2035 echo "Installing BuildRequired package:\t$package_name"
2036 update_shell_title "Installing BuildRequired package: ${package_name}"
2037 install_required_packages $package
2039 echo "Installing (sub)Required package:\t$package_name"
2040 update_shell_title "Installing (sub)Required package: ${package_name}"
2041 install_required_packages $package_name
2045 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2046 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2049 echo "Attempting to run spawn sub - builder..."
2050 echo "Package installation failed:\t$package_name"
2051 run_sub_builder $package_name
2052 if [ $? -eq 0 ]; then
2053 install_required_packages $package_name
2056 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2057 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2060 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2067 rm -f ".$package-req.txt"
2069 echo "Attempting to run spawn sub - builder..."
2070 echo "Package installation failed:\t$package"
2071 run_sub_builder $package
2072 if [ $? -eq 0 ]; then
2073 install_required_packages $package
2076 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2077 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2080 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2086 echo "Package $package is already installed. BuildRequirement satisfied."
2090 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2091 echo >&2 "Unable to install following packages and their dependencies:"
2092 for pkg in "$NOT_INSTALLED_PACKAGES"
2096 remove_build_requires
2102 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2103 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2104 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2105 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2108 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2109 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2112 if [ ! -e ../rpm-build-tools ]; then
2113 git clone ${GIT_SERVER}/${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2115 for a in adapter builder fetchsrc_request compile repackage; do
2116 ln -sf ../rpm-build-tools/${a}.sh $a
2119 ln -sf ../rpm-build-tools/${a} $a
2121 ln -sf ../rpm-build-tools/mirrors mirrors
2128 DONT_PRINT_REVISION="yes"
2130 # remove spec and sources
2131 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
2132 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2133 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2136 #---------------------------------------------
2144 while [ $# -gt 0 ]; do
2147 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2148 # unfortunately $GETURI is already formed
2153 COMMAND="update_md5"
2158 COMMAND="update_md5"
2167 DEBUG="yes"; shift ;;
2169 COMMAND="version"; shift ;;
2171 COMMAND="short-version"; shift ;;
2178 -b | -ba | --build )
2179 COMMAND="build"; shift ;;
2180 -bb | --build-binary )
2181 COMMAND="build-binary"; shift ;;
2183 COMMAND="build-build"; shift ;;
2185 COMMAND="build-install"; shift ;;
2187 COMMAND="build-list"; shift ;;
2188 -bp | --build-prep )
2189 COMMAND="build-prep"; shift ;;
2190 -bs | --build-source )
2191 COMMAND="build-source"; shift ;;
2193 COMMAND="branch"; shift; TAG="${1}"; shift;;
2195 CLEAN="--clean"; shift ;;
2197 CVS_FORCE="-f"; shift;;
2203 COMMAND="get"; shift ;;
2205 COMMAND="usage"; shift ;;
2207 PROTOCOL="ftp"; shift ;;
2209 PROTOCOL="http"; shift ;;
2211 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2215 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2219 PARALLEL_DOWNLOADS=$2
2223 PARALLEL_DOWNLOADS=${1#-p}
2227 shift; LOGFILE="${1}"; shift ;;
2229 shift; DEF_NICE_LEVEL=${1}; shift ;;
2230 -ske | --skip-existing-files)
2231 SKIP_EXISTING_FILES="yes"; shift ;;
2233 COMMAND="mr-proper"; shift ;;
2234 -ncs | --no-cvs-specs )
2235 NOCVSSPEC="yes"; shift ;;
2236 -nd | --no-distfiles )
2237 NODIST="yes"; shift ;;
2238 -nm | --no-mirrors )
2239 NOMIRRORS="yes"; shift ;;
2241 NOURLS="yes"; shift ;;
2243 NOSRCS="yes"; shift ;;
2244 -ns0 | --no-source0 )
2245 NOSOURCE0="yes"; shift ;;
2254 -pm | --prefer-mirrors )
2257 --noinit | --no-init )
2261 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2263 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2264 --skip-patch | -sp )
2265 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2267 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2270 --with | --without )
2271 case $GROUP_BCONDS in
2275 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2276 while ! `echo ${1}|grep -qE '(^-|spec)'`
2278 BCOND="$BCOND $COND $1"
2282 if [[ "$2" = *,* ]]; then
2283 for a in $(echo "$2" | tr , ' '); do
2284 BCOND="$BCOND $1 $a"
2287 BCOND="$BCOND $1 $2"
2293 shift; TARGET="${1}"; shift ;;
2295 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2297 QUIET="--quiet"; shift ;;
2299 CVSDATE="${2}"; shift 2
2300 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2310 -R | --fetch-build-requires)
2311 FETCH_BUILD_REQUIRES="yes"
2312 NOT_INSTALLED_PACKAGES=
2314 -RB | --remove-build-requires)
2315 REMOVE_BUILD_REQUIRES="nice"
2317 -FRB | --force-remove-build-requires)
2318 REMOVE_BUILD_REQUIRES="force"
2321 COMMAND="list-sources-cvs"
2323 -sd | --source-distfiles)
2324 COMMAND="list-sources-distfiles"
2326 -sdp | --source-distfiles-paths)
2327 COMMAND="list-sources-distfiles-paths"
2329 -sf | --source-files)
2330 COMMAND="list-sources-files"
2332 -lsp | --source-paths)
2333 COMMAND="list-sources-local-paths"
2335 -su | --source-urls)
2336 COMMAND="list-sources-urls"
2338 -Tvs | --tag-version-stable )
2343 -Ts | --tag-stable )
2348 -Tv | --tag-version )
2353 -Tp | --tag-prefix )
2365 -ir | --integer-release-only )
2366 INTEGER_RELEASE="yes"
2369 COMMAND="update_md5"
2374 -Upi | --update-poldek-indexes )
2375 UPDATE_POLDEK_INDEXES="yes"
2378 COMMAND="init_rpm_dir"
2380 -u | --try-upgrade )
2381 TRY_UPGRADE="1"; shift ;;
2383 shift; UPGRADE_VERSION="$1"; shift;;
2384 -un | --try-upgrade-with-float-version )
2385 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2387 BE_VERBOSE="1"; shift ;;
2392 if echo "${MACRO}" | grep -q '\W'; then
2393 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2397 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2402 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2406 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2409 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2410 COMMAND="show_bconds"
2414 COMMAND="show_bcond_args"
2417 --show-avail-bconds)
2418 COMMAND="show_avail_bconds"
2423 RPMOPTS="${RPMOPTS} --nodeps"
2426 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2430 GIT_SERVER=${PLD_GIT_SERVER}
2431 GIT_PUSH=${PLD_GIT_PUSH}
2432 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2433 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2434 ATTICDISTFILES_SERVER=${PLD_ATTICDISTFILES_SERVER}
2438 GIT_SERVER=${TLD_GIT_SERVER}
2439 GIT_PUSH=${TLD_GIT_PUSH}
2440 PACKAGES_DIR=${TLD_PACKAGES_DIR}
2441 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
2442 ATTICDISTFILES_SERVER=${TLD_ATTICDISTFILES_SERVER}
2445 Exit_error err_invalid_cmdline "$1"
2448 SPECFILE=${1%/}; shift
2449 # check if specname was passed as specname:cvstag
2450 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2451 CVSTAG="${SPECFILE##*:}"
2452 SPECFILE="${SPECFILE%%:*}"
2454 # always have SPECFILE ending with .spec extension
2455 SPECFILE=${SPECFILE%%.spec}.spec
2456 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2460 # Check if given package exists in TLD git
2461 if ! git ls-remote --heads ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME} 1>/dev/null 2>&1; then
2462 # Nope, we don't have it in TLD, switch for PLD repositories
2463 GIT_SERVER=${PLD_GIT_SERVER}
2464 GIT_PUSH=${PLD_GIT_PUSH}
2465 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2466 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2467 ATTICDISTFILES_SERVER=${PLD_ATTICDISTFILES_SERVER}
2470 if [ "$CVSTAG" ]; then
2471 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2472 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2475 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2476 echo >&2 "--all branches requires --depth <number>"
2477 Exit_error err_invalid_cmdline
2480 if [ -n "$DEBUG" ]; then
2485 if [ -n "$TARGET" ]; then
2488 TARGET_SWITCH="--target $TARGET" ;;
2490 TARGET_SWITCH="--target=$TARGET" ;;
2494 if [ "$SCHEDTOOL" != "no" ]; then
2495 NICE_COMMAND="$SCHEDTOOL"
2497 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2500 update_shell_title "$COMMAND"
2504 if [ -z "$SPECFILE" ]; then
2505 Exit_error err_no_spec_in_cmdl
2507 get_spec > /dev/null
2514 if [ -z "$SPECFILE" ]; then
2515 Exit_error err_no_spec_in_cmdl
2517 get_spec > /dev/null
2522 "show_avail_bconds")
2524 if [ -z "$SPECFILE" ]; then
2525 Exit_error err_no_spec_in_cmdl
2528 get_spec > /dev/null
2530 local bcond_avail=$(find_spec_bcond $SPECFILE)
2531 local opt bcond bconds
2532 for opt in $bcond_avail; do
2535 bcond=${opt#without_}
2536 bconds="$bconds $bcond"
2540 bconds="$bconds $bcond"
2543 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2551 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2553 if [ -z "$SPECFILE" ]; then
2554 Exit_error err_no_spec_in_cmdl
2557 # display SMP make flags if set
2558 smp_mflags=$(rpm -E %{?_smp_mflags})
2559 if [ "$smp_mflags" ]; then
2560 echo "builder: SMP make flags are set to $smp_mflags"
2568 if [ "$COMMAND" != "build-source" ]; then
2571 fetch_build_requires
2572 if [ "$INTEGER_RELEASE" = "yes" ]; then
2573 echo "Checking release $PACKAGE_RELEASE..."
2574 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2575 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2579 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2580 if [ -n "$TEST_TAG" ]; then
2581 local TAGVER=`make_tagver`
2582 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2583 # check also tags created in CVS
2584 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2585 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2586 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2587 || Exit_error err_tag_exists $TAGVER_CVS
2588 # - do not allow to build from HEAD when XX-branch exists
2589 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2590 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2591 TAG_BRANCH="${TREE_PREFIX}-branch"
2592 if [ -n "$DEPTH" ]; then
2593 cmd_branches="git ls-remote --heads"
2594 ref_prefix=refs/heads
2596 cmd_branches="git show-ref"
2597 ref_prefix=refs/remotes/${REMOTE_PLD}
2599 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2600 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2601 Exit_error err_branch_exists "$TAG_STATUS"
2607 if [ -n "$NOSOURCE0" ] ; then
2608 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2613 get_files $SOURCES $PATCHES
2614 check_md5 $SOURCES $PATCHES
2617 NODIST="yes" get_files $SOURCES $PATCHES
2618 update_md5 $SOURCES $PATCHES
2622 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2623 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2625 remove_build_requires
2629 if [ -z "$SPECFILE" ]; then
2630 Exit_error err_no_spec_in_cmdl
2639 if [ -z "$SPECFILE" ]; then
2640 Exit_error err_no_spec_in_cmdl
2644 if [ -n "$NEW_REPO" ]; then
2647 for file in $SOURCES $PATCHES; do
2648 if [ -z $(src_md5 "$file") ]; then
2649 git add $file || Exit_error err_no_source_in_repo $file
2651 cvsignore_df `nourl $file`
2655 echo "When you are ready commit your changes and run git push origin master"
2657 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2662 if [ -z "$SPECFILE" ]; then
2663 Exit_error err_no_spec_in_cmdl
2669 if [ -n "$NOSOURCE0" ] ; then
2670 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2672 get_files $SOURCES $PATCHES
2677 if [ -z "$SPECFILE" ]; then
2678 Exit_error err_no_spec_in_cmdl
2684 if [ -n "$NOSOURCE0" ] ; then
2685 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2687 update_md5 $SOURCES $PATCHES
2693 if [ -z "$SPECFILE" ]; then
2694 Exit_error err_no_spec_in_cmdl
2698 if [ ! -d .git ]; then
2699 echo "No git reposiotory" >&2
2707 "list-sources-files" )
2710 DONT_PRINT_REVISION="yes"
2713 for SAP in $SOURCES $PATCHES; do
2714 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2717 "list-sources-urls" )
2720 DONT_PRINT_REVISION="yes"
2723 SAPS="$SOURCES $PATCHES"
2724 for SAP in $SAPS; do
2728 "list-sources-local-paths" )
2731 DONT_PRINT_REVISION="yes"
2734 for SAP in $SOURCES $PATCHES; do
2735 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2738 "list-sources-distfiles-paths" )
2741 DONT_PRINT_REVISION="yes"
2744 for SAP in $SOURCES $PATCHES; do
2745 if [ -n "$(src_md5 "$SAP")" ]; then
2746 distfiles_path "$SAP"
2750 "list-sources-distfiles" )
2753 DONT_PRINT_REVISION="yes"
2756 for SAP in $SOURCES $PATCHES; do
2757 if [ -n "$(src_md5 "$SAP")" ]; then
2758 distfiles_url "$SAP"
2762 "list-sources-cvs" )
2765 DONT_PRINT_REVISION="yes"
2768 for SAP in $SOURCES $PATCHES; do
2769 if [ -z "$(src_md5 "$SAP")" ]; then
2770 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2784 echo "$VERSIONSTRING"
2787 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2788 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2792 # vi:syntax=sh:ts=4:sw=4:noet