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="TLD/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}
122 # rsync repository with git refs of packages
123 PKGREVS_URL="http://pkgrevs.tld-linux.org"
126 TLD_GIT_SERVER="git://git.tld-linux.org"
127 TLD_GIT_PUSH="git@git.tld-linux.org:7272"
128 TLD_PACKAGES_DIR="packages"
129 TLD_DISTFILES_SERVER="://df.tld-linux.org"
132 PLD_GIT_SERVER="git://git.pld-linux.org"
133 PLD_GIT_PUSH="git@git.pld-linux.org"
134 PLD_PACKAGES_DIR="packages"
135 PLD_DISTFILES_SERVER="://distfiles.pld-linux.org"
140 GIT_SERVER=${TLD_GIT_SERVER}
141 GIT_PUSH=${TLD_GIT_PUSH}
142 PACKAGES_DIR=${TLD_PACKAGES_DIR}
151 DISTFILES_SERVER=${TLD_DISTFILES_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 [--git-pld|--git-tld] [--pkgrev] [-lp]
321 <package>[.spec][:tag]
323 -4 - force IPv4 when transferring files
324 -6 - force IPv6 when transferring files
326 --update-md5 - update md5 comments in spec, implies -nd -ncs
328 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
329 --all-branches - make shallow fetch of all branches; --depth required
330 -n5, --no-md5 - ignore md5 comments in spec
331 -D, --debug - enable builder script debugging mode,
332 -debug - produce rpm debug package (same as --opts -debug)
333 -V, --version - output builder version string
334 --short-version - output builder short version
335 -a - try add new package to PLD repo.
338 - get all files from PLD repo or HTTP/FTP and build package
340 -bb - get all files from PLD repo or HTTP/FTP and build binary
341 only package from <package>.spec,
342 -bp - execute the %prep phase of <package>.spec,
343 -bc - execute the %build phase of <package>.spec,
344 -bi - execute the %install phase of <package>.spec
345 -bl - execute the %files phase of <package>.spec
346 -bs - get all files from PLD repo or HTTP/FTP and only pack
348 --short-circuit - short-circuit build
349 -B, --branch - add branch
351 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
352 may be used with building process.
353 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
354 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
355 -cf, --cvs-force - use -f when tagging
356 --define '<macro> <value>'
357 - define a macro <macro> with value <value>,
358 --depth <number> - make shallow fetch
359 --alt_kernel <kernel>
360 - same as --define 'alt_kernel <kernel>'
361 --nodeps - rpm won't check any dependences
363 --get - get <package>.spec and all related files from PLD repo
364 -h, --help - this message,
365 -j N - set %_smp_mflags to propagate concurrent jobs
366 --ftp - use FTP protocol to access distfiles server
367 --http - use HTTP protocol to access distfiles server
368 -l <logfile>, --logtofile=<logfile>
371 - don't pull from PLD repo
372 -nd, --no-distfiles - don't download from distfiles
373 -nm, --no-mirrors - don't download from mirror, if source URL is given,
374 -nu, --no-urls - don't try to download from FTP/HTTP location,
375 -ns, --no-srcs - don't download Sources/Patches
376 -ns0, --no-source0 - don't download Source0
377 -nn, --no-net - don't download anything from the net
378 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
379 -pm, --prefer-mirrors
380 - prefer mirrors (if any) over distfiles for SOURCES
381 --no-init - don't initialize builder paths (SPECS and SOURCES)
383 --skip-existing-files
384 - skip existing files in get_files
385 --opts <rpm opts> - additional options for rpm
386 -q, --quiet - be quiet,
387 --date yyyy-mm-dd - build package using resources from specified date,
388 -r <tag>, --cvstag <ref>
389 - build package using resources from specified branch/tag,
390 -A - build package using master branch as any sticky tags/branch/date being reset.
391 -R, --fetch-build-requires
392 - fetch what is BuildRequired,
393 -RB, --remove-build-requires
394 - remove all you fetched with -R or --fetch-build-requires
395 remember, this option requires confirmation,
396 -FRB, --force-remove-build-requires
397 - remove all you fetched with -R or --fetch-build-requires
398 remember, this option works without confirmation,
399 -sd, --source-distfiles
400 - list sources available from distfiles (intended for offline
401 operations; does not work when Icon field is present
402 but icon file is absent),
403 -sc, --source-cvs - list sources available from PLD repo
404 -sdp, --source-distfiles-paths
405 - list sources available from distfiles -
406 paths relative to distfiles directory (intended for offline
407 operations; does not work when Icon field is present
408 but icon file is absent),
409 -sf, --source-files - list sources - bare filenames (intended for offline
410 operations; does not work when Icon field is present
411 but icon file is absent),
413 - list sources - filenames with full local paths (intended for
414 offline operations; does not work when Icon field is present
415 but icon file is absent),
416 -su, --source-urls - list urls - urls to sources and patches
417 intended for copying urls with spec with lots of macros in urls
418 -T <tag> , --tag <tag>
419 - add git tag <tag> for files,
420 -Tvs, --tag-version-stable
421 - add git tags STABLE and NAME-VERSION-RELEASE for files,
423 - add git tag STABLE for files,
425 --tag-version - add git tag NAME-VERSION-RELEASE for files,
426 -Tp, --tag-prefix <prefix>
427 - add <prefix> to NAME-VERSION-RELEASE tags,
428 -tt, --test-tag <prefix>
429 - fail if tag is already present,
430 -ir, --integer-release-only
431 - allow only integer and snapshot releases
432 -v, --verbose - be verbose,
433 -u, --try-upgrade - check version, and try to upgrade package
434 -un, --try-upgrade-with-float-version
435 - as above, but allow float version
436 php-pear-Services_Digg/
437 --upgrade-version - upgrade to specified version in try-upgrade
438 -U, --update - refetch sources, don't use distfiles, and update md5 comments
439 -Upi, --update-poldek-indexes
440 - refresh or make poldek package index files.
442 --skip-patch <patchnumber>
443 - don't apply <patchnumber>. may be repeated.
445 --nopatch <patchnumber>
446 - abort instead of applying patch <patchnumber>
448 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
449 --show-bconds - show available conditional builds, which can be used
450 - with --with and/or --without switches.
451 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
452 In other words, the output is parseable by scripts.
453 --show-avail-bconds - show available bconds
456 - conditional build package depending on %_with_<feature>/
457 %_without_<feature> macro switch. You may now use
458 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
459 constructions. Set GROUP_BCONDS to yes to make use of it.
460 --target <platform>, --target=<platform>
461 - build for platform <platform>.
462 --init-rpm-dir - initialize ~/rpm directory structure
463 --git-pld - force use of PLD git and distfiles
464 --git-tld - force use of TLD git and distfiles (note: it will fall
465 back to PLD git/df if package doesn't exist in TLD git)
466 --pkgrev - save git revision of package being built into pkgrevs
467 (note: only official TLD source builders are allowed to do so)
468 -lp - list pkgrevs for specified package
472 # create tempfile. as secure as possible
474 mktemp --tmpdir -t builder.$PACKAGE_NAME.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
478 mktemp --tmpdir -d builder.$PACKAGE_NAME.XXXXXX
481 # inserts git log instead of %changelog
482 # outputs name of modified file created by tempfile
484 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
486 # allow this being customized
487 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
489 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
490 # otherwise i'd use --date=iso here
491 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
492 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
493 # NOTE: changelog date is always in UTC for rpmbuild
494 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
495 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
497 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
498 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
501 # add link to full git logs
502 local giturl="http://git.tld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
503 if [ -n "$CVSTAG" ]; then
504 giturl="$giturl;h=$CVSTAG"
506 local gitauthor="TLD Linux <feedback@tld-linux.org>"
507 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
508 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
513 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
514 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
518 " > $specdir/$SPECFILE
519 rm -f $gitlog $speclog
523 # @param string logfile
524 # @param varargs... commands to execute
527 # use teeboth from toys/cleanbuild, if available and enabled
528 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
532 local efile rc logfile=$1; shift
533 if [ "$logfile" ]; then
535 { "$@" 2>&1; echo $? > $efile; } | tee $logfile
546 # change dependency to specname
548 # - perl(Package::Name) -> perl-Package-Name
552 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
556 update_shell_title() {
558 local len=${COLUMNS:-80}
559 local msg="$(echo "$*" | cut -c-$len)"
561 if [ -n "$BE_VERBOSE" ]; then
562 echo >&2 "$(date +%s.%N) $*"
565 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
567 if [ -n "$PACKAGE_NAME" ]; then
568 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
573 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
574 msg=$(echo $msg | tr -d '\n\r')
577 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
580 echo >&2 -ne "\033]0;$msg\007"
586 # set TARGET from BuildArch: from SPECFILE
588 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
589 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
591 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
595 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
597 TARGET_SWITCH="--target=$TARGET" ;;
603 # runs rpm with minimal macroset
605 # we reset macros not to contain macros.build as all the %() macros are
606 # executed here, while none of them are actually needed.
607 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
608 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
610 # TODO: move these to /usr/lib/rpm/macros
611 cat > $BUILDER_MACROS <<'EOF'
612 %x8664 x86_64 amd64 ia32e
615 %bootstrap_release() %{1}
616 %requires_releq_kernel_up(s:n:) %{nil}
617 %requires_releq_kernel_smp(s:n:) %{nil}
618 %requires_releq_kernel(s:n:) %{nil}
619 %requires_releq() %{nil}
620 %pyrequires_eq() %{nil}
621 %requires_eq() %{nil}
622 %requires_eq_to() %{nil}
623 %requires_ge() %{nil}
624 %requires_ge_to() %{nil}
625 %requires_ge() %{nil}
626 %releq_kernel_up(n:) ERROR
627 %releq_kernel_smp(n:) ERROR
628 %releq_kernel(n:) ERROR
629 %py_postclean(x:) ERROR
633 %ruby_ver_requires_eq() %{nil}
634 %ruby_mod_ver_requires_eq() %{nil}
635 %__php_api_requires() %{nil}
636 %php_major_version ERROR
637 %php_api_version ERROR
638 %requires_xorg_xserver_extension %{nil}
639 %requires_xorg_xserver_xinput %{nil}
640 %requires_xorg_xserver_font %{nil}
641 %requires_xorg_xserver_videodrv %{nil}
643 %perl_vendorarch ERROR
644 %perl_vendorlib ERROR
645 # damn. need it here! - copied from /usr/lib/rpm/macros.build
646 %tmpdir %(echo "${TMPDIR:-/tmp}")
647 %patchset_source(f:b:) %(
648 base=%{-b*}%{!-b*:10000};
649 start=$(expr $base + %1);
650 end=$(expr $base + %{?2}%{!?2:%{1}});
651 # we need to call seq twice as it doesn't allow two formats
652 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
653 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
654 paste %{tmpdir}/__ps{1,2};
655 rm -f %{tmpdir}/__ps{1,2};
658 %add_etc_shells(p) %{p:<lua>}
659 %remove_etc_shells(p) %{p:<lua>}
660 %lua_add_etc_shells() %{nil}
661 %lua_remove_etc_shells() %{nil}
663 %buildrequires_jdk %{nil}
664 %pear_package_print_optionalpackages %{nil}
666 if [ "$NOINIT" = "yes" ] ; then
667 cat >> $BUILDER_MACROS <<'EOF'
672 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
676 if [ -n "$DEBUG" ]; then
681 if [ -x /usr/bin/rpm-specdump ]; then
682 update_shell_title "cache_rpm_dump using rpm-specdump command"
683 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
685 update_shell_title "cache_rpm_dump using rpmbuild command"
688 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
689 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
695 ARGS='--nodigest --nosignature --nobuild'
698 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
700 if [ $? -gt 0 ]; then
701 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
703 Exit_error err_build_fail
706 # make small dump cache
707 rpm_dump_cache=`echo "$rpm_dump" | awk '
708 $2 ~ /^SOURCEURL/ {print}
709 $2 ~ /^PATCHURL/ {print}
710 $2 ~ /^nosource/ {print}
711 $2 ~ /^PACKAGE_/ {print}
715 update_shell_title "cache_rpm_dump: OK!"
719 if [ -z "$rpm_dump_cache" ] ; then
720 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
722 echo "$rpm_dump_cache"
726 update_shell_title "get icons"
727 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
728 if [ -z "$ICONS" ]; then
732 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
736 update_shell_title "parsing specfile"
737 if [ -n "$DEBUG" ]; then
742 # icons are needed for successful spec parse
748 if rpm_dump | grep -qEi ":.*nosource.*1"; then
749 FAIL_IF_NO_SOURCES="no"
752 if [ "$NOSRCS" != "yes" ]; then
753 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
754 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
755 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
758 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
759 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
760 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
762 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
763 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
766 if [ -n "$BE_VERBOSE" ]; then
767 echo "- Sources : `nourl $SOURCES`"
768 if [ -n "$PATCHES" ]; then
769 echo "- Patches : `nourl $PATCHES`"
771 echo "- Patches : *no patches needed*"
773 if [ -n "$ICONS" ]; then
774 echo "- Icon : `nourl $ICONS`"
776 echo "- Icon : *no package icon*"
778 echo "- Name : $PACKAGE_NAME"
779 echo "- Version : $PACKAGE_VERSION"
780 echo "- Release : $PACKAGE_RELEASE"
783 update_shell_title "parse_spec: OK!"
787 if [ -n "$DEBUG" ]; then
795 "err_no_spec_in_cmdl" )
796 remove_build_requires
797 echo >&2 "ERROR: spec file name not specified."
799 "err_invalid_cmdline" )
800 echo >&2 "ERROR: invalid command line arg ($2)."
802 "err_no_spec_in_repo" )
803 remove_build_requires
804 echo >&2 "Error: spec file not stored in PLD repo."
806 "err_no_source_in_repo" )
807 remove_build_requires
808 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
810 "err_cvs_add_failed" )
811 echo >&2 "Error: failed to add package to PLD repo."
814 remove_build_requires
815 echo >&2 "Error: package build failed. (${2:-no more info})"
817 "err_no_package_data" )
818 remove_build_requires
819 echo >&2 "Error: couldn't get out package name/version/release from spec file."
822 remove_build_requires
823 echo >&2 "Tag ${2} already exists"
826 remove_build_requires
827 echo >&2 "Release ${2} not integer and not a snapshot."
829 "err_branch_exists" )
830 remove_build_requires
831 echo >&2 "Tree branch already exists (${2})."
834 remove_build_requires
835 echo >&2 "Error: conditions reject building this spec (${2})."
837 "err_remote_problem" )
838 remove_build_requires
839 echo >&2 "Error: problem with remote (${2})"
842 echo >&2 "Error: cannot checkout ${2}"
845 echo >&2 "Error: failed to set package revision for tag ${2}"
848 echo >&2 "Error: failed to get package revision for tag ${2}"
850 "err_not_implemented" )
851 remove_build_requires
852 echo >&2 "Error: functionality not yet imlemented"
855 echo >&2 "Unknown error."
860 if [ -n "$DEBUG" ]; then
865 if [ "$NOINIT" != "yes" ] ; then
866 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
868 local macros_ver=$(rpm -E %?rpm_build_macros)
869 if [ -z "$macros_ver" ]; then
870 REPO_DIR=$TOP_DIR/packages
871 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
873 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
874 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
878 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
884 export GIT_WORK_TREE=$PACKAGE_DIR
885 export GIT_DIR=$PACKAGE_DIR/.git
887 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
888 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
889 CVSTAG=${CVSTAG#refs/heads/}
890 if [ "$CVSTAG" != "master" ]; then
891 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
894 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
897 elif [ "$CVSTAG" = "HEAD" ]; then
898 # assume -r HEAD is same as -A
906 update_shell_title "add_package"
908 if [ -n "$DEBUG" ]; then
914 SPECFILE=$(basename $SPECFILE)
915 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
916 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
919 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
920 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
922 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git && \
923 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} \
924 || Exit_error err_remote_problem $REMOTE_PLD
929 update_shell_title "get_spec"
931 if [ -n "$DEBUG" ]; then
937 SPECFILE=$(basename $SPECFILE)
938 if [ "$NOCVSSPEC" != "yes" ]; then
939 if [ -z "$DEPTH" ]; then
940 if [ -d "$PACKAGE_DIR/.git" ]; then
941 git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
942 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
943 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
944 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
947 Exit_error err_not_implemented
951 git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
952 # softfail if new package, i.e not yet added to PLD rep
953 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
954 echo "Warning: package not in CVS - assuming new package"
957 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
958 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
962 if [ ! -d "$PACKAGE_DIR/.git" ]; then
963 if [ ! -d "$PACKAGE_DIR" ]; then
964 install -d $PACKAGE_DIR
967 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
968 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
969 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
970 CVSTAG=${CVSTAG:-"master"}
973 if [ -z "$ALL_BRANCHES" ]; then
974 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
976 git fetch $DEPTH $REMOTE_PLD $refs || {
977 echo >&2 "Error: branch $CVSTAG does not exist"
981 git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*'
983 cvsignore_df .gitignore
985 # add default log format to .gitignore if it is relative to package dir
986 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
987 # substitute known "macros" to glob
988 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\|TARGET\),*,g')
989 if [ "$logfile" ]; then
990 cvsignore_df "$logfile"
994 # create symlinks for tools
995 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
996 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
997 # skip tools that don't exist in top dir
998 [ -f $a ] || continue
999 # skip tools that already exist
1000 [ -f $PACKAGE_DIR/$a ] && continue
1001 ln -s ../$a $PACKAGE_DIR
1007 if [ -n "$CVSTAG" ]; then
1008 local _rev=$(get_pkgrev "$CVSTAG")
1009 echo "$_rev" | grep -q -E "^ERROR$" || CVSTAG="$_rev"
1010 if git rev-parse --verify -q "$CVSTAG"; then
1011 git checkout "$CVSTAG" --
1012 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1013 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1015 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1016 Exit_error "err_no_checkut" "$CVSTAG"
1018 git merge --ff-only '@{u}'
1019 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1020 if [ -n "$CVSDATE" ]; then
1021 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1025 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1026 Exit_error err_no_spec_in_repo
1029 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1030 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1033 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1041 if [ ! -f "mirrors" ] ; then
1042 ln -s ../rpm-build-tools/mirrors .
1046 local origin mirror name rest ol prefix
1047 while read origin mirror name rest; do
1048 # skip comments and empty lines
1049 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1052 ol=$(echo -n "$origin" | wc -c)
1053 prefix=$(echo -n "$url" | head -c $ol)
1054 if [ "$prefix" = "$origin" ] ; then
1055 suffix=$(echo "$url" | cut -b $((ol+1))-)
1056 echo -n "$mirror$suffix"
1063 # Warning: unpredictable results if same URL used twice
1066 # escape some regexp characters if part of file name
1067 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1070 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1071 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1072 head -n 1 | tr OURCEATH ourceath | xargs
1076 [ "$NO5" = "yes" ] && return
1078 [ -z "$no" ] && return
1082 # use "sources" file from package dir, like vim
1083 if [ -f sources ]; then
1084 md5=$(grep -s -v '^#' sources | \
1085 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1086 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1087 grep -E '^[0-9a-f]{32}$')
1090 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1091 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1093 echo "$md5" | tail -n 1
1098 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1099 if [ -n "$source_md5" ]; then
1102 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1103 if [ -n "$source_md5" ]; then
1106 # we have empty SourceX-md5, but it is still possible
1107 # that we have NoSourceX-md5 AND NoSource: X
1108 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1109 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1117 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1121 echo "$PROTOCOL$DISTFILES_SERVER/$(distfiles_path "$1")"
1126 [ "$md5" = "" ] || \
1127 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1131 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1132 [ -n "$size" -a "$size" -gt 0 ]
1136 if [ "$CVSIGNORE_DF" != "yes" ]; then
1139 cvsignore=${PACKAGE_DIR}/.gitignore
1141 # add only if not yet there
1142 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1143 echo "$1" >> $cvsignore
1147 # returns true if "$1" is ftp, http or https protocol url
1150 ftp://*|http://*|https://*)
1158 if [ $# -eq 0 ]; then
1162 update_shell_title "update md5"
1163 if [ -n "$DEBUG" ]; then
1170 # pass 1: check files to be fetched
1174 local fp=$(nourl "$i")
1175 local srcno=$(src_no "$i")
1176 if [ -n "$ADD5" ]; then
1177 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1178 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1179 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1181 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1183 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1184 need_files="$need_files $i"
1188 # pass 1a: get needed files
1189 if [ "$need_files" ]; then
1190 get_files $need_files
1193 # pass 2: proceed with md5 adding or updating
1195 local fp=$(nourl "$i")
1196 local srcno=$(src_no "$i")
1197 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1198 if [ -z "$md5" ]; then
1199 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1201 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1202 local tag="# $srcno-md5:\t"
1203 if [[ "$md5" == *NoSource* ]]; then
1204 tag="# No$srcno-md5:\t"
1205 elif [ -n "$USEDIGEST" ]; then
1206 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1208 md5=$(md5sum "$fp" | cut -f1 -d' ')
1209 echo "Updating $srcno ($md5: $fp)."
1211 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1212 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1214 $PACKAGE_DIR/$SPECFILE
1221 [ "$NO5" = "yes" ] && return
1223 update_shell_title "check md5"
1227 if ! good_md5 "$i"; then
1228 echo -n "MD5 sum mismatch."
1231 if ! good_size "$i"; then
1232 echo -n "0 sized file."
1236 if [ $bad -eq 1 ]; then
1237 echo " Use -U to refetch sources,"
1238 echo "or -5 to update md5 sums, if you're sure files are correct."
1239 Exit_error err_no_source_in_repo $i
1245 update_shell_title "get_files"
1247 if [ -n "$DEBUG" ]; then
1252 if [ $# -gt 0 ]; then
1256 local get_files_cvs=""
1260 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1261 update_shell_title "$i"
1262 local fp=`nourl "$i"`
1263 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1268 local srcmd5=$(src_md5 "$i")
1270 # we know if source/patch is present in cvs/distfiles
1271 # - has md5 (in distfiles)
1272 # - in cvs... ideas?
1274 # CHECK: local file didn't exist or always cvs up (first) requested.
1275 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1276 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1277 echo "Warning: no URL given for $i"
1281 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1282 if good_md5 "$i" && good_size "$i"; then
1283 echo "$fp having proper md5sum already exists"
1287 # optionally prefer mirror over distfiles if there's mirror
1288 # TODO: build url list and then try each url from the list
1289 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1292 url=$(distfiles_url "$i")
1296 # is $url local file?
1297 if [[ "$url" = [./]* ]]; then
1298 update_shell_title "${GETLOCAL%% *}: $url"
1299 ${GETLOCAL} $url $target
1302 # make shorter message for distfiles urls
1303 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]]; then
1304 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/by-md5/?/?/*/}
1307 update_shell_title "${GETURI%% *}: $uri"
1308 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1309 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1310 update_shell_title "${GETURI2%% *}: $url"
1311 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1315 if [ -s "$target" ]; then
1316 cvsignore_df $target
1323 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1324 if [ -z "$NOMIRRORS" ]; then
1325 im=$(find_mirror "$i")
1329 update_shell_title "${GETURI%% *}: $im"
1330 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1331 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1332 update_shell_title "${GETURI2%% *}: $im"
1333 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1335 test -s "$target" || rm -f "$target"
1338 if [ "$cvsup" = 1 ]; then
1344 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1345 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1346 Exit_error err_no_source_in_repo $i
1349 # we check md5 here just only to refetch immediately
1350 if good_md5 "$i" && good_size "$i"; then
1352 elif [ "$FROM_DISTFILES" = 1 ]; then
1353 # wrong md5 from distfiles: remove the file and try again
1355 echo "MD5 sum mismatch. Trying full fetch."
1358 update_shell_title "${GETURI%% *}: $url"
1359 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1360 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1361 update_shell_title "${GETURI2%% *}: $url"
1362 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1364 test -s "$target" || rm -f "$target"
1367 SHELL_TITLE_PREFIX=""
1370 if [ "$CHMOD" = "yes" ]; then
1371 CHMOD_FILES=$(nourl "$@")
1372 if [ -n "$CHMOD_FILES" ]; then
1373 chmod $CHMOD_MODE $CHMOD_FILES
1380 # If tag exists and points to other commit exit with error
1381 # If it existsts and points to HEAD return 1
1382 # If it doesn't exist return 0
1384 local sha1=$(git rev-parse HEAD)
1385 echo "Searching for tag $_tag..."
1386 if [ -n "$DEPTH" ]; then
1387 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1389 local ref=$(git show-ref -s "refs/tags/$_tag")
1391 [ -z "$ref" ] && return 0
1392 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1397 if [ -n "$DEBUG" ]; then
1402 # Check whether first character of PACKAGE_NAME is legal for tag name
1403 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1407 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1408 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1410 # Remove @kernel.version_release from TAGVER because tagging sources
1411 # could occur with different kernel-headers than kernel-headers used at build time.
1412 # besides, %{_kernel_ver_str} is not expanded.
1414 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1415 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1422 if [ -n "$DEBUG" ]; then
1427 echo "Version: $PACKAGE_VERSION"
1428 echo "Release: $PACKAGE_RELEASE"
1431 if [ "$TAG_VERSION" = "yes" ]; then
1434 if [ -n "$TAG" ]; then
1439 local OPTIONS="tag $CVS_FORCE"
1443 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1444 update_shell_title "tag sources: $_tag"
1445 git $OPTIONS $_tag || exit
1446 git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1448 echo "Tag $_tag already exists and points to the same commit"
1453 [ -z "$1" ] && return 1
1454 local _tmp=$(mktemp /tmp/.builder-XXXX)
1455 rm $_tmp 2>/dev/null
1456 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/get/$1 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1457 local result=$(cat $_tmp)
1458 rm $_tmp 2>/dev/null
1464 if [ "$TAG_VERSION" = "yes" ]; then
1467 if [ -n "$TAG" ]; then
1470 echo "Writing git revision for tag $_tag"
1471 local _tmp=$(mktemp /tmp/.builder-XXXX)
1472 rm $_tmp 2>/dev/null
1473 local _rev=$(git rev-parse HEAD)
1474 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/set/$_rev/$_tag 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1475 local result=$(cat $_tmp)
1476 rm $_tmp 2>/dev/null
1477 [ "$(get_pkgrev "$_tag")" = "$CVSTAG" ] && return 0
1478 echo "$result" | grep -q -E "^OK$" && return 0
1479 echo "$result" | grep -q -E "^EXISTS$" && Exit_error err_tag_exists "$_tag"
1480 Exit_error err_pkgrev_set
1484 local _tmp=$(mktemp /tmp/.builder-XXXX)
1485 rm $_tmp 2>/dev/null
1486 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/list/$PACKAGE_NAME 1>/dev/null 2>&1
1488 rm $_tmp 2>/dev/null
1493 echo "Git branch: $TAG"
1496 if [ -n "$DEBUG" ]; then
1501 local OPTIONS="branch $CVS_FORCE"
1504 git $OPTIONS $TAG || exit
1508 # this function should exit early if package can't be built for this arch
1509 # this avoids unneccessary BR filling.
1512 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1514 if [ $ret -ne 0 ]; then
1526 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1527 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1533 local ver="$2" subver=$ver
1534 local newver="$3" newsubver=$newver
1536 # try handling subver, everything that's not numeric-dotted in version
1537 if grep -Eq '%define\s+subver' $specfile; then
1538 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1540 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1541 newver=${newver%$newsubver}
1544 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1545 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1546 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1551 if [ -n "$TRY_UPGRADE" ]; then
1552 local TNOTIFY TNEWVER TOLDVER
1553 update_shell_title "build_package: try_upgrade"
1557 if [ "$UPGRADE_VERSION" ]; then
1558 TNEWVER=$UPGRADE_VERSION
1560 if [ -n "$FLOAT_VERSION" ]; then
1561 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1563 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1566 # pldnotify.awk does not set exit codes, but it has match for ERROR
1567 # in output which means so.
1568 if [[ "$TNOTIFY" = *ERROR* ]]; then
1573 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1576 if [ -n "$TNEWVER" ]; then
1577 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1578 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1579 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1580 cp -f $SPECFILE $SPECFILE.bak
1583 set_release $SPECFILE $PACKAGE_RELEASE 1
1584 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1586 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1587 echo >&2 "Upgrading version failed, you need to update spec yourself"
1597 update_shell_title "build_package"
1598 if [ -n "$DEBUG" ]; then
1607 BUILD_SWITCH="-ba" ;;
1609 BUILD_SWITCH="-bb" ;;
1611 BUILD_SWITCH="-bs --nodeps" ;;
1613 BUILD_SWITCH="-bp --nodeps" ;;
1615 BUILD_SWITCH="-bc" ;;
1617 BUILD_SWITCH="-bi" ;;
1619 BUILD_SWITCH="-bl" ;;
1623 update_shell_title "build_package: $COMMAND"
1624 local logfile retval
1625 if [ -n "$LOGFILE" ]; then
1626 logfile=`eval echo $LOGFILE`
1627 if [ -d "$logfile" ]; then
1628 echo "Log file $logfile is a directory."
1629 echo "Parse error in the spec?"
1630 Exit_error err_build_fail
1632 if [ -n "$LASTLOG_FILE" ]; then
1633 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1637 local specdir=$(insert_gitlog $SPECFILE)
1638 # FIXME: eval here is exactly why?
1639 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
1643 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1644 if [ "$retval" -eq "0" ]; then
1645 mv $logfile $LOGDIROK
1647 mv $logfile $LOGDIRFAIL
1651 if [ "$retval" -ne "0" ]; then
1652 if [ -n "$TRY_UPGRADE" ]; then
1653 echo "\nUpgrade package to new version failed."
1654 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1655 echo "Restoring old spec file."
1656 mv -f $SPECFILE.bak $SPECFILE
1660 Exit_error err_build_fail
1666 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1669 install_required_packages() {
1674 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1677 /^%changelog/ { exit }
1679 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1680 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1681 gsub(/[ \t]+/, "_", bcond);
1683 }' $SPEC | LC_ALL=C sort -u
1687 # expand bconds from ~/.bcondrc
1688 # The file structure is like gentoo's package.use:
1691 # samba -mysql -pgsql
1692 # w32codec-installer license_agreement
1695 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1701 SN=${SPECFILE%%\.spec}
1703 local bcondrc=$HOME/.bcondrc
1704 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1706 local bcond_avail=$(find_spec_bcond $SPECFILE)
1708 while read pkg flags; do
1710 [[ "$pkg" == \#* ]] && continue
1712 # any package or current package?
1713 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1714 for flag in $flags; do
1715 local opt=${flag#[+-]}
1717 # use only flags which are in this package.
1718 if [[ $bcond_avail = *${opt}* ]]; then
1719 if [[ $flag = -* ]]; then
1720 if [[ $BCOND != *--with?${opt}* ]]; then
1721 BCOND="$BCOND --without $opt"
1724 if [[ $BCOND != *--without?${opt}* ]]; then
1725 BCOND="$BCOND --with $opt"
1732 update_shell_title "parse ~/.bcondrc: DONE!"
1735 set_bconds_values() {
1736 update_shell_title "set bcond values"
1738 AVAIL_BCONDS_WITHOUT=""
1739 AVAIL_BCONDS_WITH=""
1741 if grep -Eq '^# *_with' ${SPECFILE}; then
1742 echo >&2 "ERROR: This spec has old style bconds."
1746 if ! grep -q '^%bcond' ${SPECFILE}; then
1750 local bcond_avail=$(find_spec_bcond $SPECFILE)
1751 process_bcondrc "$SPECFILE"
1753 update_shell_title "parse bconds"
1756 for opt in $bcond_avail; do
1759 bcond=${opt#without_}
1761 *--without?${bcond}*)
1762 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1765 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1773 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1776 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1781 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1790 update_shell_title "run_sub_builder $package_name"
1792 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1793 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1794 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1795 # jakby nie bylo tego kawalka kodu.
1797 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1798 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1802 # kurwa. translate that ^^^^
1806 # Istnieje taki spec? ${package}.spec
1807 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1808 parent_spec_name=${package}.spec
1809 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1810 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1812 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1817 if [ "${parent_spec_name}" != "" ]; then
1818 spawn_sub_builder $parent_spec_name
1820 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1823 spawn_sub_builder() {
1825 update_shell_title "spawn_sub_builder $package_name"
1828 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1829 sub_builder_opts="${sub_builder_opts} -R"
1831 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1832 sub_builder_opts="${sub_builder_opts} -RB"
1833 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1834 sub_builder_opts="${sub_builder_opts} -FRB"
1836 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1837 sub_builder_opts="${sub_builder_opts} -Upi"
1841 ./builder ${sub_builder_opts} "$@"
1844 remove_build_requires() {
1845 if [ "$INSTALLED_PACKAGES" != "" ]; then
1846 case "$REMOVE_BUILD_REQUIRES" in
1848 run_poldek --noask -ve $INSTALLED_PACKAGES
1851 run_poldek --ask -ve $INSTALLED_PACKAGES
1854 echo You may want to manually remove following BuildRequires fetched:
1855 echo $INSTALLED_PACKAGES
1856 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1863 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1864 if [ "$BCOND" ]; then
1866 echo "Building $SPECFILE with the following conditional flags:"
1870 echo "No conditional flags passed"
1873 echo "from available:"
1874 echo "--with :\t$AVAIL_BCONDS_WITH"
1875 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1880 display_branches() {
1881 echo -n "Available branches: "
1882 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1885 # checks a given list of packages/files/provides agains current rpmdb.
1886 # outputs all dependencies which current rpmdb doesn't satisfy.
1887 # input can be either STDIN or parameters
1891 if [ $# -gt 0 ]; then
1897 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1900 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1902 # other deps (files)
1903 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1906 # checks if given package/files/provides exists in rpmdb.
1907 # input can be either stdin or parameters
1908 # returns packages which are present in the rpmdb
1912 if [ $# -gt 0 ]; then
1918 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1921 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1922 install_build_requires_rpmdeps() {
1923 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1924 # TODO: Conflicts list doesn't check versions
1925 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1926 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1928 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1929 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1930 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1933 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1934 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1935 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1936 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1938 if [ -n "$CNFL" ]; then
1939 update_shell_title "uninstall conflicting packages: $CNFL"
1940 echo "Trying to uninstall conflicting packages ($CNFL):"
1941 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1944 while [ "$DEPS" ]; do
1945 update_shell_title "install deps: $DEPS"
1946 echo "Trying to install dependencies ($DEPS):"
1947 local log=.${SPECFILE}_poldek.log
1948 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1949 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1952 if [ -n "$failed" ]; then
1953 for package in $failed; do
1954 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1963 fetch_build_requires()
1965 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1969 update_shell_title "fetch build requires"
1970 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1971 install_build_requires_rpmdeps
1975 # XXX is this ugliest code written in human history still needed?
1976 echo "All packages installed by fetch_build_requires() are written to:"
1977 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1979 echo "If anything fails, you may get rid of them by executing:"
1980 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
1982 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1983 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)
1985 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)
1987 package=$(basename "$package_item"|sed -e "s/}$//g")
1988 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
1991 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1992 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1993 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
1998 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
2001 if `echo $COND_TST|grep -q 'without_'`; then
2002 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
2003 if `echo $COND_TST|grep -q !`; then
2008 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
2009 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
2010 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
2016 elif `echo $COND_TST|grep -q 'with_'`; then
2017 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
2018 if `echo $COND_TST|grep -q !`; then
2023 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
2024 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
2025 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
2031 RESULT="${COND_STATE}-${COND_ARGV}"
2033 "with-wout" | "wout-with" )
2036 "wout-wout" | "with-with" )
2040 echo "Action '$RESULT' was not defined for package '$package_item'"
2046 if [ "$GO" = "yes" ]; then
2047 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
2048 echo "Testing if $package has subrequirements..."
2049 run_poldek -t -i $package --dumpn=".$package-req.txt"
2050 if [ -f ".$package-req.txt" ]; then
2051 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2053 if [ "$package_name" = "$package" ]; then
2054 echo "Installing BuildRequired package:\t$package_name"
2055 update_shell_title "Installing BuildRequired package: ${package_name}"
2056 install_required_packages $package
2058 echo "Installing (sub)Required package:\t$package_name"
2059 update_shell_title "Installing (sub)Required package: ${package_name}"
2060 install_required_packages $package_name
2064 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2065 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2068 echo "Attempting to run spawn sub - builder..."
2069 echo "Package installation failed:\t$package_name"
2070 run_sub_builder $package_name
2071 if [ $? -eq 0 ]; then
2072 install_required_packages $package_name
2075 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2076 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2079 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2086 rm -f ".$package-req.txt"
2088 echo "Attempting to run spawn sub - builder..."
2089 echo "Package installation failed:\t$package"
2090 run_sub_builder $package
2091 if [ $? -eq 0 ]; then
2092 install_required_packages $package
2095 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2096 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2099 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2105 echo "Package $package is already installed. BuildRequirement satisfied."
2109 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2110 echo >&2 "Unable to install following packages and their dependencies:"
2111 for pkg in "$NOT_INSTALLED_PACKAGES"
2115 remove_build_requires
2121 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2122 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2123 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2124 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2127 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2128 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2131 if [ ! -e ../rpm-build-tools ]; then
2132 git clone ${GIT_SERVER}/${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2134 for a in adapter builder fetchsrc_request compile repackage; do
2135 ln -sf ../rpm-build-tools/${a}.sh $a
2138 ln -sf ../rpm-build-tools/${a} $a
2140 ln -sf ../rpm-build-tools/mirrors mirrors
2147 DONT_PRINT_REVISION="yes"
2149 # remove spec and sources
2150 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
2151 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2152 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2155 #---------------------------------------------
2163 while [ $# -gt 0 ]; do
2166 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2167 # unfortunately $GETURI is already formed
2172 COMMAND="update_md5"
2177 COMMAND="update_md5"
2186 DEBUG="yes"; shift ;;
2188 COMMAND="version"; shift ;;
2190 COMMAND="short-version"; shift ;;
2197 -b | -ba | --build )
2198 COMMAND="build"; shift ;;
2199 -bb | --build-binary )
2200 COMMAND="build-binary"; shift ;;
2202 COMMAND="build-build"; shift ;;
2204 COMMAND="build-install"; shift ;;
2206 COMMAND="build-list"; shift ;;
2207 -bp | --build-prep )
2208 COMMAND="build-prep"; shift ;;
2209 -bs | --build-source )
2210 COMMAND="build-source"; shift ;;
2212 COMMAND="branch"; shift; TAG="${1}"; shift;;
2214 CLEAN="--clean"; shift ;;
2216 CVS_FORCE="-f"; shift;;
2222 COMMAND="get"; shift ;;
2224 COMMAND="usage"; shift ;;
2226 PROTOCOL="ftp"; shift ;;
2228 PROTOCOL="http"; shift ;;
2230 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2234 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2238 PARALLEL_DOWNLOADS=$2
2242 PARALLEL_DOWNLOADS=${1#-p}
2246 shift; LOGFILE="${1}"; shift ;;
2248 shift; DEF_NICE_LEVEL=${1}; shift ;;
2249 -ske | --skip-existing-files)
2250 SKIP_EXISTING_FILES="yes"; shift ;;
2252 COMMAND="mr-proper"; shift ;;
2253 -ncs | --no-cvs-specs )
2254 NOCVSSPEC="yes"; shift ;;
2255 -nd | --no-distfiles )
2256 NODIST="yes"; shift ;;
2257 -nm | --no-mirrors )
2258 NOMIRRORS="yes"; shift ;;
2260 NOURLS="yes"; shift ;;
2262 NOSRCS="yes"; shift ;;
2263 -ns0 | --no-source0 )
2264 NOSOURCE0="yes"; shift ;;
2273 -pm | --prefer-mirrors )
2276 --noinit | --no-init )
2280 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2282 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2283 --skip-patch | -sp )
2284 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2286 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2289 --with | --without )
2290 case $GROUP_BCONDS in
2294 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2295 while ! `echo ${1}|grep -qE '(^-|spec)'`
2297 BCOND="$BCOND $COND $1"
2301 if [[ "$2" = *,* ]]; then
2302 for a in $(echo "$2" | tr , ' '); do
2303 BCOND="$BCOND $1 $a"
2306 BCOND="$BCOND $1 $2"
2312 shift; TARGET="${1}"; shift ;;
2314 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2316 QUIET="--quiet"; shift ;;
2318 CVSDATE="${2}"; shift 2
2319 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2329 -R | --fetch-build-requires)
2330 FETCH_BUILD_REQUIRES="yes"
2331 NOT_INSTALLED_PACKAGES=
2333 -RB | --remove-build-requires)
2334 REMOVE_BUILD_REQUIRES="nice"
2336 -FRB | --force-remove-build-requires)
2337 REMOVE_BUILD_REQUIRES="force"
2340 COMMAND="list-sources-cvs"
2342 -sd | --source-distfiles)
2343 COMMAND="list-sources-distfiles"
2345 -sdp | --source-distfiles-paths)
2346 COMMAND="list-sources-distfiles-paths"
2348 -sf | --source-files)
2349 COMMAND="list-sources-files"
2351 -lsp | --source-paths)
2352 COMMAND="list-sources-local-paths"
2354 -su | --source-urls)
2355 COMMAND="list-sources-urls"
2357 -Tvs | --tag-version-stable )
2362 -Ts | --tag-stable )
2367 -Tv | --tag-version )
2372 -Tp | --tag-prefix )
2384 -ir | --integer-release-only )
2385 INTEGER_RELEASE="yes"
2388 COMMAND="update_md5"
2393 -Upi | --update-poldek-indexes )
2394 UPDATE_POLDEK_INDEXES="yes"
2397 COMMAND="init_rpm_dir"
2399 -u | --try-upgrade )
2400 TRY_UPGRADE="1"; shift ;;
2402 shift; UPGRADE_VERSION="$1"; shift;;
2403 -un | --try-upgrade-with-float-version )
2404 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2406 BE_VERBOSE="1"; shift ;;
2411 if echo "${MACRO}" | grep -q '\W'; then
2412 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2416 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2421 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2425 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2428 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2429 COMMAND="show_bconds"
2433 COMMAND="show_bcond_args"
2436 --show-avail-bconds)
2437 COMMAND="show_avail_bconds"
2442 RPMOPTS="${RPMOPTS} --nodeps"
2445 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2449 GIT_SERVER=${PLD_GIT_SERVER}
2450 GIT_PUSH=${PLD_GIT_PUSH}
2451 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2452 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2456 GIT_SERVER=${TLD_GIT_SERVER}
2457 GIT_PUSH=${TLD_GIT_PUSH}
2458 PACKAGES_DIR=${TLD_PACKAGES_DIR}
2459 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
2462 COMMAND="set_pkgrev"
2465 COMMAND="list_pkgrev"
2468 Exit_error err_invalid_cmdline "$1"
2471 SPECFILE=${1%/}; shift
2472 # check if specname was passed as specname:cvstag
2473 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2474 CVSTAG="${SPECFILE##*:}"
2475 SPECFILE="${SPECFILE%%:*}"
2477 # always have SPECFILE ending with .spec extension
2478 SPECFILE=${SPECFILE%%.spec}.spec
2479 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2483 # Check if given package exists in TLD git
2484 if ! git ls-remote --heads ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME} 1>/dev/null 2>&1; then
2485 # Nope, we don't have it in TLD, switch to PLD repositories
2486 GIT_SERVER=${PLD_GIT_SERVER}
2487 GIT_PUSH=${PLD_GIT_PUSH}
2488 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2489 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2492 if [ "$CVSTAG" ]; then
2493 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2494 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2497 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2498 echo >&2 "--all branches requires --depth <number>"
2499 Exit_error err_invalid_cmdline
2502 if [ -n "$DEBUG" ]; then
2507 if [ -n "$TARGET" ]; then
2510 TARGET_SWITCH="--target $TARGET" ;;
2512 TARGET_SWITCH="--target=$TARGET" ;;
2516 if [ "$SCHEDTOOL" != "no" ]; then
2517 NICE_COMMAND="$SCHEDTOOL"
2519 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2522 update_shell_title "$COMMAND"
2526 if [ -z "$SPECFILE" ]; then
2527 Exit_error err_no_spec_in_cmdl
2529 get_spec > /dev/null
2536 if [ -z "$SPECFILE" ]; then
2537 Exit_error err_no_spec_in_cmdl
2539 get_spec > /dev/null
2544 "show_avail_bconds")
2546 if [ -z "$SPECFILE" ]; then
2547 Exit_error err_no_spec_in_cmdl
2550 get_spec > /dev/null
2552 local bcond_avail=$(find_spec_bcond $SPECFILE)
2553 local opt bcond bconds
2554 for opt in $bcond_avail; do
2557 bcond=${opt#without_}
2558 bconds="$bconds $bcond"
2562 bconds="$bconds $bcond"
2565 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2573 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2575 if [ -z "$SPECFILE" ]; then
2576 Exit_error err_no_spec_in_cmdl
2579 # display SMP make flags if set
2580 smp_mflags=$(rpm -E %{?_smp_mflags})
2581 if [ "$smp_mflags" ]; then
2582 echo "builder: SMP make flags are set to $smp_mflags"
2590 if [ "$COMMAND" != "build-source" ]; then
2593 fetch_build_requires
2594 if [ "$INTEGER_RELEASE" = "yes" ]; then
2595 echo "Checking release $PACKAGE_RELEASE..."
2596 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2597 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2601 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2602 if [ -n "$TEST_TAG" ]; then
2605 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2606 # check also tags created in CVS
2607 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2608 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2609 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2610 || Exit_error err_tag_exists $TAGVER_CVS
2611 # - do not allow to build from HEAD when XX-branch exists
2612 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2613 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2614 TAG_BRANCH="${TREE_PREFIX}-branch"
2615 if [ -n "$DEPTH" ]; then
2616 cmd_branches="git ls-remote --heads"
2617 ref_prefix=refs/heads
2619 cmd_branches="git show-ref"
2620 ref_prefix=refs/remotes/${REMOTE_PLD}
2622 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2623 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2624 Exit_error err_branch_exists "$TAG_STATUS"
2630 if [ -n "$NOSOURCE0" ] ; then
2631 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2636 get_files $SOURCES $PATCHES
2637 check_md5 $SOURCES $PATCHES
2640 NODIST="yes" get_files $SOURCES $PATCHES
2641 update_md5 $SOURCES $PATCHES
2645 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2646 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2648 remove_build_requires
2652 if [ -z "$SPECFILE" ]; then
2653 Exit_error err_no_spec_in_cmdl
2662 if [ -z "$SPECFILE" ]; then
2663 Exit_error err_no_spec_in_cmdl
2667 if [ -n "$NEW_REPO" ]; then
2670 for file in $SOURCES $PATCHES; do
2671 if [ -z $(src_md5 "$file") ]; then
2672 git add $file || Exit_error err_no_source_in_repo $file
2674 cvsignore_df `nourl $file`
2678 echo "When you are ready commit your changes and run git push origin master"
2680 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2685 if [ -z "$SPECFILE" ]; then
2686 Exit_error err_no_spec_in_cmdl
2692 if [ -n "$NOSOURCE0" ] ; then
2693 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2695 get_files $SOURCES $PATCHES
2700 if [ -z "$SPECFILE" ]; then
2701 Exit_error err_no_spec_in_cmdl
2707 if [ -n "$NOSOURCE0" ] ; then
2708 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2710 update_md5 $SOURCES $PATCHES
2716 if [ -z "$SPECFILE" ]; then
2717 Exit_error err_no_spec_in_cmdl
2721 if [ ! -d .git ]; then
2722 echo "No git reposiotory" >&2
2730 "list-sources-files" )
2733 DONT_PRINT_REVISION="yes"
2736 for SAP in $SOURCES $PATCHES; do
2737 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2740 "list-sources-urls" )
2743 DONT_PRINT_REVISION="yes"
2746 SAPS="$SOURCES $PATCHES"
2747 for SAP in $SAPS; do
2751 "list-sources-local-paths" )
2754 DONT_PRINT_REVISION="yes"
2757 for SAP in $SOURCES $PATCHES; do
2758 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2761 "list-sources-distfiles-paths" )
2764 DONT_PRINT_REVISION="yes"
2767 for SAP in $SOURCES $PATCHES; do
2768 if [ -n "$(src_md5 "$SAP")" ]; then
2769 distfiles_path "$SAP"
2773 "list-sources-distfiles" )
2776 DONT_PRINT_REVISION="yes"
2779 for SAP in $SOURCES $PATCHES; do
2780 if [ -n "$(src_md5 "$SAP")" ]; then
2781 distfiles_url "$SAP"
2785 "list-sources-cvs" )
2788 DONT_PRINT_REVISION="yes"
2791 for SAP in $SOURCES $PATCHES; do
2792 if [ -z "$(src_md5 "$SAP")" ]; then
2793 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2807 echo "$VERSIONSTRING"
2811 if [ -z "$SPECFILE" ]; then
2812 Exit_error err_no_spec_in_cmdl
2814 get_spec > /dev/null
2822 if [ -z "$SPECFILE" ]; then
2823 Exit_error err_no_spec_in_cmdl
2825 get_spec > /dev/null
2830 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2831 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2835 # vi:syntax=sh:ts=4:sw=4:noet