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-2014 Free Penguins".
44 CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
46 # required rpm-build-macros
65 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
67 # use rpm 4.4.6+ digest format instead of comments if non-zero
70 # user agent when fetching files
71 USER_AGENT="PLD/Builder($VERSION)"
73 # It can be used i.e. in log file naming.
74 # See LOGFILE example.
75 DATE=`date +%Y-%m-%d_%H-%M-%S`
77 # target arch, can also be used for log file naming
78 TARGET=$(rpm -E %{_target})
80 # Note the *single* quotes, this allows using shell variables expanded at build time
81 # Example: LOGFILE='../log.$PACKAGE_NAME'
82 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
83 # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
84 # Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
85 # Example: LOGFILE='.log.$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.$TARGET.$DATE'
88 # use teeboth Perl wrapper
89 # temporary option to disable if broken
104 # create symlinks for tools in PACKAGE_DIR, see get_spec()
116 # use lftp by default when available
118 lftp --version > /dev/null 2>&1 && USE_LFTP=yes
119 PARALLEL_DOWNLOADS=10
121 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
126 GIT_SERVER="git://git.pld-linux.org"
127 GIT_PUSH="git@git.pld-linux.org"
128 PACKAGES_DIR="packages"
137 DISTFILES_SERVER="://distfiles.pld-linux.org"
138 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
143 FAIL_IF_NO_SOURCES="yes"
145 # let get_files skip over files which are present to get those damn files fetched
146 SKIP_EXISTING_FILES="no"
149 # should the specfile be restored if upgrade failed?
150 REVERT_BROKEN_UPGRADE="yes"
152 if rpm --specsrpm 2>/dev/null; then
153 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
154 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
156 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
157 if [ -x /usr/bin/rpm-getdeps ]; then
158 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
160 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
164 UPDATE_POLDEK_INDEXES_OPTS=""
166 # Here we load saved user environment used to
167 # predefine options set above, or passed to builder
169 # This one reads global system environment settings:
170 if [ -f ~/etc/builderrc ]; then
173 # And this one cascades settings using user personal
175 # Example of ~/.builderrc:
177 #UPDATE_POLDEK_INDEXES="yes"
178 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
179 #FETCH_BUILD_REQUIRES="yes"
180 #REMOVE_BUILD_REQUIRES="force"
182 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
186 if [ -n "$HOME_ETC" ]; then
187 USER_CFG="$HOME_ETC/.builderrc"
188 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
190 USER_CFG=~/.builderrc
191 BUILDER_MACROS=~/.builder-rpmmacros
194 [ -f "$USER_CFG" ] && . "$USER_CFG"
196 if [ "$SCHEDTOOL" = "auto" ]; then
197 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
198 SCHEDTOOL="schedtool -B -e"
204 if [ -n "$USE_PROZILLA" ]; then
205 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
208 elif [ -n "$USE_AXEL" ]; then
209 GETURI="axel -a $AXEL_OPTS"
212 elif [ -n "$USE_LFTP" ]; then
217 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
218 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
219 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
220 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
222 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
223 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
229 if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
240 if [ -d $HOME/rpm/SOURCES ]; then
241 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
242 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
246 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
247 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
252 if [ -n "$LOGFILE" ]; then
253 LOG=`eval echo $LOGFILE`
254 if [ -n "$LASTLOG_FILE" ]; then
255 echo "LASTLOG=$LOG" > $LASTLOG_FILE
257 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
258 # FIXME $exit_pldk undefined
261 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
262 return `cat ${RES_FILE}`
267 #---------------------------------------------
271 local outfile=$1 url=$2 retval tmpfile
275 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
276 set ssl:verify-certificate no;
277 set net:max-retries $WGET_RETRIES;
278 set http:user-agent \"$USER_AGENT\";
279 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
283 if [ $retval -eq 0 ]; then
284 mv -f "$tmpfile" "$outfile"
292 if [ -n "$DEBUG" ]; then set -xv; fi
294 # to make this output parseable by bash-completion _parse_help()
295 # if the line contains short and long option, it will take only the long option
296 # but if you want both being completed, put the short option to separate line
298 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
299 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
300 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
301 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
302 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
303 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
304 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
305 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
306 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
307 <package>[.spec][:tag]
309 -4 - force IPv4 when transferring files
310 -6 - force IPv6 when transferring files
312 --update-md5 - update md5 comments in spec, implies -nd -ncs
314 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
315 --all-branches - make shallow fetch of all branches; --depth required
316 -n5, --no-md5 - ignore md5 comments in spec
317 -D, --debug - enable builder script debugging mode,
318 -debug - produce rpm debug package (same as --opts -debug)
319 -V, --version - output builder version string
320 --short-version - output builder short version
321 -a - try add new package to PLD repo.
324 - get all files from PLD repo or HTTP/FTP and build package
326 -bb - get all files from PLD repo or HTTP/FTP and build binary
327 only package from <package>.spec,
328 -bp - execute the %prep phase of <package>.spec,
329 -bc - execute the %build phase of <package>.spec,
330 -bi - execute the %install phase of <package>.spec
331 -bl - execute the %files phase of <package>.spec
332 -bs - get all files from PLD repo or HTTP/FTP and only pack
334 --short-circuit - short-circuit build
335 -B, --branch - add branch
337 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
338 may be used with building process.
339 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
340 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
341 -cf, --cvs-force - use -f when tagging
342 --define '<macro> <value>'
343 - define a macro <macro> with value <value>,
344 --depth <number> - make shallow fetch
345 --alt_kernel <kernel>
346 - same as --define 'alt_kernel <kernel>'
347 --nodeps - rpm won't check any dependences
349 --get - get <package>.spec and all related files from PLD repo
350 -h, --help - this message,
351 -j N - set %_smp_mflags to propagate concurrent jobs
352 --ftp - use FTP protocol to access distfiles server
353 --http - use HTTP protocol to access distfiles server
354 -l <logfile>, --logtofile=<logfile>
357 - don't pull from PLD repo
358 -nd, --no-distfiles - don't download from distfiles
359 -nm, --no-mirrors - don't download from mirror, if source URL is given,
360 -nu, --no-urls - don't try to download from FTP/HTTP location,
361 -ns, --no-srcs - don't download Sources/Patches
362 -ns0, --no-source0 - don't download Source0
363 -nn, --no-net - don't download anything from the net
364 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
365 -pm, --prefer-mirrors
366 - prefer mirrors (if any) over distfiles for SOURCES
367 --no-init - don't initialize builder paths (SPECS and SOURCES)
369 --skip-existing-files
370 - skip existing files in get_files
371 --opts <rpm opts> - additional options for rpm
372 -q, --quiet - be quiet,
373 --date yyyy-mm-dd - build package using resources from specified date,
374 -r <tag>, --cvstag <ref>
375 - build package using resources from specified branch/tag,
376 -A - build package using master branch as any sticky tags/branch/date being reset.
377 -R, --fetch-build-requires
378 - fetch what is BuildRequired,
379 -RB, --remove-build-requires
380 - remove all you fetched with -R or --fetch-build-requires
381 remember, this option requires confirmation,
382 -FRB, --force-remove-build-requires
383 - remove all you fetched with -R or --fetch-build-requires
384 remember, this option works without confirmation,
385 -sd, --source-distfiles
386 - list sources available from distfiles (intended for offline
387 operations; does not work when Icon field is present
388 but icon file is absent),
389 -sc, --source-cvs - list sources available from PLD repo
390 -sdp, --source-distfiles-paths
391 - list sources available from distfiles -
392 paths relative to distfiles directory (intended for offline
393 operations; does not work when Icon field is present
394 but icon file is absent),
395 -sf, --source-files - list sources - bare filenames (intended for offline
396 operations; does not work when Icon field is present
397 but icon file is absent),
399 - list sources - filenames with full local paths (intended for
400 offline operations; does not work when Icon field is present
401 but icon file is absent),
402 -su, --source-urls - list urls - urls to sources and patches
403 intended for copying urls with spec with lots of macros in urls
404 -T <tag> , --tag <tag>
405 - add git tag <tag> for files,
406 -Tvs, --tag-version-stable
407 - add git tags STABLE and NAME-VERSION-RELEASE for files,
409 - add git tag STABLE for files,
411 --tag-version - add git tag NAME-VERSION-RELEASE for files,
412 -Tp, --tag-prefix <prefix>
413 - add <prefix> to NAME-VERSION-RELEASE tags,
414 -tt, --test-tag <prefix>
415 - fail if tag is already present,
416 -ir, --integer-release-only
417 - allow only integer and snapshot releases
418 -v, --verbose - be verbose,
419 -u, --try-upgrade - check version, and try to upgrade package
420 -un, --try-upgrade-with-float-version
421 - as above, but allow float version
422 php-pear-Services_Digg/
423 --upgrade-version - upgrade to specified version in try-upgrade
424 -U, --update - refetch sources, don't use distfiles, and update md5 comments
425 -Upi, --update-poldek-indexes
426 - refresh or make poldek package index files.
428 --skip-patch <patchnumber>
429 - don't apply <patchnumber>. may be repeated.
431 --nopatch <patchnumber>
432 - abort instead of applying patch <patchnumber>
434 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
435 --show-bconds - show available conditional builds, which can be used
436 - with --with and/or --without switches.
437 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
438 In other words, the output is parseable by scripts.
439 --show-avail-bconds - show available bconds
442 - conditional build package depending on %_with_<feature>/
443 %_without_<feature> macro switch. You may now use
444 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
445 constructions. Set GROUP_BCONDS to yes to make use of it.
446 --target <platform>, --target=<platform>
447 - build for platform <platform>.
448 --init-rpm-dir - initialize ~/rpm directory structure
452 # create tempfile. as secure as possible
454 mktemp --tmpdir -t builder.$PACKAGE_NAME.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
458 mktemp --tmpdir -d builder.$PACKAGE_NAME.XXXXXX
461 # inserts git log instead of %changelog
462 # outputs name of modified file created by tempfile
464 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
466 # allow this being customized
467 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
469 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
470 # otherwise i'd use --date=iso here
471 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
472 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
473 # NOTE: changelog date is always in UTC for rpmbuild
474 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
475 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
477 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
478 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
481 # add link to full git logs
482 local giturl="http://git.pld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
483 if [ -n "$CVSTAG" ]; then
484 giturl="$giturl;h=$CVSTAG"
486 local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
487 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
488 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
493 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
494 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
498 " > $specdir/$SPECFILE
499 rm -f $gitlog $speclog
503 # @param string logfile
504 # @param varargs... commands to execute
507 # use teeboth from toys/cleanbuild, if available and enabled
508 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
512 local efile rc logfile=$1; shift
513 if [ "$logfile" ]; then
515 { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile
526 # change dependency to specname
528 # - perl(Package::Name) -> perl-Package-Name
532 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
536 update_shell_title() {
538 local len=${COLUMNS:-80}
539 local msg="$(echo "$*" | cut -c-$len)"
541 if [ -n "$BE_VERBOSE" ]; then
542 echo >&2 "$(date +%s.%N) $*"
545 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
547 if [ -n "$PACKAGE_NAME" ]; then
548 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
553 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
554 msg=$(echo $msg | tr -d '\n\r')
557 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
560 echo >&2 -ne "\033]0;$msg\007"
566 # set TARGET from BuildArch: from SPECFILE
568 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
569 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
571 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
575 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
577 TARGET_SWITCH="--target=$TARGET" ;;
583 # runs rpm with minimal macroset
585 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
587 # TODO: move these to /usr/lib/rpm/macros
588 cat > $BUILDER_MACROS <<'EOF'
589 %x8664 x86_64 amd64 ia32e
592 %bootstrap_release() %{1}
593 %requires_releq_kernel_up(s:n:) %{nil}
594 %requires_releq_kernel_smp(s:n:) %{nil}
595 %requires_releq_kernel(s:n:) %{nil}
596 %requires_releq() %{nil}
597 %pyrequires_eq() %{nil}
598 %requires_eq() %{nil}
599 %requires_eq_to() %{nil}
600 %requires_ge() %{nil}
601 %requires_ge_to() %{nil}
602 %requires_ge() %{nil}
603 %releq_kernel_up(n:) ERROR
604 %releq_kernel_smp(n:) ERROR
605 %releq_kernel(n:) ERROR
606 %py_postclean(x:) ERROR
610 %ruby_ver_requires_eq() %{nil}
611 %ruby_mod_ver_requires_eq() %{nil}
612 %__php_api_requires() %{nil}
613 %php_major_version ERROR
614 %php_api_version ERROR
615 %requires_xorg_xserver_extension %{nil}
616 %requires_xorg_xserver_xinput %{nil}
617 %requires_xorg_xserver_font %{nil}
618 %requires_xorg_xserver_videodrv %{nil}
620 %perl_vendorarch ERROR
621 %perl_vendorlib ERROR
622 # damn. need it here! - copied from /usr/lib/rpm/macros.build
623 %tmpdir %(echo "${TMPDIR:-/tmp}")
624 %patchset_source(f:b:) %(
625 base=%{-b*}%{!-b*:10000};
626 start=$(expr $base + %1);
627 end=$(expr $base + %{?2}%{!?2:%{1}});
628 # we need to call seq twice as it doesn't allow two formats
629 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
630 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
631 paste %{tmpdir}/__ps{1,2};
632 rm -f %{tmpdir}/__ps{1,2};
635 %add_etc_shells(p) %{p:<lua>}
636 %remove_etc_shells(p) %{p:<lua>}
637 %lua_add_etc_shells() %{nil}
638 %lua_remove_etc_shells() %{nil}
640 %buildrequires_jdk %{nil}
641 %pear_package_print_optionalpackages %{nil}
643 if [ "$NOINIT" = "yes" ] ; then
644 cat >> $BUILDER_MACROS <<'EOF'
649 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
653 if [ -n "$DEBUG" ]; then
658 if [ -x /usr/bin/rpm-specdump ]; then
659 update_shell_title "cache_rpm_dump using rpm-specdump command"
660 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
662 update_shell_title "cache_rpm_dump using rpmbuild command"
665 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
666 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
672 ARGS='--nodigest --nosignature --nobuild'
675 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
677 if [ $? -gt 0 ]; then
678 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
680 Exit_error err_build_fail
683 # make small dump cache
684 rpm_dump_cache=`echo "$rpm_dump" | awk '
685 $2 ~ /^SOURCEURL/ {print}
686 $2 ~ /^PATCHURL/ {print}
687 $2 ~ /^nosource/ {print}
688 $2 ~ /^PACKAGE_/ {print}
692 update_shell_title "cache_rpm_dump: OK!"
696 if [ -z "$rpm_dump_cache" ] ; then
697 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
699 echo "$rpm_dump_cache"
703 update_shell_title "get icons"
704 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
705 if [ -z "$ICONS" ]; then
709 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
713 update_shell_title "parsing specfile"
714 if [ -n "$DEBUG" ]; then
719 # icons are needed for successful spec parse
725 if rpm_dump | grep -qEi ":.*nosource.*1"; then
726 FAIL_IF_NO_SOURCES="no"
729 if [ "$NOSRCS" != "yes" ]; then
730 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
731 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
732 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
735 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
736 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
737 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
739 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
740 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
743 if [ -n "$BE_VERBOSE" ]; then
744 echo "- Sources : `nourl $SOURCES`"
745 if [ -n "$PATCHES" ]; then
746 echo "- Patches : `nourl $PATCHES`"
748 echo "- Patches : *no patches needed*"
750 if [ -n "$ICONS" ]; then
751 echo "- Icon : `nourl $ICONS`"
753 echo "- Icon : *no package icon*"
755 echo "- Name : $PACKAGE_NAME"
756 echo "- Version : $PACKAGE_VERSION"
757 echo "- Release : $PACKAGE_RELEASE"
760 update_shell_title "parse_spec: OK!"
764 if [ -n "$DEBUG" ]; then
772 "err_no_spec_in_cmdl" )
773 remove_build_requires
774 echo >&2 "ERROR: spec file name not specified."
776 "err_invalid_cmdline" )
777 echo >&2 "ERROR: invalid command line arg ($2)."
779 "err_no_spec_in_repo" )
780 remove_build_requires
781 echo >&2 "Error: spec file not stored in PLD repo."
783 "err_no_source_in_repo" )
784 remove_build_requires
785 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
787 "err_cvs_add_failed" )
788 echo >&2 "Error: failed to add package to PLD repo."
791 remove_build_requires
792 echo >&2 "Error: package build failed. (${2:-no more info})"
794 "err_no_package_data" )
795 remove_build_requires
796 echo >&2 "Error: couldn't get out package name/version/release from spec file."
799 remove_build_requires
800 echo >&2 "Tag ${2} already exists"
803 remove_build_requires
804 echo >&2 "Release ${2} not integer and not a snapshot."
806 "err_branch_exists" )
807 remove_build_requires
808 echo >&2 "Tree branch already exists (${2})."
811 remove_build_requires
812 echo >&2 "Error: conditions reject building this spec (${2})."
814 "err_remote_problem" )
815 remove_build_requires
816 echo >&2 "Error: problem with remote (${2})"
819 echo >&2 "Error: cannot checkout $2"
821 "err_not_implemented" )
822 remove_build_requires
823 echo >&2 "Error: functionality not yet imlemented"
826 echo >&2 "Unknown error."
831 if [ -n "$DEBUG" ]; then
836 if [ "$NOINIT" != "yes" ] ; then
837 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
839 local macros_ver=$(rpm -E %?rpm_build_macros)
840 if [ -z "$macros_ver" ]; then
841 REPO_DIR=$TOP_DIR/packages
842 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
844 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
845 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
849 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
854 REPO_DIR=$PACKAGE_DIR
855 RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
857 export GIT_WORK_TREE=$PACKAGE_DIR
858 export GIT_DIR=$PACKAGE_DIR/.git
860 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
861 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
862 CVSTAG=${CVSTAG#refs/heads/}
863 if [ "$CVSTAG" != "master" ]; then
864 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
867 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
870 elif [ "$CVSTAG" = "HEAD" ]; then
871 # assume -r HEAD is same as -A
879 update_shell_title "add_package"
881 if [ -n "$DEBUG" ]; then
887 SPECFILE=$(basename $SPECFILE)
888 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
889 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
892 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
893 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
895 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git && \
896 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} \
897 || Exit_error err_remote_problem $REMOTE_PLD
902 update_shell_title "get_spec"
904 if [ -n "$DEBUG" ]; then
910 SPECFILE=$(basename $SPECFILE)
911 if [ "$NOCVSSPEC" != "yes" ]; then
912 if [ -z "$DEPTH" ]; then
913 if [ -d "$PACKAGE_DIR/.git" ]; then
914 git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
915 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
916 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
917 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
920 Exit_error err_not_implemented
924 git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
925 # softfail if new package, i.e not yet added to PLD rep
926 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
927 echo "Warning: package not in CVS - assuming new package"
930 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
931 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
935 if [ ! -d "$PACKAGE_DIR/.git" ]; then
936 if [ ! -d "$PACKAGE_DIR" ]; then
937 install -d $PACKAGE_DIR
940 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
941 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
942 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
943 CVSTAG=${CVSTAG:-"master"}
946 if [ -z "$ALL_BRANCHES" ]; then
947 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
949 git fetch $DEPTH $REMOTE_PLD $refs || {
950 echo >&2 "Error: branch $CVSTAG does not exist"
954 git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*'
956 cvsignore_df .gitignore
958 # add default log format to .gitignore if it is relative to package dir
959 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
960 # substitute known "macros" to glob
961 local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g')
962 if [ "$logfile" ]; then
963 cvsignore_df "$logfile"
967 # create symlinks for tools
968 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
969 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
970 # skip tools that don't exist in top dir
971 [ -f $a ] || continue
972 # skip tools that already exist
973 [ -f $PACKAGE_DIR/$a ] && continue
974 ln -s ../$a $PACKAGE_DIR
980 if [ -n "$CVSTAG" ]; then
981 if git rev-parse --verify -q "$CVSTAG"; then
982 git checkout "$CVSTAG" --
983 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
984 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
986 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
987 Exit_error "err_no_checkut" "$CVSTAG"
989 git merge --ff-only '@{u}'
990 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
991 if [ -n "$CVSDATE" ]; then
992 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
996 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
997 Exit_error err_no_spec_in_repo
1000 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1001 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1004 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1012 if [ ! -f "mirrors" ] ; then
1013 ln -s ../rpm-build-tools/mirrors .
1017 local origin mirror name rest ol prefix
1018 while read origin mirror name rest; do
1019 # skip comments and empty lines
1020 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1023 ol=$(echo -n "$origin" | wc -c)
1024 prefix=$(echo -n "$url" | head -c $ol)
1025 if [ "$prefix" = "$origin" ] ; then
1026 suffix=$(echo "$url" | cut -b $((ol+1))-)
1027 echo -n "$mirror$suffix"
1034 # Warning: unpredictable results if same URL used twice
1037 # escape some regexp characters if part of file name
1038 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1041 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1042 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1043 head -n 1 | tr OURCEATH ourceath | xargs
1047 [ "$NO5" = "yes" ] && return
1049 [ -z "$no" ] && return
1053 # use "sources" file from package dir, like vim
1054 if [ -f sources ]; then
1055 md5=$(grep -s -v '^#' sources | \
1056 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1057 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1058 grep -E '^[0-9a-f]{32}$')
1061 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1062 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1064 echo "$md5" | tail -n 1
1069 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1070 if [ -n "$source_md5" ]; then
1073 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1074 if [ -n "$source_md5" ]; then
1077 # we have empty SourceX-md5, but it is still possible
1078 # that we have NoSourceX-md5 AND NoSource: X
1079 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1080 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1088 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1092 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1095 distfiles_attic_url() {
1096 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
1101 [ "$md5" = "" ] || \
1102 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1106 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1107 [ -n "$size" -a "$size" -gt 0 ]
1111 if [ "$CVSIGNORE_DF" != "yes" ]; then
1114 cvsignore=${PACKAGE_DIR}/.gitignore
1116 # add only if not yet there
1117 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1118 echo "$1" >> $cvsignore
1122 # returns true if "$1" is ftp, http or https protocol url
1125 ftp://*|http://*|https://*)
1133 if [ $# -eq 0 ]; then
1137 update_shell_title "update md5"
1138 if [ -n "$DEBUG" ]; then
1145 # pass 1: check files to be fetched
1149 local fp=$(nourl "$i")
1150 local srcno=$(src_no "$i")
1151 if [ -n "$ADD5" ]; then
1152 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1153 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1154 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1156 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1158 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1159 need_files="$need_files $i"
1163 # pass 1a: get needed files
1164 if [ "$need_files" ]; then
1165 get_files $need_files
1168 # pass 2: proceed with md5 adding or updating
1170 local fp=$(nourl "$i")
1171 local srcno=$(src_no "$i")
1172 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1173 if [ -z "$md5" ]; then
1174 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1176 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1177 local tag="# $srcno-md5:\t"
1178 if [[ "$md5" == *NoSource* ]]; then
1179 tag="# No$srcno-md5:\t"
1180 elif [ -n "$USEDIGEST" ]; then
1181 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1183 md5=$(md5sum "$fp" | cut -f1 -d' ')
1184 echo "Updating $srcno ($md5: $fp)."
1186 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1187 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1189 $PACKAGE_DIR/$SPECFILE
1196 [ "$NO5" = "yes" ] && return
1198 update_shell_title "check md5"
1202 if ! good_md5 "$i"; then
1203 echo -n "MD5 sum mismatch."
1206 if ! good_size "$i"; then
1207 echo -n "0 sized file."
1211 if [ $bad -eq 1 ]; then
1212 echo " Use -U to refetch sources,"
1213 echo "or -5 to update md5 sums, if you're sure files are correct."
1214 Exit_error err_no_source_in_repo $i
1220 update_shell_title "get_files"
1222 if [ -n "$DEBUG" ]; then
1227 if [ $# -gt 0 ]; then
1231 local get_files_cvs=""
1235 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1236 update_shell_title "$i"
1237 local fp=`nourl "$i"`
1238 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1243 local srcmd5=$(src_md5 "$i")
1245 # we know if source/patch is present in cvs/distfiles
1246 # - has md5 (in distfiles)
1247 # - in cvs... ideas?
1249 # CHECK: local file didn't exist or always cvs up (first) requested.
1250 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1251 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1252 echo "Warning: no URL given for $i"
1256 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1257 if good_md5 "$i" && good_size "$i"; then
1258 echo "$fp having proper md5sum already exists"
1262 # optionally prefer mirror over distfiles if there's mirror
1263 # TODO: build url list and then try each url from the list
1264 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1267 url=$(distfiles_url "$i")
1270 url_attic=$(distfiles_attic_url "$i")
1272 # is $url local file?
1273 if [[ "$url" = [./]* ]]; then
1274 update_shell_title "${GETLOCAL%% *}: $url"
1275 ${GETLOCAL} $url $target
1278 # make shorter message for distfiles urls
1279 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1280 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1281 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1284 update_shell_title "${GETURI%% *}: $uri"
1285 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1286 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1287 update_shell_title "${GETURI2%% *}: $url"
1288 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1293 if [ ! -s "$target" ]; then
1295 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1296 update_shell_title "${GETLOCAL%% *}: $url_attic"
1297 ${GETLOCAL} $url_attic $target
1299 update_shell_title "${GETURI%% *}: $url_attic"
1300 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1301 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1302 update_shell_title "${GETURI2%% *}: $url_attic"
1303 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1305 test -s "$target" || rm -f "$target"
1309 if [ -s "$target" ]; then
1310 cvsignore_df $target
1317 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1318 if [ -z "$NOMIRRORS" ]; then
1319 im=$(find_mirror "$i")
1323 update_shell_title "${GETURI%% *}: $im"
1324 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1325 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1326 update_shell_title "${GETURI2%% *}: $im"
1327 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1329 test -s "$target" || rm -f "$target"
1332 if [ "$cvsup" = 1 ]; then
1338 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1339 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1340 Exit_error err_no_source_in_repo $i
1343 # we check md5 here just only to refetch immediately
1344 if good_md5 "$i" && good_size "$i"; then
1346 elif [ "$FROM_DISTFILES" = 1 ]; then
1347 # wrong md5 from distfiles: remove the file and try again
1349 echo "MD5 sum mismatch. Trying full fetch."
1352 update_shell_title "${GETURI%% *}: $url"
1353 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1354 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1355 update_shell_title "${GETURI2%% *}: $url"
1356 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1358 if [ ! -s "$target" ]; then
1360 update_shell_title "${GETURI%% *}: $url_attic"
1361 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1362 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1363 update_shell_title "${GETURI2%% *}: $url_attic"
1364 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1367 test -s "$target" || rm -f "$target"
1370 SHELL_TITLE_PREFIX=""
1373 if [ "$CHMOD" = "yes" ]; then
1374 CHMOD_FILES=$(nourl "$@")
1375 if [ -n "$CHMOD_FILES" ]; then
1376 chmod $CHMOD_MODE $CHMOD_FILES
1383 # If tag exists and points to other commit exit with error
1384 # If it existsts and points to HEAD return 1
1385 # If it doesn't exist return 0
1387 local sha1=$(git rev-parse HEAD)
1388 echo "Searching for tag $_tag..."
1389 if [ -n "$DEPTH" ]; then
1390 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1392 local ref=$(git show-ref -s "refs/tags/$_tag")
1394 [ -z "$ref" ] && return 0
1395 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1400 if [ -n "$DEBUG" ]; then
1405 # Check whether first character of PACKAGE_NAME is legal for tag name
1406 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1410 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1411 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1413 # Remove @kernel.version_release from TAGVER because tagging sources
1414 # could occur with different kernel-headers than kernel-headers used at build time.
1415 # besides, %{_kernel_ver_str} is not expanded.
1417 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1418 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1425 if [ -n "$DEBUG" ]; then
1430 echo "Version: $PACKAGE_VERSION"
1431 echo "Release: $PACKAGE_RELEASE"
1434 if [ "$TAG_VERSION" = "yes" ]; then
1437 if [ -n "$TAG" ]; then
1442 local OPTIONS="tag $CVS_FORCE"
1446 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1447 update_shell_title "tag sources: $_tag"
1448 git $OPTIONS $_tag || exit
1449 git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1451 echo "Tag $_tag already exists and points to the same commit"
1457 echo "Git branch: $TAG"
1460 if [ -n "$DEBUG" ]; then
1465 local OPTIONS="branch $CVS_FORCE"
1468 git $OPTIONS $TAG || exit
1472 # this function should exit early if package can't be built for this arch
1473 # this avoids unneccessary BR filling.
1476 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1478 if [ $ret -ne 0 ]; then
1490 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1491 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1497 local ver="$2" subver=$ver
1498 local newver="$3" newsubver=$newver
1500 # try handling subver, everything that's not numeric-dotted in version
1501 if grep -Eq '%define\s+subver' $specfile; then
1502 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1504 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1505 newver=${newver%$newsubver}
1508 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1509 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1510 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1514 # try to upgrade .spec to new version
1515 # if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1517 # return 1: if .spec was updated
1518 # return 0: no changes to .spec
1519 # exit 1 in case of error
1521 if [ -z "$TRY_UPGRADE" ]; then
1525 local TNOTIFY TNEWVER TOLDVER
1526 update_shell_title "build_package: try_upgrade"
1530 if [ "$UPGRADE_VERSION" ]; then
1531 TNEWVER=$UPGRADE_VERSION
1532 echo "Updating spec file to version $TNEWVER"
1534 if [ -n "$FLOAT_VERSION" ]; then
1535 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1537 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1540 # pldnotify.awk does not set exit codes, but it has match for ERROR
1541 # in output which means so.
1542 if [[ "$TNOTIFY" = *ERROR* ]]; then
1547 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1548 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1550 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1553 if [ -z "$TNEWVER" ]; then
1557 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1558 cp -f $SPECFILE $SPECFILE.bak
1561 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1562 set_release $SPECFILE $PACKAGE_RELEASE 1
1564 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1565 echo >&2 "Upgrading version failed, you need to update spec yourself"
1572 update_shell_title "build_package"
1573 if [ -n "$DEBUG" ]; then
1582 BUILD_SWITCH="-ba" ;;
1584 BUILD_SWITCH="-bb" ;;
1586 BUILD_SWITCH="-bs --nodeps" ;;
1588 BUILD_SWITCH="-bp --nodeps" ;;
1590 BUILD_SWITCH="-bc" ;;
1592 BUILD_SWITCH="-bi" ;;
1594 BUILD_SWITCH="-bl" ;;
1598 update_shell_title "build_package: $COMMAND"
1599 local logfile retval
1600 if [ -n "$LOGFILE" ]; then
1601 logfile=`eval echo $LOGFILE`
1602 if [ -d "$logfile" ]; then
1603 echo "Log file $logfile is a directory."
1604 echo "Parse error in the spec?"
1605 Exit_error err_build_fail
1607 if [ -n "$LASTLOG_FILE" ]; then
1608 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1612 local specdir=$(insert_gitlog $SPECFILE)
1613 # FIXME: eval here is exactly why?
1614 PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${TIME_COMMAND} ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE
1618 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1619 if [ "$retval" -eq "0" ]; then
1620 mv $logfile $LOGDIROK
1622 mv $logfile $LOGDIRFAIL
1626 if [ "$retval" -ne "0" ]; then
1627 if [ -n "$TRY_UPGRADE" ]; then
1628 echo "\nUpgrade package to new version failed."
1629 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1630 echo "Restoring old spec file."
1631 mv -f $SPECFILE.bak $SPECFILE
1635 Exit_error err_build_fail
1641 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1644 install_required_packages() {
1649 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1652 /^%changelog/ { exit }
1654 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1655 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1656 gsub(/[ \t]+/, "_", bcond);
1658 }' $SPEC | LC_ALL=C sort -u
1662 # expand bconds from ~/.bcondrc
1663 # The file structure is like gentoo's package.use:
1666 # samba -mysql -pgsql
1667 # w32codec-installer license_agreement
1670 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1676 SN=${SPECFILE%%\.spec}
1678 local bcondrc=$HOME/.bcondrc
1679 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1681 local bcond_avail=$(find_spec_bcond $SPECFILE)
1683 while read pkg flags; do
1685 [[ "$pkg" == \#* ]] && continue
1687 # any package or current package?
1688 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1689 for flag in $flags; do
1690 local opt=${flag#[+-]}
1692 # use only flags which are in this package.
1693 if [[ $bcond_avail = *${opt}* ]]; then
1694 if [[ $flag = -* ]]; then
1695 if [[ $BCOND != *--with?${opt}* ]]; then
1696 BCOND="$BCOND --without $opt"
1699 if [[ $BCOND != *--without?${opt}* ]]; then
1700 BCOND="$BCOND --with $opt"
1707 update_shell_title "parse ~/.bcondrc: DONE!"
1710 set_bconds_values() {
1711 update_shell_title "set bcond values"
1713 AVAIL_BCONDS_WITHOUT=""
1714 AVAIL_BCONDS_WITH=""
1716 if grep -Eq '^# *_with' ${SPECFILE}; then
1717 echo >&2 "ERROR: This spec has old style bconds."
1721 if ! grep -q '^%bcond' ${SPECFILE}; then
1725 local bcond_avail=$(find_spec_bcond $SPECFILE)
1726 process_bcondrc "$SPECFILE"
1728 update_shell_title "parse bconds"
1731 for opt in $bcond_avail; do
1734 bcond=${opt#without_}
1736 *--without?${bcond}*)
1737 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1740 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1748 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1751 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1756 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1765 update_shell_title "run_sub_builder $package_name"
1767 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1768 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
1769 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1770 # jakby nie bylo tego kawalka kodu.
1772 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1773 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
1777 # kurwa. translate that ^^^^
1781 # Istnieje taki spec? ${package}.spec
1782 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1783 parent_spec_name=${package}.spec
1784 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1785 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1787 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1792 if [ "${parent_spec_name}" != "" ]; then
1793 spawn_sub_builder $parent_spec_name
1795 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1798 spawn_sub_builder() {
1800 update_shell_title "spawn_sub_builder $package_name"
1803 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1804 sub_builder_opts="${sub_builder_opts} -R"
1806 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1807 sub_builder_opts="${sub_builder_opts} -RB"
1808 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1809 sub_builder_opts="${sub_builder_opts} -FRB"
1811 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1812 sub_builder_opts="${sub_builder_opts} -Upi"
1816 ./builder ${sub_builder_opts} "$@"
1819 remove_build_requires() {
1820 if [ "$INSTALLED_PACKAGES" != "" ]; then
1821 case "$REMOVE_BUILD_REQUIRES" in
1823 run_poldek --noask -ve $INSTALLED_PACKAGES
1826 run_poldek --ask -ve $INSTALLED_PACKAGES
1829 echo You may want to manually remove following BuildRequires fetched:
1830 echo $INSTALLED_PACKAGES
1831 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1838 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1839 if [ "$BCOND" ]; then
1841 echo "Building $SPECFILE with the following conditional flags:"
1845 echo "No conditional flags passed"
1848 echo "from available:"
1849 echo "--with :\t$AVAIL_BCONDS_WITH"
1850 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1855 display_branches() {
1856 echo -n "Available branches: "
1857 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1860 # checks a given list of packages/files/provides agains current rpmdb.
1861 # outputs all dependencies which current rpmdb doesn't satisfy.
1862 # input can be either STDIN or parameters
1866 if [ $# -gt 0 ]; then
1872 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1875 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1877 # other deps (files)
1878 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1881 # checks if given package/files/provides exists in rpmdb.
1882 # input can be either stdin or parameters
1883 # returns packages which are present in the rpmdb
1887 if [ $# -gt 0 ]; then
1893 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1896 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1897 install_build_requires_rpmdeps() {
1898 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1899 # TODO: Conflicts list doesn't check versions
1900 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1901 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1903 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1904 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1905 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1908 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1909 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1910 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1911 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1913 if [ -n "$CNFL" ]; then
1914 update_shell_title "uninstall conflicting packages: $CNFL"
1915 echo "Trying to uninstall conflicting packages ($CNFL):"
1916 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1919 while [ "$DEPS" ]; do
1920 update_shell_title "install deps: $DEPS"
1921 echo "Trying to install dependencies ($DEPS):"
1922 local log=.${SPECFILE}_poldek.log
1923 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1924 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1927 if [ -n "$failed" ]; then
1928 for package in $failed; do
1929 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1938 fetch_build_requires()
1940 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1944 update_shell_title "fetch build requires"
1945 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1946 install_build_requires_rpmdeps
1950 # XXX is this ugliest code written in human history still needed?
1951 echo "All packages installed by fetch_build_requires() are written to:"
1952 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1954 echo "If anything fails, you may get rid of them by executing:"
1955 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
1957 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1958 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)
1960 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)
1962 package=$(basename "$package_item"|sed -e "s/}$//g")
1963 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
1966 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1967 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1968 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
1973 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1976 if `echo $COND_TST|grep -q 'without_'`; then
1977 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1978 if `echo $COND_TST|grep -q !`; then
1983 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1984 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1985 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1991 elif `echo $COND_TST|grep -q 'with_'`; then
1992 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1993 if `echo $COND_TST|grep -q !`; then
1998 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1999 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
2000 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
2006 RESULT="${COND_STATE}-${COND_ARGV}"
2008 "with-wout" | "wout-with" )
2011 "wout-wout" | "with-with" )
2015 echo "Action '$RESULT' was not defined for package '$package_item'"
2021 if [ "$GO" = "yes" ]; then
2022 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
2023 echo "Testing if $package has subrequirements..."
2024 run_poldek -t -i $package --dumpn=".$package-req.txt"
2025 if [ -f ".$package-req.txt" ]; then
2026 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2028 if [ "$package_name" = "$package" ]; then
2029 echo "Installing BuildRequired package:\t$package_name"
2030 update_shell_title "Installing BuildRequired package: ${package_name}"
2031 install_required_packages $package
2033 echo "Installing (sub)Required package:\t$package_name"
2034 update_shell_title "Installing (sub)Required package: ${package_name}"
2035 install_required_packages $package_name
2039 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2040 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2043 echo "Attempting to run spawn sub - builder..."
2044 echo "Package installation failed:\t$package_name"
2045 run_sub_builder $package_name
2046 if [ $? -eq 0 ]; then
2047 install_required_packages $package_name
2050 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2051 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2054 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2061 rm -f ".$package-req.txt"
2063 echo "Attempting to run spawn sub - builder..."
2064 echo "Package installation failed:\t$package"
2065 run_sub_builder $package
2066 if [ $? -eq 0 ]; then
2067 install_required_packages $package
2070 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2071 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2074 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2080 echo "Package $package is already installed. BuildRequirement satisfied."
2084 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2085 echo >&2 "Unable to install following packages and their dependencies:"
2086 for pkg in "$NOT_INSTALLED_PACKAGES"
2090 remove_build_requires
2099 if [ ! -e $localrepo ]; then
2100 git clone -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
2101 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2106 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2107 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2108 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2109 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2110 local TEMPLATES=template-specs
2113 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2114 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2117 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2118 init_repository projects/$TEMPLATES ../$TEMPLATES
2119 for a in adapter builder fetchsrc_request compile repackage; do
2120 ln -sf ../rpm-build-tools/${a}.sh $a
2123 ln -sf ../rpm-build-tools/${a} $a
2125 ln -sf ../rpm-build-tools/mirrors mirrors
2132 DONT_PRINT_REVISION="yes"
2134 # remove spec and sources
2135 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
2136 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2137 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2140 #---------------------------------------------
2148 while [ $# -gt 0 ]; do
2151 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2152 # unfortunately $GETURI is already formed
2157 COMMAND="update_md5"
2162 COMMAND="update_md5"
2171 DEBUG="yes"; shift ;;
2173 COMMAND="version"; shift ;;
2175 COMMAND="short-version"; shift ;;
2182 -b | -ba | --build )
2183 COMMAND="build"; shift ;;
2184 -bb | --build-binary )
2185 COMMAND="build-binary"; shift ;;
2187 COMMAND="build-build"; shift ;;
2189 COMMAND="build-install"; shift ;;
2191 COMMAND="build-list"; shift ;;
2192 -bp | --build-prep )
2193 COMMAND="build-prep"; shift ;;
2194 -bs | --build-source )
2195 COMMAND="build-source"; shift ;;
2197 COMMAND="branch"; shift; TAG="${1}"; shift;;
2199 CLEAN="--clean"; shift ;;
2201 CVS_FORCE="-f"; shift;;
2207 COMMAND="get"; shift ;;
2209 COMMAND="usage"; shift ;;
2211 PROTOCOL="ftp"; shift ;;
2213 PROTOCOL="http"; shift ;;
2215 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2219 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2223 PARALLEL_DOWNLOADS=$2
2227 PARALLEL_DOWNLOADS=${1#-p}
2231 shift; LOGFILE="${1}"; shift ;;
2233 shift; DEF_NICE_LEVEL=${1}; shift ;;
2234 -ske | --skip-existing-files)
2235 SKIP_EXISTING_FILES="yes"; shift ;;
2237 COMMAND="mr-proper"; shift ;;
2238 -ncs | --no-cvs-specs )
2239 NOCVSSPEC="yes"; shift ;;
2240 -nd | --no-distfiles )
2241 NODIST="yes"; shift ;;
2242 -nm | --no-mirrors )
2243 NOMIRRORS="yes"; shift ;;
2245 NOURLS="yes"; shift ;;
2247 NOSRCS="yes"; shift ;;
2248 -ns0 | --no-source0 )
2249 NOSOURCE0="yes"; shift ;;
2258 -pm | --prefer-mirrors )
2261 --noinit | --no-init )
2265 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2267 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2268 --skip-patch | -sp )
2269 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2271 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2274 --with | --without )
2275 case $GROUP_BCONDS in
2279 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2280 while ! `echo ${1}|grep -qE '(^-|spec)'`
2282 BCOND="$BCOND $COND $1"
2286 if [[ "$2" = *,* ]]; then
2287 for a in $(echo "$2" | tr , ' '); do
2288 BCOND="$BCOND $1 $a"
2291 BCOND="$BCOND $1 $2"
2297 shift; TARGET="${1}"; shift ;;
2299 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2301 QUIET="--quiet"; shift ;;
2303 CVSDATE="${2}"; shift 2
2304 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2314 -R | --fetch-build-requires)
2315 FETCH_BUILD_REQUIRES="yes"
2316 NOT_INSTALLED_PACKAGES=
2318 -RB | --remove-build-requires)
2319 REMOVE_BUILD_REQUIRES="nice"
2321 -FRB | --force-remove-build-requires)
2322 REMOVE_BUILD_REQUIRES="force"
2325 COMMAND="list-sources-cvs"
2327 -sd | --source-distfiles)
2328 COMMAND="list-sources-distfiles"
2330 -sdp | --source-distfiles-paths)
2331 COMMAND="list-sources-distfiles-paths"
2333 -sf | --source-files)
2334 COMMAND="list-sources-files"
2336 -lsp | --source-paths)
2337 COMMAND="list-sources-local-paths"
2339 -su | --source-urls)
2340 COMMAND="list-sources-urls"
2342 -Tvs | --tag-version-stable )
2347 -Ts | --tag-stable )
2352 -Tv | --tag-version )
2357 -Tp | --tag-prefix )
2369 -ir | --integer-release-only )
2370 INTEGER_RELEASE="yes"
2373 COMMAND="update_md5"
2378 -Upi | --update-poldek-indexes )
2379 UPDATE_POLDEK_INDEXES="yes"
2382 COMMAND="init_rpm_dir"
2384 -u | --try-upgrade )
2385 TRY_UPGRADE="1"; shift ;;
2387 shift; UPGRADE_VERSION="$1"; shift;;
2388 -un | --try-upgrade-with-float-version )
2389 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2391 BE_VERBOSE="1"; shift ;;
2396 if echo "${MACRO}" | grep -q '\W'; then
2397 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2401 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2406 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2410 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2413 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2414 COMMAND="show_bconds"
2418 COMMAND="show_bcond_args"
2421 --show-avail-bconds)
2422 COMMAND="show_avail_bconds"
2427 RPMOPTS="${RPMOPTS} --nodeps"
2430 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2433 Exit_error err_invalid_cmdline "$1"
2436 SPECFILE=${1%/}; shift
2437 # check if specname was passed as specname:cvstag
2438 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2439 CVSTAG="${SPECFILE##*:}"
2440 SPECFILE="${SPECFILE%%:*}"
2442 # always have SPECFILE ending with .spec extension
2443 SPECFILE=${SPECFILE%%.spec}.spec
2444 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2448 if [ "$CVSTAG" ]; then
2449 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2450 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2453 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2454 echo >&2 "--all branches requires --depth <number>"
2455 Exit_error err_invalid_cmdline
2458 if [ -n "$DEBUG" ]; then
2463 if [ -n "$TARGET" ]; then
2466 TARGET_SWITCH="--target $TARGET" ;;
2468 TARGET_SWITCH="--target=$TARGET" ;;
2472 if [ "$SCHEDTOOL" != "no" ]; then
2473 NICE_COMMAND="$SCHEDTOOL"
2475 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2478 # see time(1) for output format that could be used
2479 TIME_COMMAND="time -p"
2481 update_shell_title "$COMMAND"
2485 if [ -z "$SPECFILE" ]; then
2486 Exit_error err_no_spec_in_cmdl
2488 get_spec > /dev/null
2495 if [ -z "$SPECFILE" ]; then
2496 Exit_error err_no_spec_in_cmdl
2498 get_spec > /dev/null
2503 "show_avail_bconds")
2505 if [ -z "$SPECFILE" ]; then
2506 Exit_error err_no_spec_in_cmdl
2509 get_spec > /dev/null
2511 local bcond_avail=$(find_spec_bcond $SPECFILE)
2512 local opt bcond bconds
2513 for opt in $bcond_avail; do
2516 bcond=${opt#without_}
2517 bconds="$bconds $bcond"
2521 bconds="$bconds $bcond"
2524 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2532 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2534 if [ -z "$SPECFILE" ]; then
2535 Exit_error err_no_spec_in_cmdl
2538 # display SMP make flags if set
2539 smp_mflags=$(rpm -E %{?_smp_mflags})
2540 if [ "$smp_mflags" ]; then
2541 echo "builder: SMP make flags are set to $smp_mflags"
2549 if [ "$COMMAND" != "build-source" ]; then
2552 fetch_build_requires
2553 if [ "$INTEGER_RELEASE" = "yes" ]; then
2554 echo "Checking release $PACKAGE_RELEASE..."
2555 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2556 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2560 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2561 if [ -n "$TEST_TAG" ]; then
2562 local TAGVER=`make_tagver`
2563 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2564 # check also tags created in CVS
2565 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2566 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2567 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2568 || Exit_error err_tag_exists $TAGVER_CVS
2569 # - do not allow to build from HEAD when XX-branch exists
2570 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2571 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2572 TAG_BRANCH="${TREE_PREFIX}-branch"
2573 if [ -n "$DEPTH" ]; then
2574 cmd_branches="git ls-remote --heads"
2575 ref_prefix=refs/heads
2577 cmd_branches="git show-ref"
2578 ref_prefix=refs/remotes/${REMOTE_PLD}
2580 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2581 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2582 Exit_error err_branch_exists "$TAG_STATUS"
2588 if [ -n "$NOSOURCE0" ] ; then
2589 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2594 get_files $SOURCES $PATCHES
2595 check_md5 $SOURCES $PATCHES
2598 NODIST="yes" get_files $SOURCES $PATCHES
2599 update_md5 $SOURCES $PATCHES
2603 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2604 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2606 remove_build_requires
2610 if [ -z "$SPECFILE" ]; then
2611 Exit_error err_no_spec_in_cmdl
2620 if [ -z "$SPECFILE" ]; then
2621 Exit_error err_no_spec_in_cmdl
2625 if [ -n "$NEW_REPO" ]; then
2628 for file in $SOURCES $PATCHES; do
2629 if [ -z $(src_md5 "$file") ]; then
2630 git add $file || Exit_error err_no_source_in_repo $file
2632 cvsignore_df `nourl $file`
2636 echo "When you are ready commit your changes and run git push origin master"
2638 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2643 if [ -z "$SPECFILE" ]; then
2644 Exit_error err_no_spec_in_cmdl
2650 if [ -n "$NOSOURCE0" ] ; then
2651 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2653 get_files $SOURCES $PATCHES
2658 if [ -z "$SPECFILE" ]; then
2659 Exit_error err_no_spec_in_cmdl
2665 if [ -n "$NOSOURCE0" ] ; then
2666 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2668 update_md5 $SOURCES $PATCHES
2674 if [ -z "$SPECFILE" ]; then
2675 Exit_error err_no_spec_in_cmdl
2679 if [ ! -d .git ]; then
2680 echo "No git reposiotory" >&2
2688 "list-sources-files" )
2691 DONT_PRINT_REVISION="yes"
2694 for SAP in $SOURCES $PATCHES; do
2695 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2698 "list-sources-urls" )
2701 DONT_PRINT_REVISION="yes"
2704 SAPS="$SOURCES $PATCHES"
2705 for SAP in $SAPS; do
2709 "list-sources-local-paths" )
2712 DONT_PRINT_REVISION="yes"
2715 for SAP in $SOURCES $PATCHES; do
2716 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2719 "list-sources-distfiles-paths" )
2722 DONT_PRINT_REVISION="yes"
2725 for SAP in $SOURCES $PATCHES; do
2726 if [ -n "$(src_md5 "$SAP")" ]; then
2727 distfiles_path "$SAP"
2731 "list-sources-distfiles" )
2734 DONT_PRINT_REVISION="yes"
2737 for SAP in $SOURCES $PATCHES; do
2738 if [ -n "$(src_md5 "$SAP")" ]; then
2739 distfiles_url "$SAP"
2743 "list-sources-cvs" )
2746 DONT_PRINT_REVISION="yes"
2749 for SAP in $SOURCES $PATCHES; do
2750 if [ -z "$(src_md5 "$SAP")" ]; then
2751 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2765 echo "$VERSIONSTRING"
2768 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2769 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2773 # vi:syntax=sh:ts=4:sw=4:noet