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"
128 TLD_PACKAGES_DIR="packages"
129 TLD_DISTFILES_SERVER="://df.tld-linux.org"
130 TLD_ATTICDISTFILES_SERVER=""
133 PLD_GIT_SERVER="git://git.pld-linux.org"
134 PLD_GIT_PUSH="git@git.pld-linux.org"
135 PLD_PACKAGES_DIR="packages"
136 PLD_DISTFILES_SERVER="://distfiles.pld-linux.org"
137 PLD_ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
142 GIT_SERVER=${TLD_GIT_SERVER}
143 GIT_PUSH=${TLD_GIT_PUSH}
144 PACKAGES_DIR=${TLD_PACKAGES_DIR}
153 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
154 ATTICDISTFILES_SERVER=${TLD_ATTICDISTFILES_SERVER}
159 FAIL_IF_NO_SOURCES="yes"
161 # let get_files skip over files which are present to get those damn files fetched
162 SKIP_EXISTING_FILES="no"
165 # should the specfile be restored if upgrade failed?
166 REVERT_BROKEN_UPGRADE="yes"
168 if rpm --specsrpm 2>/dev/null; then
169 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
170 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
172 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
173 if [ -x /usr/bin/rpm-getdeps ]; then
174 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
176 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
180 UPDATE_POLDEK_INDEXES_OPTS=""
182 # Here we load saved user environment used to
183 # predefine options set above, or passed to builder
185 # This one reads global system environment settings:
186 if [ -f ~/etc/builderrc ]; then
189 # And this one cascades settings using user personal
191 # Example of ~/.builderrc:
193 #UPDATE_POLDEK_INDEXES="yes"
194 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
195 #FETCH_BUILD_REQUIRES="yes"
196 #REMOVE_BUILD_REQUIRES="force"
198 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
202 if [ -n "$HOME_ETC" ]; then
203 USER_CFG="$HOME_ETC/.builderrc"
204 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
206 USER_CFG=~/.builderrc
207 BUILDER_MACROS=~/.builder-rpmmacros
210 [ -f "$USER_CFG" ] && . "$USER_CFG"
212 if [ "$SCHEDTOOL" = "auto" ]; then
213 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
214 SCHEDTOOL="schedtool -B -e"
220 if [ -n "$USE_PROZILLA" ]; then
221 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
224 elif [ -n "$USE_AXEL" ]; then
225 GETURI="axel -a $AXEL_OPTS"
228 elif [ -n "$USE_LFTP" ]; then
233 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
234 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
235 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
236 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
238 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
239 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
245 if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
256 if [ -d $HOME/rpm/SOURCES ]; then
257 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
258 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
262 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
263 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
268 if [ -n "$LOGFILE" ]; then
269 LOG=`eval echo $LOGFILE`
270 if [ -n "$LASTLOG_FILE" ]; then
271 echo "LASTLOG=$LOG" > $LASTLOG_FILE
273 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
274 # FIXME $exit_pldk undefined
277 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
278 return `cat ${RES_FILE}`
283 #---------------------------------------------
287 local outfile=$1 url=$2 retval tmpfile
291 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
292 set ssl:verify-certificate no;
293 set net:max-retries $WGET_RETRIES;
294 set http:user-agent \"$USER_AGENT\";
295 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
299 if [ $retval -eq 0 ]; then
300 mv -f "$tmpfile" "$outfile"
308 if [ -n "$DEBUG" ]; then set -xv; fi
310 # to make this output parseable by bash-completion _parse_help()
311 # if the line contains short and long option, it will take only the long option
312 # but if you want both being completed, put the short option to separate line
314 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
315 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
316 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
317 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
318 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
319 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
320 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
321 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
322 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
323 [--git-pld|--git-tld] [--pkgrev] [-lp]
324 <package>[.spec][:tag]
326 -4 - force IPv4 when transferring files
327 -6 - force IPv6 when transferring files
329 --update-md5 - update md5 comments in spec, implies -nd -ncs
331 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
332 --all-branches - make shallow fetch of all branches; --depth required
333 -n5, --no-md5 - ignore md5 comments in spec
334 -D, --debug - enable builder script debugging mode,
335 -debug - produce rpm debug package (same as --opts -debug)
336 -V, --version - output builder version string
337 --short-version - output builder short version
338 -a - try add new package to PLD repo.
341 - get all files from PLD repo or HTTP/FTP and build package
343 -bb - get all files from PLD repo or HTTP/FTP and build binary
344 only package from <package>.spec,
345 -bp - execute the %prep phase of <package>.spec,
346 -bc - execute the %build phase of <package>.spec,
347 -bi - execute the %install phase of <package>.spec
348 -bl - execute the %files phase of <package>.spec
349 -bs - get all files from PLD repo or HTTP/FTP and only pack
351 --short-circuit - short-circuit build
352 -B, --branch - add branch
354 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
355 may be used with building process.
356 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
357 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
358 -cf, --cvs-force - use -f when tagging
359 --define '<macro> <value>'
360 - define a macro <macro> with value <value>,
361 --depth <number> - make shallow fetch
362 --alt_kernel <kernel>
363 - same as --define 'alt_kernel <kernel>'
364 --nodeps - rpm won't check any dependences
366 --get - get <package>.spec and all related files from PLD repo
367 -h, --help - this message,
368 -j N - set %_smp_mflags to propagate concurrent jobs
369 --ftp - use FTP protocol to access distfiles server
370 --http - use HTTP protocol to access distfiles server
371 -l <logfile>, --logtofile=<logfile>
374 - don't pull from PLD repo
375 -nd, --no-distfiles - don't download from distfiles
376 -nm, --no-mirrors - don't download from mirror, if source URL is given,
377 -nu, --no-urls - don't try to download from FTP/HTTP location,
378 -ns, --no-srcs - don't download Sources/Patches
379 -ns0, --no-source0 - don't download Source0
380 -nn, --no-net - don't download anything from the net
381 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
382 -pm, --prefer-mirrors
383 - prefer mirrors (if any) over distfiles for SOURCES
384 --no-init - don't initialize builder paths (SPECS and SOURCES)
386 --skip-existing-files
387 - skip existing files in get_files
388 --opts <rpm opts> - additional options for rpm
389 -q, --quiet - be quiet,
390 --date yyyy-mm-dd - build package using resources from specified date,
391 -r <tag>, --cvstag <ref>
392 - build package using resources from specified branch/tag,
393 -A - build package using master branch as any sticky tags/branch/date being reset.
394 -R, --fetch-build-requires
395 - fetch what is BuildRequired,
396 -RB, --remove-build-requires
397 - remove all you fetched with -R or --fetch-build-requires
398 remember, this option requires confirmation,
399 -FRB, --force-remove-build-requires
400 - remove all you fetched with -R or --fetch-build-requires
401 remember, this option works without confirmation,
402 -sd, --source-distfiles
403 - list sources available from distfiles (intended for offline
404 operations; does not work when Icon field is present
405 but icon file is absent),
406 -sc, --source-cvs - list sources available from PLD repo
407 -sdp, --source-distfiles-paths
408 - list sources available from distfiles -
409 paths relative to distfiles directory (intended for offline
410 operations; does not work when Icon field is present
411 but icon file is absent),
412 -sf, --source-files - list sources - bare filenames (intended for offline
413 operations; does not work when Icon field is present
414 but icon file is absent),
416 - list sources - filenames with full local paths (intended for
417 offline operations; does not work when Icon field is present
418 but icon file is absent),
419 -su, --source-urls - list urls - urls to sources and patches
420 intended for copying urls with spec with lots of macros in urls
421 -T <tag> , --tag <tag>
422 - add git tag <tag> for files,
423 -Tvs, --tag-version-stable
424 - add git tags STABLE and NAME-VERSION-RELEASE for files,
426 - add git tag STABLE for files,
428 --tag-version - add git tag NAME-VERSION-RELEASE for files,
429 -Tp, --tag-prefix <prefix>
430 - add <prefix> to NAME-VERSION-RELEASE tags,
431 -tt, --test-tag <prefix>
432 - fail if tag is already present,
433 -ir, --integer-release-only
434 - allow only integer and snapshot releases
435 -v, --verbose - be verbose,
436 -u, --try-upgrade - check version, and try to upgrade package
437 -un, --try-upgrade-with-float-version
438 - as above, but allow float version
439 php-pear-Services_Digg/
440 --upgrade-version - upgrade to specified version in try-upgrade
441 -U, --update - refetch sources, don't use distfiles, and update md5 comments
442 -Upi, --update-poldek-indexes
443 - refresh or make poldek package index files.
445 --skip-patch <patchnumber>
446 - don't apply <patchnumber>. may be repeated.
448 --nopatch <patchnumber>
449 - abort instead of applying patch <patchnumber>
451 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
452 --show-bconds - show available conditional builds, which can be used
453 - with --with and/or --without switches.
454 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
455 In other words, the output is parseable by scripts.
456 --show-avail-bconds - show available bconds
459 - conditional build package depending on %_with_<feature>/
460 %_without_<feature> macro switch. You may now use
461 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
462 constructions. Set GROUP_BCONDS to yes to make use of it.
463 --target <platform>, --target=<platform>
464 - build for platform <platform>.
465 --init-rpm-dir - initialize ~/rpm directory structure
466 --git-pld - force use of PLD git and distfiles
467 --git-tld - force use of TLD git and distfiles (note: it will fall
468 back to PLD git/df if package doesn't exist in TLD git)
469 --pkgrev - save git revision of package being built into pkgrevs
470 (note: only official TLD source builders are allowed to do so)
471 -lp - list pkgrevs for specified package
475 # create tempfile. as secure as possible
477 mktemp --tmpdir -t builder.$PACKAGE_NAME.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
481 mktemp --tmpdir -d builder.$PACKAGE_NAME.XXXXXX
484 # inserts git log instead of %changelog
485 # outputs name of modified file created by tempfile
487 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
489 # allow this being customized
490 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
492 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
493 # otherwise i'd use --date=iso here
494 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
495 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
496 # NOTE: changelog date is always in UTC for rpmbuild
497 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
498 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
500 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
501 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
504 # add link to full git logs
505 local giturl="http://git.tld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
506 if [ -n "$CVSTAG" ]; then
507 giturl="$giturl;h=$CVSTAG"
509 local gitauthor="TLD Linux <feedback@tld-linux.org>"
510 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
511 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
516 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
517 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
521 " > $specdir/$SPECFILE
522 rm -f $gitlog $speclog
526 # @param string logfile
527 # @param varargs... commands to execute
530 # use teeboth from toys/cleanbuild, if available and enabled
531 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
535 local efile rc logfile=$1; shift
536 if [ "$logfile" ]; then
538 { "$@" 2>&1; echo $? > $efile; } | tee $logfile
549 # change dependency to specname
551 # - perl(Package::Name) -> perl-Package-Name
555 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
559 update_shell_title() {
561 local len=${COLUMNS:-80}
562 local msg="$(echo "$*" | cut -c-$len)"
564 if [ -n "$BE_VERBOSE" ]; then
565 echo >&2 "$(date +%s.%N) $*"
568 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
570 if [ -n "$PACKAGE_NAME" ]; then
571 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
576 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
577 msg=$(echo $msg | tr -d '\n\r')
580 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
583 echo >&2 -ne "\033]0;$msg\007"
589 # set TARGET from BuildArch: from SPECFILE
591 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
592 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
594 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
598 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
600 TARGET_SWITCH="--target=$TARGET" ;;
606 # runs rpm with minimal macroset
608 # we reset macros not to contain macros.build as all the %() macros are
609 # executed here, while none of them are actually needed.
610 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
611 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
613 # TODO: move these to /usr/lib/rpm/macros
614 cat > $BUILDER_MACROS <<'EOF'
615 %x8664 x86_64 amd64 ia32e
618 %bootstrap_release() %{1}
619 %requires_releq_kernel_up(s:n:) %{nil}
620 %requires_releq_kernel_smp(s:n:) %{nil}
621 %requires_releq_kernel(s:n:) %{nil}
622 %requires_releq() %{nil}
623 %pyrequires_eq() %{nil}
624 %requires_eq() %{nil}
625 %requires_eq_to() %{nil}
626 %requires_ge() %{nil}
627 %requires_ge_to() %{nil}
628 %requires_ge() %{nil}
629 %releq_kernel_up(n:) ERROR
630 %releq_kernel_smp(n:) ERROR
631 %releq_kernel(n:) ERROR
632 %py_postclean(x:) ERROR
636 %ruby_ver_requires_eq() %{nil}
637 %ruby_mod_ver_requires_eq() %{nil}
638 %__php_api_requires() %{nil}
639 %php_major_version ERROR
640 %php_api_version ERROR
641 %requires_xorg_xserver_extension %{nil}
642 %requires_xorg_xserver_xinput %{nil}
643 %requires_xorg_xserver_font %{nil}
644 %requires_xorg_xserver_videodrv %{nil}
646 %perl_vendorarch ERROR
647 %perl_vendorlib ERROR
648 # damn. need it here! - copied from /usr/lib/rpm/macros.build
649 %tmpdir %(echo "${TMPDIR:-/tmp}")
650 %patchset_source(f:b:) %(
651 base=%{-b*}%{!-b*:10000};
652 start=$(expr $base + %1);
653 end=$(expr $base + %{?2}%{!?2:%{1}});
654 # we need to call seq twice as it doesn't allow two formats
655 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
656 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
657 paste %{tmpdir}/__ps{1,2};
658 rm -f %{tmpdir}/__ps{1,2};
661 %add_etc_shells(p) %{p:<lua>}
662 %remove_etc_shells(p) %{p:<lua>}
663 %lua_add_etc_shells() %{nil}
664 %lua_remove_etc_shells() %{nil}
666 %buildrequires_jdk %{nil}
667 %pear_package_print_optionalpackages %{nil}
669 if [ "$NOINIT" = "yes" ] ; then
670 cat >> $BUILDER_MACROS <<'EOF'
675 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
679 if [ -n "$DEBUG" ]; then
684 if [ -x /usr/bin/rpm-specdump ]; then
685 update_shell_title "cache_rpm_dump using rpm-specdump command"
686 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
688 update_shell_title "cache_rpm_dump using rpmbuild command"
691 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
692 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
698 ARGS='--nodigest --nosignature --nobuild'
701 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
703 if [ $? -gt 0 ]; then
704 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
706 Exit_error err_build_fail
709 # make small dump cache
710 rpm_dump_cache=`echo "$rpm_dump" | awk '
711 $2 ~ /^SOURCEURL/ {print}
712 $2 ~ /^PATCHURL/ {print}
713 $2 ~ /^nosource/ {print}
714 $2 ~ /^PACKAGE_/ {print}
718 update_shell_title "cache_rpm_dump: OK!"
722 if [ -z "$rpm_dump_cache" ] ; then
723 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
725 echo "$rpm_dump_cache"
729 update_shell_title "get icons"
730 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
731 if [ -z "$ICONS" ]; then
735 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
739 update_shell_title "parsing specfile"
740 if [ -n "$DEBUG" ]; then
745 # icons are needed for successful spec parse
751 if rpm_dump | grep -qEi ":.*nosource.*1"; then
752 FAIL_IF_NO_SOURCES="no"
755 if [ "$NOSRCS" != "yes" ]; then
756 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
757 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
758 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
761 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
762 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
763 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
765 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
766 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
769 if [ -n "$BE_VERBOSE" ]; then
770 echo "- Sources : `nourl $SOURCES`"
771 if [ -n "$PATCHES" ]; then
772 echo "- Patches : `nourl $PATCHES`"
774 echo "- Patches : *no patches needed*"
776 if [ -n "$ICONS" ]; then
777 echo "- Icon : `nourl $ICONS`"
779 echo "- Icon : *no package icon*"
781 echo "- Name : $PACKAGE_NAME"
782 echo "- Version : $PACKAGE_VERSION"
783 echo "- Release : $PACKAGE_RELEASE"
786 update_shell_title "parse_spec: OK!"
790 if [ -n "$DEBUG" ]; then
798 "err_no_spec_in_cmdl" )
799 remove_build_requires
800 echo >&2 "ERROR: spec file name not specified."
802 "err_invalid_cmdline" )
803 echo >&2 "ERROR: invalid command line arg ($2)."
805 "err_no_spec_in_repo" )
806 remove_build_requires
807 echo >&2 "Error: spec file not stored in PLD repo."
809 "err_no_source_in_repo" )
810 remove_build_requires
811 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
813 "err_cvs_add_failed" )
814 echo >&2 "Error: failed to add package to PLD repo."
817 remove_build_requires
818 echo >&2 "Error: package build failed. (${2:-no more info})"
820 "err_no_package_data" )
821 remove_build_requires
822 echo >&2 "Error: couldn't get out package name/version/release from spec file."
825 remove_build_requires
826 echo >&2 "Tag ${2} already exists"
829 remove_build_requires
830 echo >&2 "Release ${2} not integer and not a snapshot."
832 "err_branch_exists" )
833 remove_build_requires
834 echo >&2 "Tree branch already exists (${2})."
837 remove_build_requires
838 echo >&2 "Error: conditions reject building this spec (${2})."
840 "err_remote_problem" )
841 remove_build_requires
842 echo >&2 "Error: problem with remote (${2})"
845 echo >&2 "Error: cannot checkout ${2}"
848 echo >&2 "Error: failed to set package revision for tag ${2}"
851 echo >&2 "Error: failed to get package revision for tag ${2}"
853 "err_not_implemented" )
854 remove_build_requires
855 echo >&2 "Error: functionality not yet imlemented"
858 echo >&2 "Unknown error."
863 if [ -n "$DEBUG" ]; then
868 if [ "$NOINIT" != "yes" ] ; then
869 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
871 local macros_ver=$(rpm -E %?rpm_build_macros)
872 if [ -z "$macros_ver" ]; then
873 REPO_DIR=$TOP_DIR/packages
874 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
876 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
877 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
881 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
887 export GIT_WORK_TREE=$PACKAGE_DIR
888 export GIT_DIR=$PACKAGE_DIR/.git
890 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
891 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
892 CVSTAG=${CVSTAG#refs/heads/}
893 if [ "$CVSTAG" != "master" ]; then
894 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
897 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
900 elif [ "$CVSTAG" = "HEAD" ]; then
901 # assume -r HEAD is same as -A
909 update_shell_title "add_package"
911 if [ -n "$DEBUG" ]; then
917 SPECFILE=$(basename $SPECFILE)
918 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
919 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
922 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
923 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
925 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git && \
926 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} \
927 || Exit_error err_remote_problem $REMOTE_PLD
932 update_shell_title "get_spec"
934 if [ -n "$DEBUG" ]; then
940 SPECFILE=$(basename $SPECFILE)
941 if [ "$NOCVSSPEC" != "yes" ]; then
942 if [ -z "$DEPTH" ]; then
943 if [ -d "$PACKAGE_DIR/.git" ]; then
944 git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
945 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
946 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
947 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
950 Exit_error err_not_implemented
954 git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
955 # softfail if new package, i.e not yet added to PLD rep
956 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
957 echo "Warning: package not in CVS - assuming new package"
960 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
961 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
965 if [ ! -d "$PACKAGE_DIR/.git" ]; then
966 if [ ! -d "$PACKAGE_DIR" ]; then
967 install -d $PACKAGE_DIR
970 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
971 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
972 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
973 CVSTAG=${CVSTAG:-"master"}
976 if [ -z "$ALL_BRANCHES" ]; then
977 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
979 git fetch $DEPTH $REMOTE_PLD $refs || {
980 echo >&2 "Error: branch $CVSTAG does not exist"
984 git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*'
986 cvsignore_df .gitignore
988 # add default log format to .gitignore if it is relative to package dir
989 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
990 # substitute known "macros" to glob
991 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\|TARGET\),*,g')
992 if [ "$logfile" ]; then
993 cvsignore_df "$logfile"
997 # create symlinks for tools
998 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
999 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
1000 # skip tools that don't exist in top dir
1001 [ -f $a ] || continue
1002 # skip tools that already exist
1003 [ -f $PACKAGE_DIR/$a ] && continue
1004 ln -s ../$a $PACKAGE_DIR
1010 if [ -n "$CVSTAG" ]; then
1011 local _rev=$(get_pkgrev "$CVSTAG")
1012 echo "$_rev" | grep -q -E "^ERROR$" || CVSTAG="$_rev"
1013 if git rev-parse --verify -q "$CVSTAG"; then
1014 git checkout "$CVSTAG" --
1015 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1016 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1018 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1019 Exit_error "err_no_checkut" "$CVSTAG"
1021 git merge --ff-only '@{u}'
1022 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1023 if [ -n "$CVSDATE" ]; then
1024 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1028 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1029 Exit_error err_no_spec_in_repo
1032 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1033 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1036 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1044 if [ ! -f "mirrors" ] ; then
1045 ln -s ../rpm-build-tools/mirrors .
1049 local origin mirror name rest ol prefix
1050 while read origin mirror name rest; do
1051 # skip comments and empty lines
1052 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1055 ol=$(echo -n "$origin" | wc -c)
1056 prefix=$(echo -n "$url" | head -c $ol)
1057 if [ "$prefix" = "$origin" ] ; then
1058 suffix=$(echo "$url" | cut -b $((ol+1))-)
1059 echo -n "$mirror$suffix"
1066 # Warning: unpredictable results if same URL used twice
1069 # escape some regexp characters if part of file name
1070 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1073 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1074 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1075 head -n 1 | tr OURCEATH ourceath | xargs
1079 [ "$NO5" = "yes" ] && return
1081 [ -z "$no" ] && return
1085 # use "sources" file from package dir, like vim
1086 if [ -f sources ]; then
1087 md5=$(grep -s -v '^#' sources | \
1088 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1089 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1090 grep -E '^[0-9a-f]{32}$')
1093 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1094 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1096 echo "$md5" | tail -n 1
1101 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1102 if [ -n "$source_md5" ]; then
1105 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1106 if [ -n "$source_md5" ]; then
1109 # we have empty SourceX-md5, but it is still possible
1110 # that we have NoSourceX-md5 AND NoSource: X
1111 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1112 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1120 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1124 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1127 distfiles_attic_url() {
1128 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
1133 [ "$md5" = "" ] || \
1134 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1138 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1139 [ -n "$size" -a "$size" -gt 0 ]
1143 if [ "$CVSIGNORE_DF" != "yes" ]; then
1146 cvsignore=${PACKAGE_DIR}/.gitignore
1148 # add only if not yet there
1149 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1150 echo "$1" >> $cvsignore
1154 # returns true if "$1" is ftp, http or https protocol url
1157 ftp://*|http://*|https://*)
1165 if [ $# -eq 0 ]; then
1169 update_shell_title "update md5"
1170 if [ -n "$DEBUG" ]; then
1177 # pass 1: check files to be fetched
1181 local fp=$(nourl "$i")
1182 local srcno=$(src_no "$i")
1183 if [ -n "$ADD5" ]; then
1184 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1185 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1186 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1188 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1190 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1191 need_files="$need_files $i"
1195 # pass 1a: get needed files
1196 if [ "$need_files" ]; then
1197 get_files $need_files
1200 # pass 2: proceed with md5 adding or updating
1202 local fp=$(nourl "$i")
1203 local srcno=$(src_no "$i")
1204 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1205 if [ -z "$md5" ]; then
1206 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1208 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1209 local tag="# $srcno-md5:\t"
1210 if [[ "$md5" == *NoSource* ]]; then
1211 tag="# No$srcno-md5:\t"
1212 elif [ -n "$USEDIGEST" ]; then
1213 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1215 md5=$(md5sum "$fp" | cut -f1 -d' ')
1216 echo "Updating $srcno ($md5: $fp)."
1218 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1219 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1221 $PACKAGE_DIR/$SPECFILE
1228 [ "$NO5" = "yes" ] && return
1230 update_shell_title "check md5"
1234 if ! good_md5 "$i"; then
1235 echo -n "MD5 sum mismatch."
1238 if ! good_size "$i"; then
1239 echo -n "0 sized file."
1243 if [ $bad -eq 1 ]; then
1244 echo " Use -U to refetch sources,"
1245 echo "or -5 to update md5 sums, if you're sure files are correct."
1246 Exit_error err_no_source_in_repo $i
1252 update_shell_title "get_files"
1254 if [ -n "$DEBUG" ]; then
1259 if [ $# -gt 0 ]; then
1263 local get_files_cvs=""
1267 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1268 update_shell_title "$i"
1269 local fp=`nourl "$i"`
1270 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1275 local srcmd5=$(src_md5 "$i")
1277 # we know if source/patch is present in cvs/distfiles
1278 # - has md5 (in distfiles)
1279 # - in cvs... ideas?
1281 # CHECK: local file didn't exist or always cvs up (first) requested.
1282 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1283 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1284 echo "Warning: no URL given for $i"
1288 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1289 if good_md5 "$i" && good_size "$i"; then
1290 echo "$fp having proper md5sum already exists"
1294 # optionally prefer mirror over distfiles if there's mirror
1295 # TODO: build url list and then try each url from the list
1296 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1299 url=$(distfiles_url "$i")
1302 url_attic=$(distfiles_attic_url "$i")
1304 # is $url local file?
1305 if [[ "$url" = [./]* ]]; then
1306 update_shell_title "${GETLOCAL%% *}: $url"
1307 ${GETLOCAL} $url $target
1310 # make shorter message for distfiles urls
1311 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1312 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1313 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1316 update_shell_title "${GETURI%% *}: $uri"
1317 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1318 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1319 update_shell_title "${GETURI2%% *}: $url"
1320 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1325 if [ ! -s "$target" ]; then
1327 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1328 update_shell_title "${GETLOCAL%% *}: $url_attic"
1329 ${GETLOCAL} $url_attic $target
1331 update_shell_title "${GETURI%% *}: $url_attic"
1332 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1333 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1334 update_shell_title "${GETURI2%% *}: $url_attic"
1335 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1337 test -s "$target" || rm -f "$target"
1341 if [ -s "$target" ]; then
1342 cvsignore_df $target
1349 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1350 if [ -z "$NOMIRRORS" ]; then
1351 im=$(find_mirror "$i")
1355 update_shell_title "${GETURI%% *}: $im"
1356 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1357 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1358 update_shell_title "${GETURI2%% *}: $im"
1359 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1361 test -s "$target" || rm -f "$target"
1364 if [ "$cvsup" = 1 ]; then
1370 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1371 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1372 Exit_error err_no_source_in_repo $i
1375 # we check md5 here just only to refetch immediately
1376 if good_md5 "$i" && good_size "$i"; then
1378 elif [ "$FROM_DISTFILES" = 1 ]; then
1379 # wrong md5 from distfiles: remove the file and try again
1381 echo "MD5 sum mismatch. Trying full fetch."
1384 update_shell_title "${GETURI%% *}: $url"
1385 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1386 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1387 update_shell_title "${GETURI2%% *}: $url"
1388 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1390 if [ ! -s "$target" ]; then
1392 update_shell_title "${GETURI%% *}: $url_attic"
1393 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1394 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1395 update_shell_title "${GETURI2%% *}: $url_attic"
1396 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1399 test -s "$target" || rm -f "$target"
1402 SHELL_TITLE_PREFIX=""
1405 if [ "$CHMOD" = "yes" ]; then
1406 CHMOD_FILES=$(nourl "$@")
1407 if [ -n "$CHMOD_FILES" ]; then
1408 chmod $CHMOD_MODE $CHMOD_FILES
1415 # If tag exists and points to other commit exit with error
1416 # If it existsts and points to HEAD return 1
1417 # If it doesn't exist return 0
1419 local sha1=$(git rev-parse HEAD)
1420 echo "Searching for tag $_tag..."
1421 if [ -n "$DEPTH" ]; then
1422 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1424 local ref=$(git show-ref -s "refs/tags/$_tag")
1426 [ -z "$ref" ] && return 0
1427 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1432 if [ -n "$DEBUG" ]; then
1437 # Check whether first character of PACKAGE_NAME is legal for tag name
1438 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1442 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1443 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1445 # Remove @kernel.version_release from TAGVER because tagging sources
1446 # could occur with different kernel-headers than kernel-headers used at build time.
1447 # besides, %{_kernel_ver_str} is not expanded.
1449 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1450 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1457 if [ -n "$DEBUG" ]; then
1462 echo "Version: $PACKAGE_VERSION"
1463 echo "Release: $PACKAGE_RELEASE"
1466 if [ "$TAG_VERSION" = "yes" ]; then
1469 if [ -n "$TAG" ]; then
1474 local OPTIONS="tag $CVS_FORCE"
1478 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1479 update_shell_title "tag sources: $_tag"
1480 git $OPTIONS $_tag || exit
1481 git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1483 echo "Tag $_tag already exists and points to the same commit"
1488 [ -z "$1" ] && return 1
1489 local _tmp=$(mktemp /tmp/.builder-XXXX)
1490 rm $_tmp 2>/dev/null
1491 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/get/$1 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1492 local result=$(cat $_tmp)
1493 rm $_tmp 2>/dev/null
1499 if [ "$TAG_VERSION" = "yes" ]; then
1502 if [ -n "$TAG" ]; then
1505 echo "Writing git revision for tag $_tag"
1506 local _tmp=$(mktemp /tmp/.builder-XXXX)
1507 rm $_tmp 2>/dev/null
1508 local _rev=$(git rev-parse HEAD)
1509 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/set/$_rev/$_tag 1>/dev/null 2>&1 || Exit_error err_pkgrev_get "$1"
1510 local result=$(cat $_tmp)
1511 rm $_tmp 2>/dev/null
1512 [ "$(get_pkgrev "$_tag")" = "$CVSTAG" ] && return 0
1513 echo "$result" | grep -q -E "^OK$" && return 0
1514 echo "$result" | grep -q -E "^EXISTS$" && Exit_error err_tag_exists "$_tag"
1515 Exit_error err_pkgrev_set
1519 local _tmp=$(mktemp /tmp/.builder-XXXX)
1520 rm $_tmp 2>/dev/null
1521 $GETURI $OUTFILEOPT $_tmp $PKGREVS_URL/list/$PACKAGE_NAME 1>/dev/null 2>&1
1523 rm $_tmp 2>/dev/null
1528 echo "Git branch: $TAG"
1531 if [ -n "$DEBUG" ]; then
1536 local OPTIONS="branch $CVS_FORCE"
1539 git $OPTIONS $TAG || exit
1543 # this function should exit early if package can't be built for this arch
1544 # this avoids unneccessary BR filling.
1547 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1549 if [ $ret -ne 0 ]; then
1561 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1562 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1568 local ver="$2" subver=$ver
1569 local newver="$3" newsubver=$newver
1571 # try handling subver, everything that's not numeric-dotted in version
1572 if grep -Eq '%define\s+subver' $specfile; then
1573 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1575 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1576 newver=${newver%$newsubver}
1579 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1580 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1581 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1586 if [ -n "$TRY_UPGRADE" ]; then
1587 local TNOTIFY TNEWVER TOLDVER
1588 update_shell_title "build_package: try_upgrade"
1592 if [ "$UPGRADE_VERSION" ]; then
1593 TNEWVER=$UPGRADE_VERSION
1595 if [ -n "$FLOAT_VERSION" ]; then
1596 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1598 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1601 # pldnotify.awk does not set exit codes, but it has match for ERROR
1602 # in output which means so.
1603 if [[ "$TNOTIFY" = *ERROR* ]]; then
1608 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1611 if [ -n "$TNEWVER" ]; then
1612 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1613 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1614 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1615 cp -f $SPECFILE $SPECFILE.bak
1618 set_release $SPECFILE $PACKAGE_RELEASE 1
1619 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1621 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1622 echo >&2 "Upgrading version failed, you need to update spec yourself"
1632 update_shell_title "build_package"
1633 if [ -n "$DEBUG" ]; then
1642 BUILD_SWITCH="-ba" ;;
1644 BUILD_SWITCH="-bb" ;;
1646 BUILD_SWITCH="-bs --nodeps" ;;
1648 BUILD_SWITCH="-bp --nodeps" ;;
1650 BUILD_SWITCH="-bc" ;;
1652 BUILD_SWITCH="-bi" ;;
1654 BUILD_SWITCH="-bl" ;;
1658 update_shell_title "build_package: $COMMAND"
1659 local logfile retval
1660 if [ -n "$LOGFILE" ]; then
1661 logfile=`eval echo $LOGFILE`
1662 if [ -d "$logfile" ]; then
1663 echo "Log file $logfile is a directory."
1664 echo "Parse error in the spec?"
1665 Exit_error err_build_fail
1667 if [ -n "$LASTLOG_FILE" ]; then
1668 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1672 local specdir=$(insert_gitlog $SPECFILE)
1673 # FIXME: eval here is exactly why?
1674 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
1678 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1679 if [ "$retval" -eq "0" ]; then
1680 mv $logfile $LOGDIROK
1682 mv $logfile $LOGDIRFAIL
1686 if [ "$retval" -ne "0" ]; then
1687 if [ -n "$TRY_UPGRADE" ]; then
1688 echo "\nUpgrade package to new version failed."
1689 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1690 echo "Restoring old spec file."
1691 mv -f $SPECFILE.bak $SPECFILE
1695 Exit_error err_build_fail
1701 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1704 install_required_packages() {
1709 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1712 /^%changelog/ { exit }
1714 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1715 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1716 gsub(/[ \t]+/, "_", bcond);
1718 }' $SPEC | LC_ALL=C sort -u
1722 # expand bconds from ~/.bcondrc
1723 # The file structure is like gentoo's package.use:
1726 # samba -mysql -pgsql
1727 # w32codec-installer license_agreement
1730 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1736 SN=${SPECFILE%%\.spec}
1738 local bcondrc=$HOME/.bcondrc
1739 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1741 local bcond_avail=$(find_spec_bcond $SPECFILE)
1743 while read pkg flags; do
1745 [[ "$pkg" == \#* ]] && continue
1747 # any package or current package?
1748 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1749 for flag in $flags; do
1750 local opt=${flag#[+-]}
1752 # use only flags which are in this package.
1753 if [[ $bcond_avail = *${opt}* ]]; then
1754 if [[ $flag = -* ]]; then
1755 if [[ $BCOND != *--with?${opt}* ]]; then
1756 BCOND="$BCOND --without $opt"
1759 if [[ $BCOND != *--without?${opt}* ]]; then
1760 BCOND="$BCOND --with $opt"
1767 update_shell_title "parse ~/.bcondrc: DONE!"
1770 set_bconds_values() {
1771 update_shell_title "set bcond values"
1773 AVAIL_BCONDS_WITHOUT=""
1774 AVAIL_BCONDS_WITH=""
1776 if grep -Eq '^# *_with' ${SPECFILE}; then
1777 echo >&2 "ERROR: This spec has old style bconds."
1781 if ! grep -q '^%bcond' ${SPECFILE}; then
1785 local bcond_avail=$(find_spec_bcond $SPECFILE)
1786 process_bcondrc "$SPECFILE"
1788 update_shell_title "parse bconds"
1791 for opt in $bcond_avail; do
1794 bcond=${opt#without_}
1796 *--without?${bcond}*)
1797 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1800 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1808 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1811 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1816 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1825 update_shell_title "run_sub_builder $package_name"
1827 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1828 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1829 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1830 # jakby nie bylo tego kawalka kodu.
1832 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1833 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1837 # kurwa. translate that ^^^^
1841 # Istnieje taki spec? ${package}.spec
1842 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1843 parent_spec_name=${package}.spec
1844 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1845 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1847 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1852 if [ "${parent_spec_name}" != "" ]; then
1853 spawn_sub_builder $parent_spec_name
1855 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1858 spawn_sub_builder() {
1860 update_shell_title "spawn_sub_builder $package_name"
1863 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1864 sub_builder_opts="${sub_builder_opts} -R"
1866 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1867 sub_builder_opts="${sub_builder_opts} -RB"
1868 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1869 sub_builder_opts="${sub_builder_opts} -FRB"
1871 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1872 sub_builder_opts="${sub_builder_opts} -Upi"
1876 ./builder ${sub_builder_opts} "$@"
1879 remove_build_requires() {
1880 if [ "$INSTALLED_PACKAGES" != "" ]; then
1881 case "$REMOVE_BUILD_REQUIRES" in
1883 run_poldek --noask -ve $INSTALLED_PACKAGES
1886 run_poldek --ask -ve $INSTALLED_PACKAGES
1889 echo You may want to manually remove following BuildRequires fetched:
1890 echo $INSTALLED_PACKAGES
1891 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1898 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1899 if [ "$BCOND" ]; then
1901 echo "Building $SPECFILE with the following conditional flags:"
1905 echo "No conditional flags passed"
1908 echo "from available:"
1909 echo "--with :\t$AVAIL_BCONDS_WITH"
1910 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1915 display_branches() {
1916 echo -n "Available branches: "
1917 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1920 # checks a given list of packages/files/provides agains current rpmdb.
1921 # outputs all dependencies which current rpmdb doesn't satisfy.
1922 # input can be either STDIN or parameters
1926 if [ $# -gt 0 ]; then
1932 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1935 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1937 # other deps (files)
1938 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1941 # checks if given package/files/provides exists in rpmdb.
1942 # input can be either stdin or parameters
1943 # returns packages which are present in the rpmdb
1947 if [ $# -gt 0 ]; then
1953 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1956 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1957 install_build_requires_rpmdeps() {
1958 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1959 # TODO: Conflicts list doesn't check versions
1960 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1961 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1963 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1964 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1965 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1968 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1969 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1970 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1971 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1973 if [ -n "$CNFL" ]; then
1974 update_shell_title "uninstall conflicting packages: $CNFL"
1975 echo "Trying to uninstall conflicting packages ($CNFL):"
1976 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1979 while [ "$DEPS" ]; do
1980 update_shell_title "install deps: $DEPS"
1981 echo "Trying to install dependencies ($DEPS):"
1982 local log=.${SPECFILE}_poldek.log
1983 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1984 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1987 if [ -n "$failed" ]; then
1988 for package in $failed; do
1989 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1998 fetch_build_requires()
2000 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
2004 update_shell_title "fetch build requires"
2005 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2006 install_build_requires_rpmdeps
2010 # XXX is this ugliest code written in human history still needed?
2011 echo "All packages installed by fetch_build_requires() are written to:"
2012 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2014 echo "If anything fails, you may get rid of them by executing:"
2015 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
2017 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2018 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)
2020 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)
2022 package=$(basename "$package_item"|sed -e "s/}$//g")
2023 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
2026 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
2027 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
2028 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
2033 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
2036 if `echo $COND_TST|grep -q 'without_'`; then
2037 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
2038 if `echo $COND_TST|grep -q !`; then
2043 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
2044 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
2045 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
2051 elif `echo $COND_TST|grep -q 'with_'`; then
2052 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
2053 if `echo $COND_TST|grep -q !`; then
2058 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
2059 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
2060 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
2066 RESULT="${COND_STATE}-${COND_ARGV}"
2068 "with-wout" | "wout-with" )
2071 "wout-wout" | "with-with" )
2075 echo "Action '$RESULT' was not defined for package '$package_item'"
2081 if [ "$GO" = "yes" ]; then
2082 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
2083 echo "Testing if $package has subrequirements..."
2084 run_poldek -t -i $package --dumpn=".$package-req.txt"
2085 if [ -f ".$package-req.txt" ]; then
2086 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2088 if [ "$package_name" = "$package" ]; then
2089 echo "Installing BuildRequired package:\t$package_name"
2090 update_shell_title "Installing BuildRequired package: ${package_name}"
2091 install_required_packages $package
2093 echo "Installing (sub)Required package:\t$package_name"
2094 update_shell_title "Installing (sub)Required package: ${package_name}"
2095 install_required_packages $package_name
2099 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2100 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2103 echo "Attempting to run spawn sub - builder..."
2104 echo "Package installation failed:\t$package_name"
2105 run_sub_builder $package_name
2106 if [ $? -eq 0 ]; then
2107 install_required_packages $package_name
2110 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2111 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2114 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2121 rm -f ".$package-req.txt"
2123 echo "Attempting to run spawn sub - builder..."
2124 echo "Package installation failed:\t$package"
2125 run_sub_builder $package
2126 if [ $? -eq 0 ]; then
2127 install_required_packages $package
2130 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2131 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2134 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2140 echo "Package $package is already installed. BuildRequirement satisfied."
2144 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2145 echo >&2 "Unable to install following packages and their dependencies:"
2146 for pkg in "$NOT_INSTALLED_PACKAGES"
2150 remove_build_requires
2156 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2157 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2158 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2159 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2162 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2163 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2166 if [ ! -e ../rpm-build-tools ]; then
2167 git clone ${GIT_SERVER}/${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2169 for a in adapter builder fetchsrc_request compile repackage; do
2170 ln -sf ../rpm-build-tools/${a}.sh $a
2173 ln -sf ../rpm-build-tools/${a} $a
2175 ln -sf ../rpm-build-tools/mirrors mirrors
2182 DONT_PRINT_REVISION="yes"
2184 # remove spec and sources
2185 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
2186 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2187 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2190 #---------------------------------------------
2198 while [ $# -gt 0 ]; do
2201 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2202 # unfortunately $GETURI is already formed
2207 COMMAND="update_md5"
2212 COMMAND="update_md5"
2221 DEBUG="yes"; shift ;;
2223 COMMAND="version"; shift ;;
2225 COMMAND="short-version"; shift ;;
2232 -b | -ba | --build )
2233 COMMAND="build"; shift ;;
2234 -bb | --build-binary )
2235 COMMAND="build-binary"; shift ;;
2237 COMMAND="build-build"; shift ;;
2239 COMMAND="build-install"; shift ;;
2241 COMMAND="build-list"; shift ;;
2242 -bp | --build-prep )
2243 COMMAND="build-prep"; shift ;;
2244 -bs | --build-source )
2245 COMMAND="build-source"; shift ;;
2247 COMMAND="branch"; shift; TAG="${1}"; shift;;
2249 CLEAN="--clean"; shift ;;
2251 CVS_FORCE="-f"; shift;;
2257 COMMAND="get"; shift ;;
2259 COMMAND="usage"; shift ;;
2261 PROTOCOL="ftp"; shift ;;
2263 PROTOCOL="http"; shift ;;
2265 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2269 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2273 PARALLEL_DOWNLOADS=$2
2277 PARALLEL_DOWNLOADS=${1#-p}
2281 shift; LOGFILE="${1}"; shift ;;
2283 shift; DEF_NICE_LEVEL=${1}; shift ;;
2284 -ske | --skip-existing-files)
2285 SKIP_EXISTING_FILES="yes"; shift ;;
2287 COMMAND="mr-proper"; shift ;;
2288 -ncs | --no-cvs-specs )
2289 NOCVSSPEC="yes"; shift ;;
2290 -nd | --no-distfiles )
2291 NODIST="yes"; shift ;;
2292 -nm | --no-mirrors )
2293 NOMIRRORS="yes"; shift ;;
2295 NOURLS="yes"; shift ;;
2297 NOSRCS="yes"; shift ;;
2298 -ns0 | --no-source0 )
2299 NOSOURCE0="yes"; shift ;;
2308 -pm | --prefer-mirrors )
2311 --noinit | --no-init )
2315 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2317 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2318 --skip-patch | -sp )
2319 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2321 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2324 --with | --without )
2325 case $GROUP_BCONDS in
2329 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2330 while ! `echo ${1}|grep -qE '(^-|spec)'`
2332 BCOND="$BCOND $COND $1"
2336 if [[ "$2" = *,* ]]; then
2337 for a in $(echo "$2" | tr , ' '); do
2338 BCOND="$BCOND $1 $a"
2341 BCOND="$BCOND $1 $2"
2347 shift; TARGET="${1}"; shift ;;
2349 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2351 QUIET="--quiet"; shift ;;
2353 CVSDATE="${2}"; shift 2
2354 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2364 -R | --fetch-build-requires)
2365 FETCH_BUILD_REQUIRES="yes"
2366 NOT_INSTALLED_PACKAGES=
2368 -RB | --remove-build-requires)
2369 REMOVE_BUILD_REQUIRES="nice"
2371 -FRB | --force-remove-build-requires)
2372 REMOVE_BUILD_REQUIRES="force"
2375 COMMAND="list-sources-cvs"
2377 -sd | --source-distfiles)
2378 COMMAND="list-sources-distfiles"
2380 -sdp | --source-distfiles-paths)
2381 COMMAND="list-sources-distfiles-paths"
2383 -sf | --source-files)
2384 COMMAND="list-sources-files"
2386 -lsp | --source-paths)
2387 COMMAND="list-sources-local-paths"
2389 -su | --source-urls)
2390 COMMAND="list-sources-urls"
2392 -Tvs | --tag-version-stable )
2397 -Ts | --tag-stable )
2402 -Tv | --tag-version )
2407 -Tp | --tag-prefix )
2419 -ir | --integer-release-only )
2420 INTEGER_RELEASE="yes"
2423 COMMAND="update_md5"
2428 -Upi | --update-poldek-indexes )
2429 UPDATE_POLDEK_INDEXES="yes"
2432 COMMAND="init_rpm_dir"
2434 -u | --try-upgrade )
2435 TRY_UPGRADE="1"; shift ;;
2437 shift; UPGRADE_VERSION="$1"; shift;;
2438 -un | --try-upgrade-with-float-version )
2439 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2441 BE_VERBOSE="1"; shift ;;
2446 if echo "${MACRO}" | grep -q '\W'; then
2447 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2451 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2456 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2460 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2463 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2464 COMMAND="show_bconds"
2468 COMMAND="show_bcond_args"
2471 --show-avail-bconds)
2472 COMMAND="show_avail_bconds"
2477 RPMOPTS="${RPMOPTS} --nodeps"
2480 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2484 GIT_SERVER=${PLD_GIT_SERVER}
2485 GIT_PUSH=${PLD_GIT_PUSH}
2486 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2487 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2488 ATTICDISTFILES_SERVER=${PLD_ATTICDISTFILES_SERVER}
2492 GIT_SERVER=${TLD_GIT_SERVER}
2493 GIT_PUSH=${TLD_GIT_PUSH}
2494 PACKAGES_DIR=${TLD_PACKAGES_DIR}
2495 DISTFILES_SERVER=${TLD_DISTFILES_SERVER}
2496 ATTICDISTFILES_SERVER=${TLD_ATTICDISTFILES_SERVER}
2499 COMMAND="set_pkgrev"
2502 COMMAND="list_pkgrev"
2505 Exit_error err_invalid_cmdline "$1"
2508 SPECFILE=${1%/}; shift
2509 # check if specname was passed as specname:cvstag
2510 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2511 CVSTAG="${SPECFILE##*:}"
2512 SPECFILE="${SPECFILE%%:*}"
2514 # always have SPECFILE ending with .spec extension
2515 SPECFILE=${SPECFILE%%.spec}.spec
2516 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2520 # Check if given package exists in TLD git
2521 if ! git ls-remote --heads ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME} 1>/dev/null 2>&1; then
2522 # Nope, we don't have it in TLD, switch to PLD repositories
2523 GIT_SERVER=${PLD_GIT_SERVER}
2524 GIT_PUSH=${PLD_GIT_PUSH}
2525 PACKAGES_DIR=${PLD_PACKAGES_DIR}
2526 DISTFILES_SERVER=${PLD_DISTFILES_SERVER}
2527 ATTICDISTFILES_SERVER=${PLD_ATTICDISTFILES_SERVER}
2530 if [ "$CVSTAG" ]; then
2531 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2532 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2535 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2536 echo >&2 "--all branches requires --depth <number>"
2537 Exit_error err_invalid_cmdline
2540 if [ -n "$DEBUG" ]; then
2545 if [ -n "$TARGET" ]; then
2548 TARGET_SWITCH="--target $TARGET" ;;
2550 TARGET_SWITCH="--target=$TARGET" ;;
2554 if [ "$SCHEDTOOL" != "no" ]; then
2555 NICE_COMMAND="$SCHEDTOOL"
2557 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2560 update_shell_title "$COMMAND"
2564 if [ -z "$SPECFILE" ]; then
2565 Exit_error err_no_spec_in_cmdl
2567 get_spec > /dev/null
2574 if [ -z "$SPECFILE" ]; then
2575 Exit_error err_no_spec_in_cmdl
2577 get_spec > /dev/null
2582 "show_avail_bconds")
2584 if [ -z "$SPECFILE" ]; then
2585 Exit_error err_no_spec_in_cmdl
2588 get_spec > /dev/null
2590 local bcond_avail=$(find_spec_bcond $SPECFILE)
2591 local opt bcond bconds
2592 for opt in $bcond_avail; do
2595 bcond=${opt#without_}
2596 bconds="$bconds $bcond"
2600 bconds="$bconds $bcond"
2603 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2611 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2613 if [ -z "$SPECFILE" ]; then
2614 Exit_error err_no_spec_in_cmdl
2617 # display SMP make flags if set
2618 smp_mflags=$(rpm -E %{?_smp_mflags})
2619 if [ "$smp_mflags" ]; then
2620 echo "builder: SMP make flags are set to $smp_mflags"
2628 if [ "$COMMAND" != "build-source" ]; then
2631 fetch_build_requires
2632 if [ "$INTEGER_RELEASE" = "yes" ]; then
2633 echo "Checking release $PACKAGE_RELEASE..."
2634 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2635 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2639 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2640 if [ -n "$TEST_TAG" ]; then
2643 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2644 # check also tags created in CVS
2645 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2646 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2647 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2648 || Exit_error err_tag_exists $TAGVER_CVS
2649 # - do not allow to build from HEAD when XX-branch exists
2650 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2651 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2652 TAG_BRANCH="${TREE_PREFIX}-branch"
2653 if [ -n "$DEPTH" ]; then
2654 cmd_branches="git ls-remote --heads"
2655 ref_prefix=refs/heads
2657 cmd_branches="git show-ref"
2658 ref_prefix=refs/remotes/${REMOTE_PLD}
2660 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2661 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2662 Exit_error err_branch_exists "$TAG_STATUS"
2668 if [ -n "$NOSOURCE0" ] ; then
2669 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2674 get_files $SOURCES $PATCHES
2675 check_md5 $SOURCES $PATCHES
2678 NODIST="yes" get_files $SOURCES $PATCHES
2679 update_md5 $SOURCES $PATCHES
2683 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2684 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2686 remove_build_requires
2690 if [ -z "$SPECFILE" ]; then
2691 Exit_error err_no_spec_in_cmdl
2700 if [ -z "$SPECFILE" ]; then
2701 Exit_error err_no_spec_in_cmdl
2705 if [ -n "$NEW_REPO" ]; then
2708 for file in $SOURCES $PATCHES; do
2709 if [ -z $(src_md5 "$file") ]; then
2710 git add $file || Exit_error err_no_source_in_repo $file
2712 cvsignore_df `nourl $file`
2716 echo "When you are ready commit your changes and run git push origin master"
2718 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2723 if [ -z "$SPECFILE" ]; then
2724 Exit_error err_no_spec_in_cmdl
2730 if [ -n "$NOSOURCE0" ] ; then
2731 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2733 get_files $SOURCES $PATCHES
2738 if [ -z "$SPECFILE" ]; then
2739 Exit_error err_no_spec_in_cmdl
2745 if [ -n "$NOSOURCE0" ] ; then
2746 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2748 update_md5 $SOURCES $PATCHES
2754 if [ -z "$SPECFILE" ]; then
2755 Exit_error err_no_spec_in_cmdl
2759 if [ ! -d .git ]; then
2760 echo "No git reposiotory" >&2
2768 "list-sources-files" )
2771 DONT_PRINT_REVISION="yes"
2774 for SAP in $SOURCES $PATCHES; do
2775 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2778 "list-sources-urls" )
2781 DONT_PRINT_REVISION="yes"
2784 SAPS="$SOURCES $PATCHES"
2785 for SAP in $SAPS; do
2789 "list-sources-local-paths" )
2792 DONT_PRINT_REVISION="yes"
2795 for SAP in $SOURCES $PATCHES; do
2796 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2799 "list-sources-distfiles-paths" )
2802 DONT_PRINT_REVISION="yes"
2805 for SAP in $SOURCES $PATCHES; do
2806 if [ -n "$(src_md5 "$SAP")" ]; then
2807 distfiles_path "$SAP"
2811 "list-sources-distfiles" )
2814 DONT_PRINT_REVISION="yes"
2817 for SAP in $SOURCES $PATCHES; do
2818 if [ -n "$(src_md5 "$SAP")" ]; then
2819 distfiles_url "$SAP"
2823 "list-sources-cvs" )
2826 DONT_PRINT_REVISION="yes"
2829 for SAP in $SOURCES $PATCHES; do
2830 if [ -z "$(src_md5 "$SAP")" ]; then
2831 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2845 echo "$VERSIONSTRING"
2849 if [ -z "$SPECFILE" ]; then
2850 Exit_error err_no_spec_in_cmdl
2852 get_spec > /dev/null
2860 if [ -z "$SPECFILE" ]; then
2861 Exit_error err_no_spec_in_cmdl
2863 get_spec > /dev/null
2868 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2869 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2873 # vi:syntax=sh:ts=4:sw=4:noet