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-2012 Free Penguins".
44 CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
46 # required rpm-build-macros
65 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
67 # use rpm 4.4.6+ digest format instead of comments if non-zero
70 # user agent when fetching files
71 USER_AGENT="PLD/Builder($VERSION)"
73 # It can be used i.e. in log file naming.
74 # See LOGFILE example.
75 DATE=`date +%Y-%m-%d_%H-%M-%S`
77 # target arch, can also be used for log file naming
78 TARGET=$(rpm -E %{_target})
80 # Example: LOGFILE='../log.$PACKAGE_NAME'
81 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
82 # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
83 # Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
84 # Yes, you can use variable name! Note _single_ quotes!
99 # create symlinks for tools in PACKAGE_DIR, see get_spec()
111 # use lftp by default when available
113 lftp --version > /dev/null 2>&1 && USE_LFTP=yes
114 PARALLEL_DOWNLOADS=10
116 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
121 GIT_SERVER="git://git.pld-linux.org"
122 GIT_PUSH="git@git.pld-linux.org"
123 PACKAGES_DIR="packages"
132 DISTFILES_SERVER="://distfiles.pld-linux.org"
133 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
138 FAIL_IF_NO_SOURCES="yes"
140 # let get_files skip over files which are present to get those damn files fetched
141 SKIP_EXISTING_FILES="no"
144 # should the specfile be restored if upgrade failed?
145 REVERT_BROKEN_UPGRADE="yes"
147 if rpm --specsrpm 2>/dev/null; then
148 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
149 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
151 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
152 if [ -x /usr/bin/rpm-getdeps ]; then
153 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
155 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
159 UPDATE_POLDEK_INDEXES_OPTS=""
161 # Here we load saved user environment used to
162 # predefine options set above, or passed to builder
164 # This one reads global system environment settings:
165 if [ -f ~/etc/builderrc ]; then
168 # And this one cascades settings using user personal
170 # Example of ~/.builderrc:
172 #UPDATE_POLDEK_INDEXES="yes"
173 #UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
174 #FETCH_BUILD_REQUIRES="yes"
175 #REMOVE_BUILD_REQUIRES="force"
177 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
181 if [ -n "$HOME_ETC" ]; then
182 USER_CFG="$HOME_ETC/.builderrc"
183 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
185 USER_CFG=~/.builderrc
186 BUILDER_MACROS=~/.builder-rpmmacros
189 [ -f "$USER_CFG" ] && . "$USER_CFG"
191 if [ "$SCHEDTOOL" = "auto" ]; then
192 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
193 SCHEDTOOL="schedtool -B -e"
199 if [ -n "$USE_PROZILLA" ]; then
200 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
203 elif [ -n "$USE_AXEL" ]; then
204 GETURI="axel -a $AXEL_OPTS"
207 elif [ -n "$USE_LFTP" ]; then
212 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
213 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
214 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
215 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
217 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
218 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
224 if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
235 if [ -d $HOME/rpm/SOURCES ]; then
236 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
237 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
241 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
242 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
246 if [ -n "$LOGFILE" ]; then
247 LOG=`eval echo $LOGFILE`
248 if [ -n "$LASTLOG_FILE" ]; then
249 echo "LASTLOG=$LOG" > $LASTLOG_FILE
251 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
254 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
255 return `cat ${RES_FILE}`
260 #---------------------------------------------
264 local outfile=$1 url=$2 retval tmpfile
268 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
269 set ssl:verify-certificate no;
270 set net:max-retries $WGET_RETRIES;
271 set http:user-agent \"$USER_AGENT\";
272 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
276 if [ $retval -eq 0 ]; then
277 mv -f "$tmpfile" "$outfile"
285 if [ -n "$DEBUG" ]; then set -xv; fi
287 # to make this output parseable by bash-completion _parse_help()
288 # if the line contains short and long option, it will take only the long option
289 # but if you want both being completed, put the short option to separate line
291 Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
292 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
293 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
294 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
295 [-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
296 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
297 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
298 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
299 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
300 <package>[.spec][:tag]
302 -4 - force IPv4 when transferring files
303 -6 - force IPv6 when transferring files
305 --update-md5 - update md5 comments in spec, implies -nd -ncs
307 --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
308 --all-branches - make shallow fetch of all branches; --depth required
309 -n5, --no-md5 - ignore md5 comments in spec
310 -D, --debug - enable builder script debugging mode,
311 -debug - produce rpm debug package (same as --opts -debug)
312 -V, --version - output builder version string
313 --short-version - output builder short version
314 -a - try add new package to PLD repo.
317 - get all files from PLD repo or HTTP/FTP and build package
319 -bb - get all files from PLD repo or HTTP/FTP and build binary
320 only package from <package>.spec,
321 -bp - execute the %prep phase of <package>.spec,
322 -bc - execute the %build phase of <package>.spec,
323 -bi - execute the %install phase of <package>.spec
324 -bl - execute the %files phase of <package>.spec
325 -bs - get all files from PLD repo or HTTP/FTP and only pack
327 --short-circuit - short-circuit build
328 -B, --branch - add branch
330 --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
331 may be used with building process.
332 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
333 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
334 -cf, --cvs-force - use -f when tagging
335 --define '<macro> <value>'
336 - define a macro <macro> with value <value>,
337 --depth <number> - make shallow fetch
338 --alt_kernel <kernel>
339 - same as --define 'alt_kernel <kernel>'
340 --nodeps - rpm won't check any dependences
342 --get - get <package>.spec and all related files from PLD repo
343 -h, --help - this message,
344 -j N - set %_smp_mflags to propagate concurrent jobs
345 --ftp - use FTP protocol to access distfiles server
346 --http - use HTTP protocol to access distfiles server
347 -l <logfile>, --logtofile=<logfile>
350 - don't pull from PLD repo
351 -nd, --no-distfiles - don't download from distfiles
352 -nm, --no-mirrors - don't download from mirror, if source URL is given,
353 -nu, --no-urls - don't try to download from FTP/HTTP location,
354 -ns, --no-srcs - don't download Sources/Patches
355 -ns0, --no-source0 - don't download Source0
356 -nn, --no-net - don't download anything from the net
357 -p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
358 -pm, --prefer-mirrors
359 - prefer mirrors (if any) over distfiles for SOURCES
360 --no-init - don't initialize builder paths (SPECS and SOURCES)
362 --skip-existing-files
363 - skip existing files in get_files
364 --opts <rpm opts> - additional options for rpm
365 -q, --quiet - be quiet,
366 --date yyyy-mm-dd - build package using resources from specified date,
367 -r <tag>, --cvstag <ref>
368 - build package using resources from specified branch/tag,
369 -A - build package using master branch as any sticky tags/branch/date being reset.
370 -R, --fetch-build-requires
371 - fetch what is BuildRequired,
372 -RB, --remove-build-requires
373 - remove all you fetched with -R or --fetch-build-requires
374 remember, this option requires confirmation,
375 -FRB, --force-remove-build-requires
376 - remove all you fetched with -R or --fetch-build-requires
377 remember, this option works without confirmation,
378 -sd, --source-distfiles
379 - list sources available from distfiles (intended for offline
380 operations; does not work when Icon field is present
381 but icon file is absent),
382 -sc, --source-cvs - list sources available from PLD repo
383 -sdp, --source-distfiles-paths
384 - list sources available from distfiles -
385 paths relative to distfiles directory (intended for offline
386 operations; does not work when Icon field is present
387 but icon file is absent),
388 -sf, --source-files - list sources - bare filenames (intended for offline
389 operations; does not work when Icon field is present
390 but icon file is absent),
392 - list sources - filenames with full local paths (intended for
393 offline operations; does not work when Icon field is present
394 but icon file is absent),
395 -su, --source-urls - list urls - urls to sources and patches
396 intended for copying urls with spec with lots of macros in urls
397 -T <tag> , --tag <tag>
398 - add git tag <tag> for files,
399 -Tvs, --tag-version-stable
400 - add git tags STABLE and NAME-VERSION-RELEASE for files,
402 - add git tag STABLE for files,
404 --tag-version - add git tag NAME-VERSION-RELEASE for files,
405 -Tp, --tag-prefix <prefix>
406 - add <prefix> to NAME-VERSION-RELEASE tags,
407 -tt, --test-tag <prefix>
408 - fail if tag is already present,
409 -ir, --integer-release-only
410 - allow only integer and snapshot releases
411 -v, --verbose - be verbose,
412 -u, --try-upgrade - check version, and try to upgrade package
413 -un, --try-upgrade-with-float-version
414 - as above, but allow float version
415 php-pear-Services_Digg/
416 --upgrade-version - upgrade to specified version in try-upgrade
417 -U, --update - refetch sources, don't use distfiles, and update md5 comments
418 -Upi, --update-poldek-indexes
419 - refresh or make poldek package index files.
421 --skip-patch <patchnumber>
422 - don't apply <patchnumber>. may be repeated.
424 --nopatch <patchnumber>
425 - abort instead of applying patch <patchnumber>
427 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
428 --show-bconds - show available conditional builds, which can be used
429 - with --with and/or --without switches.
430 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
431 In other words, the output is parseable by scripts.
432 --show-avail-bconds - show available bconds
435 - conditional build package depending on %_with_<feature>/
436 %_without_<feature> macro switch. You may now use
437 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
438 constructions. Set GROUP_BCONDS to yes to make use of it.
439 --target <platform>, --target=<platform>
440 - build for platform <platform>.
441 --init-rpm-dir - initialize ~/rpm directory structure
445 # create tempfile. as secure as possible
447 mktemp --tmpdir -t builder.$PACKAGE_NAME.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
451 mktemp --tmpdir -d builder.$PACKAGE_NAME.XXXXXX
454 # inserts git log instead of %changelog
455 # outputs name of modified file created by tempfile
457 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
459 # allow this being customized
460 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
462 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
463 # otherwise i'd use --date=iso here
464 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
465 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c#l31
466 # NOTE: changelog date is always in UTC for rpmbuild
467 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
468 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
470 git notes list $sha1 > /dev/null 2>&1 && logfmt=%N
471 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n${logfmt}%n" --date=raw | sed '/^$/q'
474 # add link to full git logs
475 local giturl="http://git.pld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
476 if [ -n "$CVSTAG" ]; then
477 giturl="$giturl;h=$CVSTAG"
479 local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
480 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
481 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
486 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
487 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
491 " > $specdir/$SPECFILE
492 rm -f $gitlog $speclog
496 # change dependency to specname
498 # - perl(Package::Name) -> perl-Package-Name
502 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
506 update_shell_title() {
508 local len=${COLUMNS:-80}
509 local msg="$(echo "$*" | cut -c-$len)"
511 if [ -n "$BE_VERBOSE" ]; then
512 echo >&2 "$(date +%s.%N) $*"
515 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
517 if [ -n "$PACKAGE_NAME" ]; then
518 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
523 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
524 msg=$(echo $msg | tr -d '\n\r')
527 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
530 echo >&2 -ne "\033]0;$msg\007"
536 # set TARGET from BuildArch: from SPECFILE
538 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
539 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
541 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
545 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
547 TARGET_SWITCH="--target=$TARGET" ;;
553 # runs rpm with minimal macroset
555 # we reset macros not to contain macros.build as all the %() macros are
556 # executed here, while none of them are actually needed.
557 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
558 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
560 # TODO: move these to /usr/lib/rpm/macros
561 cat > $BUILDER_MACROS <<'EOF'
562 %x8664 x86_64 amd64 ia32e
565 %bootstrap_release() %{1}
566 %requires_releq_kernel_up(s:n:) %{nil}
567 %requires_releq_kernel_smp(s:n:) %{nil}
568 %requires_releq_kernel(s:n:) %{nil}
569 %requires_releq() %{nil}
570 %pyrequires_eq() %{nil}
571 %requires_eq() %{nil}
572 %requires_eq_to() %{nil}
573 %requires_ge() %{nil}
574 %requires_ge_to() %{nil}
575 %requires_ge() %{nil}
576 %releq_kernel_up(n:) ERROR
577 %releq_kernel_smp(n:) ERROR
578 %releq_kernel(n:) ERROR
582 %ruby_ver_requires_eq() %{nil}
583 %ruby_mod_ver_requires_eq() %{nil}
584 %__php_api_requires() %{nil}
585 %php_major_version ERROR
586 %php_api_version ERROR
587 %requires_xorg_xserver_extension %{nil}
588 %requires_xorg_xserver_xinput %{nil}
589 %requires_xorg_xserver_font %{nil}
590 %requires_xorg_xserver_videodrv %{nil}
592 %perl_vendorarch ERROR
593 %perl_vendorlib ERROR
594 # damn. need it here! - copied from /usr/lib/rpm/macros.build
595 %tmpdir %(echo "${TMPDIR:-/tmp}")
596 %patchset_source(f:b:) %(
597 base=%{-b*}%{!-b*:10000};
598 start=$(expr $base + %1);
599 end=$(expr $base + %{?2}%{!?2:%{1}});
600 # we need to call seq twice as it doesn't allow two formats
601 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
602 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
603 paste %{tmpdir}/__ps{1,2};
604 rm -f %{tmpdir}/__ps{1,2};
607 %add_etc_shells(p) %{p:<lua>}
608 %remove_etc_shells(p) %{p:<lua>}
609 %lua_add_etc_shells() %{nil}
610 %lua_remove_etc_shells() %{nil}
612 %buildrequires_jdk %{nil}
613 %pear_package_print_optionalpackages %{nil}
615 if [ "$NOINIT" = "yes" ] ; then
616 cat >> $BUILDER_MACROS <<'EOF'
621 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
625 if [ -n "$DEBUG" ]; then
630 if [ -x /usr/bin/rpm-specdump ]; then
631 update_shell_title "cache_rpm_dump using rpm-specdump command"
632 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
634 update_shell_title "cache_rpm_dump using rpmbuild command"
637 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
638 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
644 ARGS='--nodigest --nosignature --nobuild'
647 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
649 if [ $? -gt 0 ]; then
650 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
652 Exit_error err_build_fail
655 # make small dump cache
656 rpm_dump_cache=`echo "$rpm_dump" | awk '
657 $2 ~ /^SOURCEURL/ {print}
658 $2 ~ /^PATCHURL/ {print}
659 $2 ~ /^nosource/ {print}
660 $2 ~ /^PACKAGE_/ {print}
664 update_shell_title "cache_rpm_dump: OK!"
668 if [ -z "$rpm_dump_cache" ] ; then
669 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
671 echo "$rpm_dump_cache"
675 update_shell_title "get icons"
676 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
677 if [ -z "$ICONS" ]; then
681 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
685 update_shell_title "parsing specfile"
686 if [ -n "$DEBUG" ]; then
691 # icons are needed for successful spec parse
697 if rpm_dump | grep -qEi ":.*nosource.*1"; then
698 FAIL_IF_NO_SOURCES="no"
701 if [ "$NOSRCS" != "yes" ]; then
702 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
703 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
704 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
707 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
708 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
709 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
711 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
712 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
715 if [ -n "$BE_VERBOSE" ]; then
716 echo "- Sources : `nourl $SOURCES`"
717 if [ -n "$PATCHES" ]; then
718 echo "- Patches : `nourl $PATCHES`"
720 echo "- Patches : *no patches needed*"
722 if [ -n "$ICONS" ]; then
723 echo "- Icon : `nourl $ICONS`"
725 echo "- Icon : *no package icon*"
727 echo "- Name : $PACKAGE_NAME"
728 echo "- Version : $PACKAGE_VERSION"
729 echo "- Release : $PACKAGE_RELEASE"
732 update_shell_title "parse_spec: OK!"
736 if [ -n "$DEBUG" ]; then
744 "err_no_spec_in_cmdl" )
745 remove_build_requires
746 echo >&2 "ERROR: spec file name not specified."
748 "err_invalid_cmdline" )
749 echo >&2 "ERROR: invalid command line arg ($2)."
751 "err_no_spec_in_repo" )
752 remove_build_requires
753 echo >&2 "Error: spec file not stored in PLD repo."
755 "err_no_source_in_repo" )
756 remove_build_requires
757 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
759 "err_cvs_add_failed" )
760 echo >&2 "Error: failed to add package to PLD repo."
763 remove_build_requires
764 echo >&2 "Error: package build failed. (${2:-no more info})"
766 "err_no_package_data" )
767 remove_build_requires
768 echo >&2 "Error: couldn't get out package name/version/release from spec file."
771 remove_build_requires
772 echo >&2 "Tag ${2} already exists"
775 remove_build_requires
776 echo >&2 "Release ${2} not integer and not a snapshot."
778 "err_branch_exists" )
779 remove_build_requires
780 echo >&2 "Tree branch already exists (${2})."
783 remove_build_requires
784 echo >&2 "Error: conditions reject building this spec (${2})."
786 "err_remote_problem" )
787 remove_build_requires
788 echo >&2 "Error: problem with remote (${2})"
791 echo >&2 "Error: cannot checkout $2"
793 "err_not_implemented" )
794 remove_build_requires
795 echo >&2 "Error: functionality not yet imlemented"
798 echo >&2 "Unknown error."
803 if [ -n "$DEBUG" ]; then
808 if [ "$NOINIT" != "yes" ] ; then
809 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
811 local macros_ver=$(rpm -E %?rpm_build_macros)
812 if [ -z "$macros_ver" ]; then
813 REPO_DIR=$TOP_DIR/packages
814 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
816 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
817 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
821 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
827 export GIT_WORK_TREE=$PACKAGE_DIR
828 export GIT_DIR=$PACKAGE_DIR/.git
830 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
831 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
832 CVSTAG=${CVSTAG#refs/heads/}
833 if [ "$CVSTAG" != "master" ]; then
834 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
837 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
840 elif [ "$CVSTAG" = "HEAD" ]; then
841 # assume -r HEAD is same as -A
849 update_shell_title "add_package"
851 if [ -n "$DEBUG" ]; then
857 SPECFILE=$(basename $SPECFILE)
858 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
859 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
862 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
863 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
865 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git && \
866 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} \
867 || Exit_error err_remote_problem $REMOTE_PLD
872 update_shell_title "get_spec"
874 if [ -n "$DEBUG" ]; then
880 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
882 SPECFILE=$(basename $SPECFILE)
885 if [ "$NOCVSSPEC" != "yes" ]; then
886 if [ -z "$DEPTH" ]; then
887 if [ -d "$ASSUMED_NAME/.git" ]; then
888 git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
889 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
890 if [ ! -r "$ASSUMED_NAME/$SPECFILE" ]; then
891 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
894 Exit_error err_not_implemented
898 git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
899 # softfail if new package, i.e not yet added to PLD rep
900 [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo
901 echo "Warning: package not in CVS - assuming new package"
904 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
905 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
909 if [ ! -d "$ASSUMED_NAME/.git" ]; then
910 if [ ! -d "$ASSUMED_NAME" ]; then
914 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
915 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
916 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
917 CVSTAG=${CVSTAG:-"master"}
920 if [ -z "$ALL_BRANCHES" ]; then
921 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
923 git fetch $DEPTH $REMOTE_PLD $refs || {
924 echo >&2 "Error: branch $CVSTAG does not exist"
928 git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*'
930 cvsignore_df .gitignore
932 # add default log format to .gitignore if it is relative to package dir
933 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
934 # substitute known "macros" to glob
935 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\|TARGET\),*,g')
936 if [ "$logfile" ]; then
937 cvsignore_df "$logfile"
941 # create symlinks for tools
942 if [ "$SYMLINK_TOOLS" != "no" -a -d "$ASSUMED_NAME" ]; then
943 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
944 # skip tools that don't exist in top dir
945 [ -f $a ] || continue
946 # skip tools that already exist
947 [ -f $ASSUMED_NAME/$a ] && continue
948 ln -s ../$a $ASSUMED_NAME
954 if [ -n "$CVSTAG" ]; then
955 if git rev-parse --verify -q "$CVSTAG"; then
956 git checkout "$CVSTAG" --
957 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
958 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
960 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
961 Exit_error "err_no_checkut" "$CVSTAG"
963 git merge --ff-only '@{u}'
964 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
965 if [ -n "$CVSDATE" ]; then
966 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
970 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
971 Exit_error err_no_spec_in_repo
974 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
975 chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE
978 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE
986 if [ ! -f "mirrors" ] ; then
987 ln -s ../rpm-build-tools/mirrors .
991 local origin mirror name rest ol prefix
992 while read origin mirror name rest; do
993 # skip comments and empty lines
994 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
997 ol=$(echo -n "$origin" | wc -c)
998 prefix=$(echo -n "$url" | head -c $ol)
999 if [ "$prefix" = "$origin" ] ; then
1000 suffix=$(echo "$url" | cut -b $((ol+1))-)
1001 echo -n "$mirror$suffix"
1008 # Warning: unpredictable results if same URL used twice
1011 # escape some regexp characters if part of file name
1012 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1015 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1016 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1017 head -n 1 | tr OURCEATH ourceath | xargs
1021 [ "$NO5" = "yes" ] && return
1023 [ -z "$no" ] && return
1027 if [ -f additional-md5sums ]; then
1028 md5=$(grep -s -v '^#' additional-md5sums | \
1029 grep -E "[ ]$(basename "$1")([ ,]|\$)" | \
1030 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1031 grep -E '^[0-9a-f]{32}$')
1034 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1035 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
1037 echo "$md5" | tail -n 1
1042 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1043 if [ -n "$source_md5" ]; then
1046 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1047 if [ -n "$source_md5" ]; then
1050 # we have empty SourceX-md5, but it is still possible
1051 # that we have NoSourceX-md5 AND NoSource: X
1052 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1053 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1061 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1065 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1068 distfiles_attic_url() {
1069 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
1074 [ "$md5" = "" ] || \
1075 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1079 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1080 [ -n "$size" -a "$size" -gt 0 ]
1084 if [ "$CVSIGNORE_DF" != "yes" ]; then
1087 cvsignore=${PACKAGE_DIR}/.gitignore
1089 # add only if not yet there
1090 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1091 echo "$1" >> $cvsignore
1095 # returns true if "$1" is ftp, http or https protocol url
1098 ftp://*|http://*|https://*)
1106 if [ $# -eq 0 ]; then
1110 update_shell_title "update md5"
1111 if [ -n "$DEBUG" ]; then
1118 # pass 1: check files to be fetched
1122 local fp=$(nourl "$i")
1123 local srcno=$(src_no "$i")
1124 if [ -n "$ADD5" ]; then
1125 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1126 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1127 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1129 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1131 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1132 need_files="$need_files $i"
1136 # pass 1a: get needed files
1137 if [ "$need_files" ]; then
1138 get_files $need_files
1141 # pass 2: proceed with md5 adding or updating
1143 local fp=$(nourl "$i")
1144 local srcno=$(src_no "$i")
1145 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1146 if [ -z "$md5" ]; then
1147 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1149 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1150 local tag="# $srcno-md5:\t"
1151 if [[ "$md5" == *NoSource* ]]; then
1152 tag="# No$srcno-md5:\t"
1153 elif [ -n "$USEDIGEST" ]; then
1154 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1156 md5=$(md5sum "$fp" | cut -f1 -d' ')
1157 echo "Updating $srcno ($md5: $fp)."
1159 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1160 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1162 $PACKAGE_DIR/$SPECFILE
1169 [ "$NO5" = "yes" ] && return
1171 update_shell_title "check md5"
1175 if ! good_md5 "$i"; then
1176 echo -n "MD5 sum mismatch."
1179 if ! good_size "$i"; then
1180 echo -n "0 sized file."
1184 if [ $bad -eq 1 ]; then
1185 echo " Use -U to refetch sources,"
1186 echo "or -5 to update md5 sums, if you're sure files are correct."
1187 Exit_error err_no_source_in_repo $i
1193 update_shell_title "get_files"
1195 if [ -n "$DEBUG" ]; then
1200 if [ $# -gt 0 ]; then
1204 local get_files_cvs=""
1208 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1209 update_shell_title "$i"
1210 local fp=`nourl "$i"`
1211 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1216 local srcmd5=$(src_md5 "$i")
1218 # we know if source/patch is present in cvs/distfiles
1219 # - has md5 (in distfiles)
1220 # - in cvs... ideas?
1222 # CHECK: local file didn't exist or always cvs up (first) requested.
1223 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1224 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1225 echo "Warning: no URL given for $i"
1229 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1230 if good_md5 "$i" && good_size "$i"; then
1231 echo "$fp having proper md5sum already exists"
1235 # optionally prefer mirror over distfiles if there's mirror
1236 # TODO: build url list and then try each url from the list
1237 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1240 url=$(distfiles_url "$i")
1243 url_attic=$(distfiles_attic_url "$i")
1245 # is $url local file?
1246 if [[ "$url" = [./]* ]]; then
1247 update_shell_title "${GETLOCAL%% *}: $url"
1248 ${GETLOCAL} $url $target
1251 # make shorter message for distfiles urls
1252 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1253 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1254 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1257 update_shell_title "${GETURI%% *}: $uri"
1258 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1259 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1260 update_shell_title "${GETURI2%% *}: $url"
1261 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1266 if [ ! -s "$target" ]; then
1268 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1269 update_shell_title "${GETLOCAL%% *}: $url_attic"
1270 ${GETLOCAL} $url_attic $target
1272 update_shell_title "${GETURI%% *}: $url_attic"
1273 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1274 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1275 update_shell_title "${GETURI2%% *}: $url_attic"
1276 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1278 test -s "$target" || rm -f "$target"
1282 if [ -s "$target" ]; then
1283 cvsignore_df $target
1290 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1291 if [ -z "$NOMIRRORS" ]; then
1292 im=$(find_mirror "$i")
1296 update_shell_title "${GETURI%% *}: $im"
1297 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1298 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1299 update_shell_title "${GETURI2%% *}: $im"
1300 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1302 test -s "$target" || rm -f "$target"
1305 if [ "$cvsup" = 1 ]; then
1311 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1312 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1313 Exit_error err_no_source_in_repo $i
1316 # we check md5 here just only to refetch immediately
1317 if good_md5 "$i" && good_size "$i"; then
1319 elif [ "$FROM_DISTFILES" = 1 ]; then
1320 # wrong md5 from distfiles: remove the file and try again
1322 echo "MD5 sum mismatch. Trying full fetch."
1325 update_shell_title "${GETURI%% *}: $url"
1326 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1327 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1328 update_shell_title "${GETURI2%% *}: $url"
1329 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1331 if [ ! -s "$target" ]; then
1333 update_shell_title "${GETURI%% *}: $url_attic"
1334 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1335 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1336 update_shell_title "${GETURI2%% *}: $url_attic"
1337 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1340 test -s "$target" || rm -f "$target"
1343 SHELL_TITLE_PREFIX=""
1346 if [ "$CHMOD" = "yes" ]; then
1347 CHMOD_FILES=$(nourl "$@")
1348 if [ -n "$CHMOD_FILES" ]; then
1349 chmod $CHMOD_MODE $CHMOD_FILES
1356 # If tag exists and points to other commit exit with error
1357 # If it existsts and points to HEAD return 1
1358 # If it doesn't exist return 0
1360 local sha1=$(git rev-parse HEAD)
1361 echo "Searching for tag $_tag..."
1362 if [ -n "$DEPTH" ]; then
1363 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1365 local ref=$(git show-ref -s "refs/tags/$_tag")
1367 [ -z "$ref" ] && return 0
1368 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1373 if [ -n "$DEBUG" ]; then
1378 # Check whether first character of PACKAGE_NAME is legal for tag name
1379 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1383 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1384 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1386 # Remove @kernel.version_release from TAGVER because tagging sources
1387 # could occur with different kernel-headers than kernel-headers used at build time.
1388 # besides, %{_kernel_ver_str} is not expanded.
1390 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1391 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1398 if [ -n "$DEBUG" ]; then
1403 echo "Version: $PACKAGE_VERSION"
1404 echo "Release: $PACKAGE_RELEASE"
1407 if [ "$TAG_VERSION" = "yes" ]; then
1410 if [ -n "$TAG" ]; then
1415 local OPTIONS="tag $CVS_FORCE"
1419 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1420 update_shell_title "tag sources: $_tag"
1421 git $OPTIONS $_tag || exit
1422 git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1424 echo "Tag $_tag already exists and points to the same commit"
1430 echo "Git branch: $TAG"
1433 if [ -n "$DEBUG" ]; then
1438 local OPTIONS="branch $CVS_FORCE"
1441 git $OPTIONS $TAG || exit
1445 # this function should exit early if package can't be built for this arch
1446 # this avoids unneccessary BR filling.
1449 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1451 if [ $ret -ne 0 ]; then
1463 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1464 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1470 local ver="$2" subver=$ver
1471 local newver="$3" newsubver=$newver
1473 # try handling subver, everything that's not numeric-dotted in version
1474 if grep -Eq '%define\s+subver' $specfile; then
1475 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1477 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1478 newver=${newver%$newsubver}
1481 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1482 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1483 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1488 if [ -n "$TRY_UPGRADE" ]; then
1489 local TNOTIFY TNEWVER TOLDVER
1490 update_shell_title "build_package: try_upgrade"
1494 if [ "$UPGRADE_VERSION" ]; then
1495 TNEWVER=$UPGRADE_VERSION
1497 if [ -n "$FLOAT_VERSION" ]; then
1498 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1500 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1503 # pldnotify.awk does not set exit codes, but it has match for ERROR
1504 # in output which means so.
1505 if [[ "$TNOTIFY" = *ERROR* ]]; then
1510 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1513 if [ -n "$TNEWVER" ]; then
1514 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1515 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1516 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1517 cp -f $SPECFILE $SPECFILE.bak
1520 set_release $SPECFILE $PACKAGE_RELEASE 1
1521 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1523 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1524 echo >&2 "Upgrading version failed, you need to update spec yourself"
1534 update_shell_title "build_package"
1535 if [ -n "$DEBUG" ]; then
1544 BUILD_SWITCH="-ba" ;;
1546 BUILD_SWITCH="-bb" ;;
1548 BUILD_SWITCH="-bs --nodeps" ;;
1550 BUILD_SWITCH="-bp --nodeps" ;;
1552 BUILD_SWITCH="-bc" ;;
1554 BUILD_SWITCH="-bi" ;;
1556 BUILD_SWITCH="-bl" ;;
1560 update_shell_title "build_package: $COMMAND"
1561 if [ -n "$LOGFILE" ]; then
1562 LOG=`eval echo $LOGFILE`
1563 if [ -d "$LOG" ]; then
1564 echo "Log file $LOG is a directory."
1565 echo "Parse error in the spec?"
1566 Exit_error err_build_fail
1568 if [ -n "$LASTLOG_FILE" ]; then
1569 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1571 RES_FILE=$(tempfile)
1572 local specdir=$(insert_gitlog $SPECFILE)
1574 (time eval PATH=$CLEAN_PATH ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
1575 RETVAL=`cat $RES_FILE`
1576 rm -r $RES_FILE $specdir
1577 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1578 if [ "$RETVAL" -eq "0" ]; then
1585 local specdir=$(insert_gitlog $SPECFILE)
1586 eval PATH=$CLEAN_PATH ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE
1590 if [ "$RETVAL" -ne "0" ]; then
1591 if [ -n "$TRY_UPGRADE" ]; then
1592 echo "\nUpgrade package to new version failed."
1593 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1594 echo "Restoring old spec file."
1595 mv -f $SPECFILE.bak $SPECFILE
1599 Exit_error err_build_fail
1605 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1608 install_required_packages() {
1613 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1616 /^%changelog/ { exit }
1618 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1619 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1620 gsub(/[ \t]+/, "_", bcond);
1622 }' $SPEC | LC_ALL=C sort -u
1626 # expand bconds from ~/.bcondrc
1627 # The file structure is like gentoo's package.use:
1630 # samba -mysql -pgsql
1631 # w32codec-installer license_agreement
1634 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1640 SN=${SPECFILE%%\.spec}
1642 local bcondrc=$HOME/.bcondrc
1643 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1645 local bcond_avail=$(find_spec_bcond $SPECFILE)
1647 while read pkg flags; do
1649 [[ "$pkg" == \#* ]] && continue
1651 # any package or current package?
1652 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1653 for flag in $flags; do
1654 local opt=${flag#[+-]}
1656 # use only flags which are in this package.
1657 if [[ $bcond_avail = *${opt}* ]]; then
1658 if [[ $flag = -* ]]; then
1659 if [[ $BCOND != *--with?${opt}* ]]; then
1660 BCOND="$BCOND --without $opt"
1663 if [[ $BCOND != *--without?${opt}* ]]; then
1664 BCOND="$BCOND --with $opt"
1671 update_shell_title "parse ~/.bcondrc: DONE!"
1674 set_bconds_values() {
1675 update_shell_title "set bcond values"
1677 AVAIL_BCONDS_WITHOUT=""
1678 AVAIL_BCONDS_WITH=""
1680 if grep -Eq '^# *_with' ${SPECFILE}; then
1681 echo >&2 "ERROR: This spec has old style bconds."
1685 if ! grep -q '^%bcond' ${SPECFILE}; then
1689 local bcond_avail=$(find_spec_bcond $SPECFILE)
1690 process_bcondrc "$SPECFILE"
1692 update_shell_title "parse bconds"
1695 for opt in $bcond_avail; do
1698 bcond=${opt#without_}
1700 *--without?${bcond}*)
1701 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1704 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1712 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1715 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1720 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1729 update_shell_title "run_sub_builder $package_name"
1731 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1732 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1733 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1734 # jakby nie bylo tego kawalka kodu.
1736 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1737 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1741 # kurwa. translate that ^^^^
1745 # Istnieje taki spec? ${package}.spec
1746 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1747 parent_spec_name=${package}.spec
1748 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1749 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1751 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1756 if [ "${parent_spec_name}" != "" ]; then
1757 spawn_sub_builder $parent_spec_name
1759 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1762 spawn_sub_builder() {
1764 update_shell_title "spawn_sub_builder $package_name"
1767 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1768 sub_builder_opts="${sub_builder_opts} -R"
1770 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1771 sub_builder_opts="${sub_builder_opts} -RB"
1772 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1773 sub_builder_opts="${sub_builder_opts} -FRB"
1775 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1776 sub_builder_opts="${sub_builder_opts} -Upi"
1780 ./builder ${sub_builder_opts} "$@"
1783 remove_build_requires() {
1784 if [ "$INSTALLED_PACKAGES" != "" ]; then
1785 case "$REMOVE_BUILD_REQUIRES" in
1787 run_poldek --noask -ve $INSTALLED_PACKAGES
1790 run_poldek --ask -ve $INSTALLED_PACKAGES
1793 echo You may want to manually remove following BuildRequires fetched:
1794 echo $INSTALLED_PACKAGES
1795 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1802 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1803 if [ "$BCOND" ]; then
1805 echo "Building $SPECFILE with the following conditional flags:"
1809 echo "No conditional flags passed"
1812 echo "from available:"
1813 echo "--with :\t$AVAIL_BCONDS_WITH"
1814 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1819 display_branches() {
1820 echo -n "Available branches: "
1821 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1824 # checks a given list of packages/files/provides agains current rpmdb.
1825 # outputs all dependencies which current rpmdb doesn't satisfy.
1826 # input can be either STDIN or parameters
1830 if [ $# -gt 0 ]; then
1836 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1839 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1841 # other deps (files)
1842 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1845 # checks if given package/files/provides exists in rpmdb.
1846 # input can be either stdin or parameters
1847 # returns packages which are present in the rpmdb
1851 if [ $# -gt 0 ]; then
1857 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1860 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1861 install_build_requires_rpmdeps() {
1862 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1863 # TODO: Conflicts list doesn't check versions
1864 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1865 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1867 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1868 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1869 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1872 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1873 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1874 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1875 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1877 if [ -n "$CNFL" ]; then
1878 update_shell_title "uninstall conflicting packages: $CNFL"
1879 echo "Trying to uninstall conflicting packages ($CNFL):"
1880 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1883 while [ "$DEPS" ]; do
1884 update_shell_title "install deps: $DEPS"
1885 echo "Trying to install dependencies ($DEPS):"
1886 local log=.${SPECFILE}_poldek.log
1887 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1888 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1891 if [ -n "$failed" ]; then
1892 for package in $failed; do
1893 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1902 fetch_build_requires()
1904 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1908 update_shell_title "fetch build requires"
1909 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1910 install_build_requires_rpmdeps
1914 # XXX is this ugliest code written in human history still needed?
1915 echo "All packages installed by fetch_build_requires() are written to:"
1916 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1918 echo "If anything fails, you may get rid of them by executing:"
1919 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
1921 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1922 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)
1924 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)
1926 package=$(basename "$package_item"|sed -e "s/}$//g")
1927 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
1930 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1931 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1932 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
1937 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1940 if `echo $COND_TST|grep -q 'without_'`; then
1941 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1942 if `echo $COND_TST|grep -q !`; then
1947 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1948 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1949 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1955 elif `echo $COND_TST|grep -q 'with_'`; then
1956 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1957 if `echo $COND_TST|grep -q !`; then
1962 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1963 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1964 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
1970 RESULT="${COND_STATE}-${COND_ARGV}"
1972 "with-wout" | "wout-with" )
1975 "wout-wout" | "with-with" )
1979 echo "Action '$RESULT' was not defined for package '$package_item'"
1985 if [ "$GO" = "yes" ]; then
1986 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1987 echo "Testing if $package has subrequirements..."
1988 run_poldek -t -i $package --dumpn=".$package-req.txt"
1989 if [ -f ".$package-req.txt" ]; then
1990 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1992 if [ "$package_name" = "$package" ]; then
1993 echo "Installing BuildRequired package:\t$package_name"
1994 update_shell_title "Installing BuildRequired package: ${package_name}"
1995 install_required_packages $package
1997 echo "Installing (sub)Required package:\t$package_name"
1998 update_shell_title "Installing (sub)Required package: ${package_name}"
1999 install_required_packages $package_name
2003 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2004 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2007 echo "Attempting to run spawn sub - builder..."
2008 echo "Package installation failed:\t$package_name"
2009 run_sub_builder $package_name
2010 if [ $? -eq 0 ]; then
2011 install_required_packages $package_name
2014 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2015 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2018 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2025 rm -f ".$package-req.txt"
2027 echo "Attempting to run spawn sub - builder..."
2028 echo "Package installation failed:\t$package"
2029 run_sub_builder $package
2030 if [ $? -eq 0 ]; then
2031 install_required_packages $package
2034 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2035 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2038 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2044 echo "Package $package is already installed. BuildRequirement satisfied."
2048 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2049 echo >&2 "Unable to install following packages and their dependencies:"
2050 for pkg in "$NOT_INSTALLED_PACKAGES"
2054 remove_build_requires
2060 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2061 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2062 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2063 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2066 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2067 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2070 if [ ! -e ../rpm-build-tools ]; then
2071 git clone ${GIT_SERVER}/${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2073 for a in adapter builder fetchsrc_request; do
2074 ln -sf ../rpm-build-tools/${a}.sh $a
2076 ln -sf ../rpm-build-tools/mirrors mirrors
2083 DONT_PRINT_REVISION="yes"
2085 # remove spec and sources
2086 PATH=$CLEAN_PATH $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $PACKAGE_DIR/$SPECFILE
2087 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2088 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2091 #---------------------------------------------
2099 while [ $# -gt 0 ]; do
2102 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2103 # unfortunately $GETURI is already formed
2108 COMMAND="update_md5"
2113 COMMAND="update_md5"
2122 DEBUG="yes"; shift ;;
2124 COMMAND="version"; shift ;;
2126 COMMAND="short-version"; shift ;;
2133 -b | -ba | --build )
2134 COMMAND="build"; shift ;;
2135 -bb | --build-binary )
2136 COMMAND="build-binary"; shift ;;
2138 COMMAND="build-build"; shift ;;
2140 COMMAND="build-install"; shift ;;
2142 COMMAND="build-list"; shift ;;
2143 -bp | --build-prep )
2144 COMMAND="build-prep"; shift ;;
2145 -bs | --build-source )
2146 COMMAND="build-source"; shift ;;
2148 COMMAND="branch"; shift; TAG="${1}"; shift;;
2150 CLEAN="--clean"; shift ;;
2152 CVS_FORCE="-f"; shift;;
2158 COMMAND="get"; shift ;;
2160 COMMAND="usage"; shift ;;
2162 PROTOCOL="ftp"; shift ;;
2164 PROTOCOL="http"; shift ;;
2166 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2170 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2174 PARALLEL_DOWNLOADS=$2
2178 PARALLEL_DOWNLOADS=${1#-p}
2182 shift; LOGFILE="${1}"; shift ;;
2184 shift; DEF_NICE_LEVEL=${1}; shift ;;
2185 -ske | --skip-existing-files)
2186 SKIP_EXISTING_FILES="yes"; shift ;;
2188 COMMAND="mr-proper"; shift ;;
2189 -ncs | --no-cvs-specs )
2190 NOCVSSPEC="yes"; shift ;;
2191 -nd | --no-distfiles )
2192 NODIST="yes"; shift ;;
2193 -nm | --no-mirrors )
2194 NOMIRRORS="yes"; shift ;;
2196 NOURLS="yes"; shift ;;
2198 NOSRCS="yes"; shift ;;
2199 -ns0 | --no-source0 )
2200 NOSOURCE0="yes"; shift ;;
2209 -pm | --prefer-mirrors )
2216 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2218 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2219 --skip-patch | -sp )
2220 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2222 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2225 --with | --without )
2226 case $GROUP_BCONDS in
2230 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2231 while ! `echo ${1}|grep -qE '(^-|spec)'`
2233 BCOND="$BCOND $COND $1"
2237 if [[ "$2" = *,* ]]; then
2238 for a in $(echo "$2" | tr , ' '); do
2239 BCOND="$BCOND $1 $a"
2242 BCOND="$BCOND $1 $2"
2248 shift; TARGET="${1}"; shift ;;
2250 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2252 QUIET="--quiet"; shift ;;
2254 CVSDATE="${2}"; shift 2
2255 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2265 -R | --fetch-build-requires)
2266 FETCH_BUILD_REQUIRES="yes"
2267 NOT_INSTALLED_PACKAGES=
2269 -RB | --remove-build-requires)
2270 REMOVE_BUILD_REQUIRES="nice"
2272 -FRB | --force-remove-build-requires)
2273 REMOVE_BUILD_REQUIRES="force"
2276 COMMAND="list-sources-cvs"
2278 -sd | --source-distfiles)
2279 COMMAND="list-sources-distfiles"
2281 -sdp | --source-distfiles-paths)
2282 COMMAND="list-sources-distfiles-paths"
2284 -sf | --source-files)
2285 COMMAND="list-sources-files"
2287 -lsp | --source-paths)
2288 COMMAND="list-sources-local-paths"
2290 -su | --source-urls)
2291 COMMAND="list-sources-urls"
2293 -Tvs | --tag-version-stable )
2298 -Ts | --tag-stable )
2303 -Tv | --tag-version )
2308 -Tp | --tag-prefix )
2320 -ir | --integer-release-only )
2321 INTEGER_RELEASE="yes"
2324 COMMAND="update_md5"
2329 -Upi | --update-poldek-indexes )
2330 UPDATE_POLDEK_INDEXES="yes"
2333 COMMAND="init_rpm_dir"
2335 -u | --try-upgrade )
2336 TRY_UPGRADE="1"; shift ;;
2338 shift; UPGRADE_VERSION="$1"; shift;;
2339 -un | --try-upgrade-with-float-version )
2340 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2342 BE_VERBOSE="1"; shift ;;
2347 if echo "${MACRO}" | grep -q '\W'; then
2348 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2352 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2357 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2361 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2364 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2365 COMMAND="show_bconds"
2369 COMMAND="show_bcond_args"
2372 --show-avail-bconds)
2373 COMMAND="show_avail_bconds"
2378 RPMOPTS="${RPMOPTS} --nodeps"
2381 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2384 Exit_error err_invalid_cmdline "$1"
2387 SPECFILE=${1%/}; shift
2388 # check if specname was passed as specname:cvstag
2389 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2390 CVSTAG="${SPECFILE##*:}"
2391 SPECFILE="${SPECFILE%%:*}"
2393 # always have SPECFILE ending with .spec extension
2394 SPECFILE=${SPECFILE%%.spec}.spec
2395 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2399 if [ "$CVSTAG" ]; then
2400 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2401 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2404 if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2405 echo >&2 "--all branches requires --depth <number>"
2406 Exit_error err_invalid_cmdline
2409 if [ -n "$DEBUG" ]; then
2414 if [ -n "$TARGET" ]; then
2417 TARGET_SWITCH="--target $TARGET" ;;
2419 TARGET_SWITCH="--target=$TARGET" ;;
2423 if [ "$SCHEDTOOL" != "no" ]; then
2424 NICE_COMMAND="$SCHEDTOOL"
2426 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2429 update_shell_title "$COMMAND"
2433 if [ -z "$SPECFILE" ]; then
2434 Exit_error err_no_spec_in_cmdl
2436 get_spec > /dev/null
2443 if [ -z "$SPECFILE" ]; then
2444 Exit_error err_no_spec_in_cmdl
2446 get_spec > /dev/null
2451 "show_avail_bconds")
2453 if [ -z "$SPECFILE" ]; then
2454 Exit_error err_no_spec_in_cmdl
2457 get_spec > /dev/null
2459 local bcond_avail=$(find_spec_bcond $SPECFILE)
2460 local opt bcond bconds
2461 for opt in $bcond_avail; do
2464 bcond=${opt#without_}
2465 bconds="$bconds $bcond"
2469 bconds="$bconds $bcond"
2472 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2480 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2482 if [ -z "$SPECFILE" ]; then
2483 Exit_error err_no_spec_in_cmdl
2486 # display SMP make flags if set
2487 smp_mflags=$(rpm -E %{?_smp_mflags})
2488 if [ "$smp_mflags" ]; then
2489 echo "builder: SMP make flags are set to $smp_mflags"
2497 if [ "$COMMAND" != "build-source" ]; then
2500 fetch_build_requires
2501 if [ "$INTEGER_RELEASE" = "yes" ]; then
2502 echo "Checking release $PACKAGE_RELEASE..."
2503 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2504 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2508 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2509 if [ -n "$TEST_TAG" ]; then
2510 local TAGVER=`make_tagver`
2511 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2512 # check also tags created in CVS
2513 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2514 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2515 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2516 || Exit_error err_tag_exists $TAGVER_CVS
2517 # - do not allow to build from HEAD when XX-branch exists
2518 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2519 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2520 TAG_BRANCH="${TREE_PREFIX}-branch"
2521 if [ -n "$DEPTH" ]; then
2522 cmd_branches="git ls-remote --heads"
2523 ref_prefix=refs/heads
2525 cmd_branches="git show-ref"
2526 ref_prefix=refs/remotes/${REMOTE_PLD}
2528 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2529 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2530 Exit_error err_branch_exists "$TAG_STATUS"
2536 if [ -n "$NOSOURCE0" ] ; then
2537 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2542 get_files $SOURCES $PATCHES
2546 NODIST="yes" get_files $SOURCES $PATCHES
2547 update_md5 $SOURCES $PATCHES
2551 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2552 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2554 remove_build_requires
2558 if [ -z "$SPECFILE" ]; then
2559 Exit_error err_no_spec_in_cmdl
2568 if [ -z "$SPECFILE" ]; then
2569 Exit_error err_no_spec_in_cmdl
2573 if [ -n "$NEW_REPO" ]; then
2576 for file in $SOURCES $PATCHES; do
2577 if [ -z $(src_md5 "$file") ]; then
2578 git add $file || Exit_error err_no_source_in_repo $file
2580 cvsignore_df `nourl $file`
2584 echo "When you are ready commit your changes and run git push origin master"
2586 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2591 if [ -z "$SPECFILE" ]; then
2592 Exit_error err_no_spec_in_cmdl
2598 if [ -n "$NOSOURCE0" ] ; then
2599 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2601 get_files $SOURCES $PATCHES
2606 if [ -z "$SPECFILE" ]; then
2607 Exit_error err_no_spec_in_cmdl
2613 if [ -n "$NOSOURCE0" ] ; then
2614 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2616 update_md5 $SOURCES $PATCHES
2622 if [ -z "$SPECFILE" ]; then
2623 Exit_error err_no_spec_in_cmdl
2627 if [ ! -d .git ]; then
2628 echo "No git reposiotory" >&2
2636 "list-sources-files" )
2639 DONT_PRINT_REVISION="yes"
2642 for SAP in $SOURCES $PATCHES; do
2643 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2646 "list-sources-urls" )
2649 DONT_PRINT_REVISION="yes"
2652 SAPS="$SOURCES $PATCHES"
2653 for SAP in $SAPS ; do
2657 "list-sources-local-paths" )
2660 DONT_PRINT_REVISION="yes"
2663 for SAP in $SOURCES $PATCHES; do
2664 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2667 "list-sources-distfiles-paths" )
2670 DONT_PRINT_REVISION="yes"
2673 for SAP in $SOURCES $PATCHES; do
2674 if [ -n "$(src_md5 "$SAP")" ]; then
2675 distfiles_path "$SAP"
2679 "list-sources-distfiles" )
2682 DONT_PRINT_REVISION="yes"
2685 for SAP in $SOURCES $PATCHES; do
2686 if [ -n "$(src_md5 "$SAP")" ]; then
2687 distfiles_url "$SAP"
2691 "list-sources-cvs" )
2694 DONT_PRINT_REVISION="yes"
2697 for SAP in $SOURCES $PATCHES; do
2698 if [ -z "$(src_md5 "$SAP")" ]; then
2699 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2713 echo "$VERSIONSTRING"
2716 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2717 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2721 # vi:syntax=sh:ts=4:sw=4:noet