]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame_incremental - builder.sh
- updated list
[packages/rpm-build-tools.git] / builder.sh
... / ...
CommitLineData
1#!/bin/ksh
2#
3# This program is free software, distributed under the terms of
4# the GNU General Public License Version 2.
5#
6# -----------
7# Exit codes:
8# 0 - succesful
9# 1 - help displayed
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
21
22# Notes (todo/bugs):
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 ]
26# TODO:
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
31# - builder --help:
32# basename: missing operand
33# Try `basename --help' for more information.
34# -- and the normal usage info --
35
36PROGRAM=${0##*/}
37APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
38VERSION="v0.35"
39VERSIONSTRING="\
40Build package utility from PLD Linux Packages repository
41$VERSION (C) 1999-2015 Free Penguins".
42
43CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
44
45# required rpm-build-macros
46RPM_MACROS_VER=1.534
47
48COMMAND="build"
49TARGET=""
50
51SPECFILE=""
52BE_VERBOSE=""
53QUIET=""
54CLEAN=""
55DEBUG=""
56NOURLS=""
57NOCVSSPEC=""
58NODIST=""
59NOINIT=""
60PREFMIRRORS=""
61UPDATE=""
62ADD5=""
63NO5=""
64ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
65
66# use rpm 4.4.6+ digest format instead of comments if non-zero
67USEDIGEST=
68
69# user agent when fetching files
70USER_AGENT="PLD/Builder($VERSION)"
71
72# It can be used i.e. in log file naming.
73# See LOGFILE example.
74DATE=`date +%Y-%m-%d_%H-%M-%S`
75
76# target arch, can also be used for log file naming
77TARGET=$(rpm -E %{_target})
78
79# Note the *single* quotes, this allows using shell variables expanded at build time
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# Example: LOGFILE='.log.$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.$TARGET.$DATE'
85LOGFILE=''
86
87# use teeboth Perl wrapper
88# temporary option to disable if broken
89USE_TEEBOTH=yes
90
91LOGDIR=""
92LOGDIROK=""
93LOGDIRFAIL=""
94LASTLOG_FILE=""
95
96CHMOD="no"
97CHMOD_MODE="0644"
98RPMOPTS=""
99RPMBUILDOPTS=""
100BCOND=""
101GROUP_BCONDS="no"
102
103# create symlinks for tools in PACKAGE_DIR, see get_spec()
104SYMLINK_TOOLS="no"
105
106PATCHES=""
107SOURCES=""
108ICONS=""
109PACKAGE_RELEASE=""
110PACKAGE_VERSION=""
111PACKAGE_NAME=""
112ASSUMED_NAME=""
113PROTOCOL="http"
114
115# use lftp by default when available
116USE_LFTP=
117lftp --version > /dev/null 2>&1 && USE_LFTP=yes
118PARALLEL_DOWNLOADS=10
119
120WGET_RETRIES=${MAX_WGET_RETRIES:-0}
121
122CVS_FORCE=""
123CVSIGNORE_DF="yes"
124CVSTAG=""
125GIT_SERVER="git://git.pld-linux.org"
126GIT_PUSH="git@git.pld-linux.org"
127PACKAGES_DIR="packages"
128HEAD_DETACHED=""
129DEPTH=""
130ALL_BRANCHES=""
131REMOTE_PLD="origin"
132NEW_REPO=""
133
134RES_FILE=""
135
136DISTFILES_SERVER="://distfiles.pld-linux.org"
137ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
138
139DEF_NICE_LEVEL=19
140SCHEDTOOL="auto"
141
142FAIL_IF_NO_SOURCES="yes"
143
144# let get_files skip over files which are present to get those damn files fetched
145SKIP_EXISTING_FILES="no"
146
147TRY_UPGRADE=""
148# should the specfile be restored if upgrade failed?
149REVERT_BROKEN_UPGRADE="yes"
150
151if rpm --specsrpm 2>/dev/null; then
152 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
153 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
154else
155 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
156 if [ -x /usr/bin/rpm-getdeps ]; then
157 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
158 else
159 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
160 fi
161fi
162
163UPDATE_POLDEK_INDEXES_OPTS=""
164
165# Here we load saved user environment used to
166# predefine options set above, or passed to builder
167# in command line.
168# This one reads global system environment settings:
169if [ -f ~/etc/builderrc ]; then
170 . ~/etc/builderrc
171fi
172# And this one cascades settings using user personal
173# builder settings.
174# Example of ~/.builderrc:
175#
176#UPDATE_POLDEK_INDEXES="yes"
177#UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
178#FETCH_BUILD_REQUIRES="yes"
179#REMOVE_BUILD_REQUIRES="force"
180#GROUP_BCONDS="yes"
181#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
182#TITLECHANGE=no
183
184SU_SUDO="sudo"
185
186if [ -n "$HOME_ETC" ]; then
187 USER_CFG="$HOME_ETC/.builderrc"
188 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
189else
190 USER_CFG=~/.builderrc
191 BUILDER_MACROS=~/.builder-rpmmacros
192fi
193
194[ -f "$USER_CFG" ] && . "$USER_CFG"
195
196if [ "$SCHEDTOOL" = "auto" ]; then
197 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
198 SCHEDTOOL="schedtool -B -e"
199 else
200 SCHEDTOOL="no"
201 fi
202fi
203
204if [ -n "$USE_PROZILLA" ]; then
205 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
206 GETURI2="$GETURI"
207 OUTFILEOPT="-O"
208elif [ -n "$USE_AXEL" ]; then
209 GETURI="axel -a $AXEL_OPTS"
210 GETURI2="$GETURI"
211 OUTFILEOPT="-o"
212elif [ -n "$USE_LFTP" ]; then
213 GETURI=download_lftp
214 GETURI2=$GETURI
215 OUTFILEOPT=""
216else
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 --help 2>&1 | grep -q -- ' --no-iri ' && WGET_OPTS="$WGET_OPTS --no-iri"
221 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
222
223 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
224 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
225 OUTFILEOPT="-O"
226fi
227
228GETLOCAL="cp -a"
229
230if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
231 RPM="rpm"
232 RPMBUILD="rpm"
233else
234 RPM="rpm"
235 RPMBUILD="rpmbuild"
236fi
237
238#
239# sanity checks
240#
241if [ -d $HOME/rpm/SOURCES ]; then
242 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
243 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
244 exit 1
245fi
246
247POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
248POLDEK_CMD="$SU_SUDO /usr/bin/poldek"
249
250# TODO: add teeboth
251# TODO: what this function does?
252run_poldek() {
253 RES_FILE=$(tempfile)
254 if [ -n "$LOGFILE" ]; then
255 LOG=`eval echo $LOGFILE`
256 if [ -n "$LASTLOG_FILE" ]; then
257 echo "LASTLOG=$LOG" > $LASTLOG_FILE
258 fi
259 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
260 # FIXME $exit_pldk undefined
261 return $exit_pldk
262 else
263 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
264 return `cat ${RES_FILE}`
265 rm -rf ${RES_FILE}
266 fi
267}
268
269#---------------------------------------------
270# functions
271
272download_lftp() {
273 local outfile=$1 url=$2 retval tmpfile
274 # TODO: use mktemp
275 tmpfile=$outfile.tmp
276 lftp -c "
277 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
278 set ssl:verify-certificate no;
279 set net:max-retries $WGET_RETRIES;
280 set http:user-agent \"$USER_AGENT\";
281 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
282 "
283
284 retval=$?
285 if [ $retval -eq 0 ]; then
286 mv -f "$tmpfile" "$outfile"
287 else
288 rm -f "$tmpfile"
289 fi
290 return $retval
291}
292
293usage() {
294 if [ -n "$DEBUG" ]; then set -xv; fi
295# NOTE:
296# to make this output parseable by bash-completion _parse_help()
297# if the line contains short and long option, it will take only the long option
298# but if you want both being completed, put the short option to separate line
299 echo "\
300Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
301[-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
302[{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
303[-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
304[-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
305[-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
306[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
307[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
308[--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
309<package>[.spec][:tag]
310
311-4 - force IPv4 when transferring files
312-6 - force IPv6 when transferring files
313-5,
314--update-md5 - update md5 comments in spec, implies -nd -ncs
315-a5,
316--add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
317--all-branches - make shallow fetch of all branches; --depth required
318-n5, --no-md5 - ignore md5 comments in spec
319-D, --debug - enable builder script debugging mode,
320-debug - produce rpm debug package (same as --opts -debug)
321-V, --version - output builder version string
322--short-version - output builder short version
323-a - try add new package to PLD repo.
324-b,
325-ba
326 - get all files from PLD repo or HTTP/FTP and build package
327 from <package>.spec,
328-bb - get all files from PLD repo or HTTP/FTP and build binary
329 only package from <package>.spec,
330-bp - execute the %prep phase of <package>.spec,
331-bc - execute the %build phase of <package>.spec,
332-bi - execute the %install phase of <package>.spec
333-bl - execute the %files phase of <package>.spec
334-bs - get all files from PLD repo or HTTP/FTP and only pack
335 them into src.rpm,
336--short-circuit - short-circuit build
337-B, --branch - add branch
338-c,
339--clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
340 may be used with building process.
341-m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
342 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
343-cf, --cvs-force - use -f when tagging
344--define '<macro> <value>'
345 - define a macro <macro> with value <value>,
346--depth <number> - make shallow fetch
347--alt_kernel <kernel>
348 - same as --define 'alt_kernel <kernel>'
349--nodeps - rpm won't check any dependences
350-g
351--get - get <package>.spec and all related files from PLD repo
352-h, --help - this message,
353-j N - set %_smp_mflags to propagate concurrent jobs
354--ftp - use FTP protocol to access distfiles server
355--http - use HTTP protocol to access distfiles server
356-l <logfile>, --logtofile=<logfile>
357 - log all to file,
358-ncs, --no-cvs-specs
359 - don't pull from PLD repo
360-nd, --no-distfiles - don't download from distfiles
361-nm, --no-mirrors - don't download from mirror, if source URL is given,
362-nu, --no-urls - don't try to download from FTP/HTTP location,
363-ns, --no-srcs - don't download Sources/Patches
364-ns0, --no-source0 - don't download Source0
365-nn, --no-net - don't download anything from the net
366-p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
367-pm, --prefer-mirrors
368 - prefer mirrors (if any) over distfiles for SOURCES
369--no-init - don't initialize builder paths (SPECS and SOURCES)
370-ske,
371--skip-existing-files
372 - skip existing files in get_files
373--opts <rpm opts> - additional options for rpm
374-q, --quiet - be quiet,
375--date yyyy-mm-dd - build package using resources from specified date,
376-r <tag>, --cvstag <ref>
377 - build package using resources from specified branch/tag,
378-A - build package using master branch as any sticky tags/branch/date being reset.
379-R, --fetch-build-requires
380 - fetch what is BuildRequired,
381-RB, --remove-build-requires
382 - remove all you fetched with -R or --fetch-build-requires
383 remember, this option requires confirmation,
384-FRB, --force-remove-build-requires
385 - remove all you fetched with -R or --fetch-build-requires
386 remember, this option works without confirmation,
387-sd, --source-distfiles
388 - list sources available from distfiles (intended for offline
389 operations; does not work when Icon field is present
390 but icon file is absent),
391-sc, --source-cvs - list sources available from PLD repo
392-sdp, --source-distfiles-paths
393 - list sources available from distfiles -
394 paths relative to distfiles directory (intended for offline
395 operations; does not work when Icon field is present
396 but icon file is absent),
397-sf, --source-files - list sources - bare filenames (intended for offline
398 operations; does not work when Icon field is present
399 but icon file is absent),
400-lsp, --source-paths
401 - list sources - filenames with full local paths (intended for
402 offline operations; does not work when Icon field is present
403 but icon file is absent),
404-su, --source-urls - list urls - urls to sources and patches
405 intended for copying urls with spec with lots of macros in urls
406-T <tag> , --tag <tag>
407 - add git tag <tag> for files,
408-Tvs, --tag-version-stable
409 - add git tags STABLE and NAME-VERSION-RELEASE for files,
410-Ts, --tag-stable
411 - add git tag STABLE for files,
412-Tv,
413--tag-version - add git tag NAME-VERSION-RELEASE for files,
414-Tp, --tag-prefix <prefix>
415 - add <prefix> to NAME-VERSION-RELEASE tags,
416-tt, --test-tag <prefix>
417 - fail if tag is already present,
418-ir, --integer-release-only
419 - allow only integer and snapshot releases
420-v, --verbose - be verbose,
421-u, --try-upgrade - check version, and try to upgrade package
422-un, --try-upgrade-with-float-version
423 - as above, but allow float version
424 php-pear-Services_Digg/
425--upgrade-version - upgrade to specified version in try-upgrade
426-U, --update - refetch sources, don't use distfiles, and update md5 comments
427-Upi, --update-poldek-indexes
428 - refresh or make poldek package index files.
429-sp <patchnumber>,
430--skip-patch <patchnumber>
431 - don't apply <patchnumber>. may be repeated.
432-np <patchnumber>,
433--nopatch <patchnumber>
434 - abort instead of applying patch <patchnumber>
435--noinit
436 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
437--show-bconds - show available conditional builds, which can be used
438 - with --with and/or --without switches.
439--show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
440 In other words, the output is parseable by scripts.
441--show-avail-bconds - show available bconds
442--with <feature>,
443--without <feature>
444 - conditional build package depending on %_with_<feature>/
445 %_without_<feature> macro switch. You may now use
446 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
447 constructions. Set GROUP_BCONDS to yes to make use of it.
448--target <platform>, --target=<platform>
449 - build for platform <platform>.
450--init-rpm-dir - initialize ~/rpm directory structure
451"
452}
453
454# create tempfile. as secure as possible
455tempfile() {
456 local prefix=builder.$PACKAGE_NAME${1:+.$1}
457 mktemp --tmpdir -t $prefix.XXXXXX || echo ${TMPDIR:-/tmp}/$prefix.$RANDOM.$$
458}
459
460tempdir() {
461 local prefix=builder.$PACKAGE_NAME${1:+.$1}
462 mktemp --tmpdir -d $prefix.XXXXXX
463}
464
465# inserts git log instead of %changelog
466# @output directory containing modified specfile
467insert_gitlog() {
468 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
469
470 # allow this being customized
471 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
472
473 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
474 # otherwise i'd use --date=iso here
475 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
476 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
477 # NOTE: changelog date is always in UTC for rpmbuild
478 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
479 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
480 local logfmt='%B%n'
481 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
482 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
483 done > $gitlog
484
485 # add link to full git logs
486 local giturl="http://git.pld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
487 if [ -n "$CVSTAG" ]; then
488 giturl="$giturl;h=$CVSTAG"
489 fi
490 local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
491 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
492 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
493 print;
494 exit
495 }' > $speclog
496
497 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
498 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
499 a%changelog
500 r $speclog
501 }
502 " > $specdir/$SPECFILE
503 rm -f $gitlog $speclog
504 echo $specdir
505}
506
507# @param string logfile
508# @param varargs... commands to execute
509teeboth() {
510 local rc
511 # use teeboth from toys/cleanbuild, if available and enabled
512 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
513 $APPDIR/teeboth "$@"
514 rc=$?
515 else
516 local efile rc logfile=$1; shift
517 if [ "$logfile" ]; then
518 efile=$(tempfile)
519 { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile
520 rc=$(< $efile)
521 rm -f $efile
522 else
523 "$@"
524 rc=$?
525 fi
526 fi
527 return $rc
528}
529
530# change dependency to specname
531# common changes:
532# - perl(Package::Name) -> perl-Package-Name
533depspecname() {
534 local DEPS
535
536 if [ $# -gt 0 ]; then
537 DEPS="$@"
538 else
539 DEPS=$(cat)
540 fi
541
542 echo "$DEPS" | tr ' ' '\n' | sed -re '
543 # perl virtual deps
544 /perl\(.*\)/{
545 s/perl\((.*)\)/perl-\1/
546 s/::/-/g
547 }
548
549 s/apache\(EAPI\)-devel/apache-devel/
550
551 s/db-devel/db5.3-devel/
552 s/libjpeg-devel/libjpeg-turbo-devel/
553 '
554}
555
556update_shell_title() {
557 [ -t 1 ] || return
558 local len=${COLUMNS:-80}
559 local msg="$(echo "$*" | cut -c-$len)"
560
561 if [ -n "$BE_VERBOSE" ]; then
562 echo >&2 "$(date +%s.%N) $*"
563 fi
564
565 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
566 local pkg
567 if [ -n "$PACKAGE_NAME" ]; then
568 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
569 else
570 pkg=${SPECFILE}
571 fi
572
573 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
574 msg=$(echo $msg | tr -d '\n\r')
575 case "$TERM" in
576 cygwin|xterm*)
577 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
578 ;;
579 screen*)
580 echo >&2 -ne "\033]0;$msg\007"
581 ;;
582 esac
583 fi
584}
585
586# set TARGET from BuildArch: from SPECFILE
587set_spec_target() {
588 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
589 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
590 if [ "$tmp" ]; then
591 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
592 TARGET="$tmp"
593 case "$RPMBUILD" in
594 "rpmbuild")
595 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
596 "rpm")
597 TARGET_SWITCH="--target=$TARGET" ;;
598 esac
599 fi
600 fi
601}
602
603# runs rpm with minimal macroset
604minirpm() {
605 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
606
607 # TODO: move these to /usr/lib/rpm/macros
608 cat > $BUILDER_MACROS <<'EOF'
609%x8664 x86_64 amd64 ia32e
610%alt_kernel %{nil}
611%_alt_kernel %{nil}
612%bootstrap_release() %{1}
613%requires_releq_kernel_up(s:n:) %{nil}
614%requires_releq_kernel_smp(s:n:) %{nil}
615%requires_releq_kernel(s:n:) %{nil}
616%requires_releq() %{nil}
617%pyrequires_eq() %{nil}
618%requires_eq() %{nil}
619%requires_eq_to() %{nil}
620%requires_ge() %{nil}
621%requires_ge_to() %{nil}
622%requires_ge() %{nil}
623%releq_kernel_up(n:) ERROR
624%releq_kernel_smp(n:) ERROR
625%releq_kernel(n:) ERROR
626%py_postclean(x:) ERROR
627%kgcc_package ERROR
628%_fontsdir ERROR
629%ruby_version ERROR
630%ruby_ver_requires_eq() %{nil}
631%ruby_mod_ver_requires_eq() %{nil}
632%__php_api_requires() %{nil}
633%php_major_version ERROR
634%php_api_version ERROR
635%requires_xorg_xserver_extension %{nil}
636%requires_xorg_xserver_xinput %{nil}
637%requires_xorg_xserver_font %{nil}
638%requires_xorg_xserver_videodrv %{nil}
639%py_ver ERROR
640%perl_vendorarch ERROR
641%perl_vendorlib ERROR
642# damn. need it here! - copied from /usr/lib/rpm/macros.build
643%tmpdir %(echo "${TMPDIR:-/tmp}")
644%patchset_source(f:b:) %(
645 base=%{-b*}%{!-b*:10000};
646 start=$(expr $base + %1);
647 end=$(expr $base + %{?2}%{!?2:%{1}});
648 # we need to call seq twice as it doesn't allow two formats
649 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
650 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
651 paste %{tmpdir}/__ps{1,2};
652 rm -f %{tmpdir}/__ps{1,2};
653) \
654%{nil}
655%add_etc_shells(p) %{p:<lua>}
656%remove_etc_shells(p) %{p:<lua>}
657%lua_add_etc_shells() %{nil}
658%lua_remove_etc_shells() %{nil}
659%required_jdk %{nil}
660%buildrequires_jdk %{nil}
661%pear_package_print_optionalpackages %{nil}
662EOF
663 if [ "$NOINIT" = "yes" ] ; then
664 cat >> $BUILDER_MACROS <<'EOF'
665%_specdir ./
666%_sourcedir ./
667EOF
668 fi
669 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
670}
671
672cache_rpm_dump() {
673 if [ -n "$DEBUG" ]; then
674 set -x
675 set -v
676 fi
677
678 if [ -x /usr/bin/rpm-specdump ]; then
679 update_shell_title "cache_rpm_dump using rpm-specdump command"
680 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
681 else
682 update_shell_title "cache_rpm_dump using rpmbuild command"
683 local rpm_dump
684 rpm_dump=`
685 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
686 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
687 case "$RPMBUILD" in
688 rpm)
689 ARGS='-bp'
690 ;;
691 rpmbuild)
692 ARGS='--nodigest --nosignature --nobuild'
693 ;;
694 esac
695 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
696 `
697 if [ $? -gt 0 ]; then
698 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
699 echo "$error" >&2
700 Exit_error err_build_fail
701 fi
702
703 # make small dump cache
704 rpm_dump_cache=`echo "$rpm_dump" | awk '
705 $2 ~ /^SOURCEURL/ {print}
706 $2 ~ /^PATCHURL/ {print}
707 $2 ~ /^nosource/ {print}
708 $2 ~ /^PACKAGE_/ {print}
709 '`
710 fi
711
712 update_shell_title "cache_rpm_dump: OK!"
713}
714
715rpm_dump() {
716 if [ -z "$rpm_dump_cache" ] ; then
717 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
718 fi
719 echo "$rpm_dump_cache"
720}
721
722get_icons() {
723 update_shell_title "get icons"
724 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
725 if [ -z "$ICONS" ]; then
726 return
727 fi
728
729 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
730}
731
732parse_spec() {
733 update_shell_title "parsing specfile"
734 if [ -n "$DEBUG" ]; then
735 set -x
736 set -v
737 fi
738
739 # icons are needed for successful spec parse
740 get_icons
741
742 cd $PACKAGE_DIR
743 cache_rpm_dump
744
745 if rpm_dump | grep -qEi ":.*nosource.*1"; then
746 FAIL_IF_NO_SOURCES="no"
747 fi
748
749 if [ "$NOSRCS" != "yes" ]; then
750 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
751 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
752 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
753 fi
754
755 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
756 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
757 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
758
759 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
760 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
761 fi
762
763 if [ -n "$BE_VERBOSE" ]; then
764 echo "- Sources : `nourl $SOURCES`"
765 if [ -n "$PATCHES" ]; then
766 echo "- Patches : `nourl $PATCHES`"
767 else
768 echo "- Patches : *no patches needed*"
769 fi
770 if [ -n "$ICONS" ]; then
771 echo "- Icon : `nourl $ICONS`"
772 else
773 echo "- Icon : *no package icon*"
774 fi
775 echo "- Name : $PACKAGE_NAME"
776 echo "- Version : $PACKAGE_VERSION"
777 echo "- Release : $PACKAGE_RELEASE"
778 fi
779
780 update_shell_title "parse_spec: OK!"
781}
782
783# aborts program abnormally
784die() {
785 local rc=${2:-1}
786 echo >&2 "$PROGRAM: ERROR: $*"
787 exit $rc
788}
789
790Exit_error() {
791 if [ -n "$DEBUG" ]; then
792 set -x
793 set -v
794 fi
795
796 cd "$__PWD"
797
798 case "$1" in
799 "err_no_spec_in_cmdl" )
800 remove_build_requires
801 echo >&2 "ERROR: spec file name not specified."
802 exit 2 ;;
803 "err_invalid_cmdline" )
804 echo >&2 "ERROR: invalid command line arg ($2)."
805 exit 2 ;;
806 "err_no_spec_in_repo" )
807 remove_build_requires
808 echo >&2 "Error: spec file not stored in PLD repo."
809 exit 3 ;;
810 "err_no_source_in_repo" )
811 remove_build_requires
812 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
813 exit 4 ;;
814 "err_cvs_add_failed" )
815 echo >&2 "Error: failed to add package to PLD repo."
816 exit 4 ;;
817 "err_build_fail" )
818 remove_build_requires
819 echo >&2 "Error: package build failed. (${2:-no more info})"
820 exit 5 ;;
821 "err_no_package_data" )
822 remove_build_requires
823 echo >&2 "Error: couldn't get out package name/version/release from spec file."
824 exit 6 ;;
825 "err_tag_exists" )
826 remove_build_requires
827 echo >&2 "Tag ${2} already exists"
828 exit 9 ;;
829 "err_fract_rel" )
830 remove_build_requires
831 echo >&2 "Release ${2} not integer and not a snapshot."
832 exit 10 ;;
833 "err_branch_exists" )
834 remove_build_requires
835 echo >&2 "Tree branch already exists (${2})."
836 exit 11 ;;
837 "err_acl_deny" )
838 remove_build_requires
839 echo >&2 "Error: conditions reject building this spec (${2})."
840 exit 12 ;;
841 "err_remote_problem" )
842 remove_build_requires
843 echo >&2 "Error: problem with remote (${2})"
844 exit 13 ;;
845 "err_no_checkut" )
846 echo >&2 "Error: cannot checkout $2"
847 exit 14 ;;
848 "err_not_implemented" )
849 remove_build_requires
850 echo >&2 "Error: functionality not yet imlemented"
851 exit 110 ;;
852 esac
853 echo >&2 "Unknown error."
854 exit 100
855}
856
857init_builder() {
858 if [ -n "$DEBUG" ]; then
859 set -x
860 set -v
861 fi
862
863 if [ "$NOINIT" != "yes" ] ; then
864 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
865
866 local macros_ver=$(rpm -E %?rpm_build_macros)
867 if [ -z "$macros_ver" ]; then
868 REPO_DIR=$TOP_DIR/packages
869 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
870 else
871 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
872 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
873 exit 1
874 fi
875 REPO_DIR=$TOP_DIR
876 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
877 fi
878 else
879 TOP_DIR=$(pwd)
880 PACKAGE_DIR=$TOP_DIR
881 REPO_DIR=$PACKAGE_DIR
882 RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
883 fi
884 export GIT_WORK_TREE=$PACKAGE_DIR
885 export GIT_DIR=$PACKAGE_DIR/.git
886
887 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
888 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
889 CVSTAG=${CVSTAG#refs/heads/}
890 if [ "$CVSTAG" != "master" ]; then
891 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
892 fi
893 else
894 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
895 HEAD_DETACHED="yes"
896 fi
897 elif [ "$CVSTAG" = "HEAD" ]; then
898 # assume -r HEAD is same as -A
899 CVSTAG="master"
900 fi
901
902 __PWD=$(pwd)
903}
904
905create_git_repo() {
906 update_shell_title "add_package"
907
908 if [ -n "$DEBUG" ]; then
909 set -x
910 set -v
911 fi
912
913 cd "$REPO_DIR"
914 SPECFILE=$(basename $SPECFILE)
915 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
916 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
917 exit 101
918 fi
919 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
920 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
921 git init
922 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git && \
923 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} \
924 || Exit_error err_remote_problem $REMOTE_PLD
925}
926
927get_spec() {
928
929 update_shell_title "get_spec"
930
931 if [ -n "$DEBUG" ]; then
932 set -x
933 set -v
934 fi
935
936 cd "$REPO_DIR"
937 SPECFILE=$(basename $SPECFILE)
938 if [ "$NOCVSSPEC" != "yes" ]; then
939 if [ -z "$DEPTH" ]; then
940 if [ -d "$PACKAGE_DIR/.git" ]; then
941 git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
942 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
943 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
944 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
945 exit 101
946 fi
947 Exit_error err_not_implemented
948 else
949 (
950 unset GIT_WORK_TREE
951 git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
952 # softfail if new package, i.e not yet added to PLD rep
953 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
954 echo "Warning: package not in CVS - assuming new package"
955 NOCVSSPEC="yes"
956 }
957 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
958 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
959 )
960 fi
961 else
962 if [ ! -d "$PACKAGE_DIR/.git" ]; then
963 if [ ! -d "$PACKAGE_DIR" ]; then
964 install -d $PACKAGE_DIR
965 fi
966 git init
967 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
968 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
969 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
970 CVSTAG=${CVSTAG:-"master"}
971 fi
972 local refs=''
973 if [ -z "$ALL_BRANCHES" ]; then
974 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
975 fi
976 git fetch $DEPTH $REMOTE_PLD $refs || {
977 echo >&2 "Error: branch $CVSTAG does not exist"
978 exit 3
979 }
980 fi
981 git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*'
982
983 cvsignore_df .gitignore
984
985 # add default log format to .gitignore if it is relative to package dir
986 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
987 # substitute known "macros" to glob
988 local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g')
989 if [ "$logfile" ]; then
990 cvsignore_df "$logfile"
991 fi
992 fi
993
994 # create symlinks for tools
995 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
996 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
997 # skip tools that don't exist in top dir
998 [ -f $a ] || continue
999 # skip tools that already exist
1000 [ -f $PACKAGE_DIR/$a ] && continue
1001 ln -s ../$a $PACKAGE_DIR
1002 cvsignore_df $a
1003 done
1004 fi
1005 fi
1006
1007 if [ -n "$CVSTAG" ]; then
1008 if git rev-parse --verify -q "$CVSTAG"; then
1009 git checkout "$CVSTAG" --
1010 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1011 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1012 fi
1013 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1014 Exit_error "err_no_checkut" "$CVSTAG"
1015 fi
1016 git merge --ff-only '@{u}'
1017 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
1018 if [ -n "$CVSDATE" ]; then
1019 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1020 fi
1021 fi
1022
1023 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
1024 Exit_error err_no_spec_in_repo
1025 fi
1026
1027 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
1028 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
1029 fi
1030 unset OPTIONS
1031 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
1032
1033 set_spec_target
1034}
1035
1036find_mirror() {
1037 cd "$REPO_DIR"
1038 local url="$1"
1039 if [ ! -f "mirrors" ] ; then
1040 ln -s ../rpm-build-tools/mirrors .
1041 fi
1042
1043 IFS="|"
1044 local origin mirror name rest ol prefix
1045 while read origin mirror name rest; do
1046 # skip comments and empty lines
1047 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
1048 continue
1049 fi
1050 ol=$(echo -n "$origin" | wc -c)
1051 prefix=$(echo -n "$url" | head -c $ol)
1052 if [ "$prefix" = "$origin" ] ; then
1053 suffix=$(echo "$url" | cut -b $((ol+1))-)
1054 echo -n "$mirror$suffix"
1055 return 0
1056 fi
1057 done < mirrors
1058 echo "$url"
1059}
1060
1061# Warning: unpredictable results if same URL used twice
1062src_no() {
1063 local file="$1"
1064 # escape some regexp characters if part of file name
1065 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
1066 cd $PACKAGE_DIR
1067 rpm_dump | \
1068 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
1069 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1070 head -n 1 | tr OURCEATH ourceath | xargs
1071}
1072
1073src_md5() {
1074 [ "$NO5" = "yes" ] && return
1075 no=$(src_no "$1")
1076 [ -z "$no" ] && return
1077 cd $PACKAGE_DIR
1078 local md5
1079
1080 # use "sources" file from package dir, like vim
1081 if [ -f sources ]; then
1082 md5=$(grep -s -v '^#' sources | \
1083 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
1084 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1085 grep -E '^[0-9a-f]{32}$')
1086
1087 if [ "$md5" ]; then
1088 if [ $(echo "$md5" | wc -l) != 1 ] ; then
1089 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
1090 fi
1091 echo "$md5" | tail -n 1
1092 return
1093 fi
1094 fi
1095
1096 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
1097 if [ -n "$source_md5" ]; then
1098 echo $source_md5
1099 else
1100 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1101 if [ -n "$source_md5" ]; then
1102 echo $source_md5
1103 else
1104 # we have empty SourceX-md5, but it is still possible
1105 # that we have NoSourceX-md5 AND NoSource: X
1106 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
1107 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1108 echo $nosource_md5
1109 fi
1110 fi
1111 fi
1112}
1113
1114distfiles_path() {
1115 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1116}
1117
1118distfiles_url() {
1119 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
1120}
1121
1122distfiles_attic_url() {
1123 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
1124}
1125
1126good_md5() {
1127 md5=$(src_md5 "$1")
1128 [ "$md5" = "" ] || \
1129 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
1130}
1131
1132good_size() {
1133 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
1134 [ -n "$size" -a "$size" -gt 0 ]
1135}
1136
1137cvsignore_df() {
1138 if [ "$CVSIGNORE_DF" != "yes" ]; then
1139 return
1140 fi
1141 cvsignore=${PACKAGE_DIR}/.gitignore
1142
1143 # add only if not yet there
1144 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
1145 echo "$1" >> $cvsignore
1146 fi
1147}
1148
1149# returns true if "$1" is ftp, http or https protocol url
1150is_url() {
1151 case "$1" in
1152 ftp://*|http://*|https://*)
1153 return 0
1154 ;;
1155 esac
1156 return 1
1157}
1158
1159update_md5() {
1160 if [ $# -eq 0 ]; then
1161 return
1162 fi
1163
1164 update_shell_title "update md5"
1165 if [ -n "$DEBUG" ]; then
1166 set -x
1167 set -v
1168 fi
1169
1170 cd "$PACKAGE_DIR"
1171
1172 # pass 1: check files to be fetched
1173 local todo
1174 local need_files
1175 for i in "$@"; do
1176 local fp=$(nourl "$i")
1177 local srcno=$(src_no "$i")
1178 if [ -n "$ADD5" ]; then
1179 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1180 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1181 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1182 else
1183 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1184 fi
1185 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1186 need_files="$need_files $i"
1187 fi
1188 done
1189
1190 # pass 1a: get needed files
1191 if [ "$need_files" ]; then
1192 get_files $need_files
1193 fi
1194
1195 # pass 2: proceed with md5 adding or updating
1196 for i in "$@"; do
1197 local fp=$(nourl "$i")
1198 local srcno=$(src_no "$i")
1199 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1200 if [ -z "$md5" ]; then
1201 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1202 fi
1203 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1204 local tag="# $srcno-md5:\t"
1205 if [[ "$md5" == *NoSource* ]]; then
1206 tag="# No$srcno-md5:\t"
1207 elif [ -n "$USEDIGEST" ]; then
1208 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1209 fi
1210 md5=$(md5sum "$fp" | cut -f1 -d' ')
1211 echo "Updating $srcno ($md5: $fp)."
1212 perl -i -ne '
1213 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1214 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1215 ' \
1216 $PACKAGE_DIR/$SPECFILE
1217 fi
1218 done
1219}
1220
1221check_md5() {
1222 local bad
1223 [ "$NO5" = "yes" ] && return
1224
1225 update_shell_title "check md5"
1226
1227 for i in "$@"; do
1228 bad=0
1229 if ! good_md5 "$i"; then
1230 echo -n "MD5 sum mismatch."
1231 bad=1
1232 fi
1233 if ! good_size "$i"; then
1234 echo -n "0 sized file."
1235 bad=1
1236 fi
1237
1238 if [ $bad -eq 1 ]; then
1239 echo " Use -U to refetch sources,"
1240 echo "or -5 to update md5 sums, if you're sure files are correct."
1241 Exit_error err_no_source_in_repo $i
1242 fi
1243 done
1244}
1245
1246get_files() {
1247 update_shell_title "get_files"
1248
1249 if [ -n "$DEBUG" ]; then
1250 set -x
1251 set -v
1252 fi
1253
1254 if [ $# -gt 0 ]; then
1255 cd "$PACKAGE_DIR"
1256
1257 local nc=0
1258 local get_files_cvs=""
1259 for i in "$@"; do
1260 nc=$((nc + 1))
1261 local cvsup=0
1262 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1263 update_shell_title "$i"
1264 local fp=`nourl "$i"`
1265 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1266 continue
1267 fi
1268
1269 FROM_DISTFILES=0
1270 local srcmd5=$(src_md5 "$i")
1271
1272 # we know if source/patch is present in cvs/distfiles
1273 # - has md5 (in distfiles)
1274 # - in cvs... ideas?
1275
1276 # CHECK: local file didn't exist or always cvs up (first) requested.
1277 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1278 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1279 echo "Warning: no URL given for $i"
1280 fi
1281 target="$fp"
1282
1283 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1284 if good_md5 "$i" && good_size "$i"; then
1285 echo "$fp having proper md5sum already exists"
1286 continue
1287 fi
1288
1289 # optionally prefer mirror over distfiles if there's mirror
1290 # TODO: build url list and then try each url from the list
1291 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1292 url="$im"
1293 else
1294 url=$(distfiles_url "$i")
1295 fi
1296
1297 url_attic=$(distfiles_attic_url "$i")
1298 FROM_DISTFILES=1
1299 # is $url local file?
1300 if [[ "$url" = [./]* ]]; then
1301 update_shell_title "${GETLOCAL%% *}: $url"
1302 ${GETLOCAL} $url $target
1303 else
1304 local uri=${url}
1305 # make shorter message for distfiles urls
1306 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1307 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1308 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1309 uri="df: $uri"
1310 fi
1311 update_shell_title "${GETURI%% *}: $uri"
1312 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1313 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1314 update_shell_title "${GETURI2%% *}: $url"
1315 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1316 fi
1317 fi
1318
1319 # is it empty file?
1320 if [ ! -s "$target" ]; then
1321 rm -f "$target"
1322 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1323 update_shell_title "${GETLOCAL%% *}: $url_attic"
1324 ${GETLOCAL} $url_attic $target
1325 else
1326 update_shell_title "${GETURI%% *}: $url_attic"
1327 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1328 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1329 update_shell_title "${GETURI2%% *}: $url_attic"
1330 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1331 fi
1332 test -s "$target" || rm -f "$target"
1333 fi
1334 fi
1335
1336 if [ -s "$target" ]; then
1337 cvsignore_df $target
1338 else
1339 rm -f "$target"
1340 FROM_DISTFILES=0
1341 fi
1342 fi
1343
1344 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1345 if [ -z "$NOMIRRORS" ]; then
1346 im=$(find_mirror "$i")
1347 else
1348 im="$i"
1349 fi
1350 update_shell_title "${GETURI%% *}: $im"
1351 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1352 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1353 update_shell_title "${GETURI2%% *}: $im"
1354 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1355 fi
1356 test -s "$target" || rm -f "$target"
1357 fi
1358
1359 if [ "$cvsup" = 1 ]; then
1360 continue
1361 fi
1362
1363 fi
1364
1365 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1366 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1367 Exit_error err_no_source_in_repo $i
1368 fi
1369
1370 # we check md5 here just only to refetch immediately
1371 if good_md5 "$i" && good_size "$i"; then
1372 :
1373 elif [ "$FROM_DISTFILES" = 1 ]; then
1374 # wrong md5 from distfiles: remove the file and try again
1375 # but only once ...
1376 echo "MD5 sum mismatch. Trying full fetch."
1377 FROM_DISTFILES=2
1378 rm -f $target
1379 update_shell_title "${GETURI%% *}: $url"
1380 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1381 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1382 update_shell_title "${GETURI2%% *}: $url"
1383 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1384 fi
1385 if [ ! -s "$target" ]; then
1386 rm -f "$target"
1387 update_shell_title "${GETURI%% *}: $url_attic"
1388 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1389 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1390 update_shell_title "${GETURI2%% *}: $url_attic"
1391 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1392 fi
1393 fi
1394 test -s "$target" || rm -f "$target"
1395 fi
1396 done
1397 SHELL_TITLE_PREFIX=""
1398
1399
1400 if [ "$CHMOD" = "yes" ]; then
1401 CHMOD_FILES=$(nourl "$@")
1402 if [ -n "$CHMOD_FILES" ]; then
1403 chmod $CHMOD_MODE $CHMOD_FILES
1404 fi
1405 fi
1406 fi
1407}
1408
1409tag_exist() {
1410# If tag exists and points to other commit exit with error
1411# If it existsts and points to HEAD return 1
1412# If it doesn't exist return 0
1413 local _tag="$1"
1414 local sha1=$(git rev-parse HEAD)
1415 echo "Searching for tag $_tag..."
1416 if [ -n "$DEPTH" ]; then
1417 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
1418 else
1419 local ref=$(git show-ref -s "refs/tags/$_tag")
1420 fi
1421 [ -z "$ref" ] && return 0
1422 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1423 return 1
1424}
1425
1426make_tagver() {
1427 if [ -n "$DEBUG" ]; then
1428 set -x
1429 set -v
1430 fi
1431
1432 # Check whether first character of PACKAGE_NAME is legal for tag name
1433 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1434 TAG_PREFIX=tag_
1435 fi
1436
1437 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1438 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
1439
1440 # Remove @kernel.version_release from TAGVER because tagging sources
1441 # could occur with different kernel-headers than kernel-headers used at build time.
1442 # besides, %{_kernel_ver_str} is not expanded.
1443
1444 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
1445 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1446
1447 TAGVER=${TAGVER%@*}
1448 echo -n "$TAGVER"
1449}
1450
1451tag_files() {
1452 if [ -n "$DEBUG" ]; then
1453 set -x
1454 set -v
1455 fi
1456
1457 echo "Version: $PACKAGE_VERSION"
1458 echo "Release: $PACKAGE_RELEASE"
1459
1460 local _tag
1461 if [ "$TAG_VERSION" = "yes" ]; then
1462 _tag=`make_tagver`
1463 fi
1464 if [ -n "$TAG" ]; then
1465 _tag="$TAG"
1466 fi
1467 echo "tag: $_tag"
1468
1469 local OPTIONS="tag $CVS_FORCE"
1470
1471 cd "$PACKAGE_DIR"
1472
1473 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1474 update_shell_title "tag sources: $_tag"
1475 git $OPTIONS $_tag || exit
1476 git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1477 else
1478 echo "Tag $_tag already exists and points to the same commit"
1479 fi
1480}
1481
1482branch_files() {
1483 TAG=$1
1484 echo "Git branch: $TAG"
1485 shift
1486
1487 if [ -n "$DEBUG" ]; then
1488 set -x
1489 set -v
1490 fi
1491
1492 local OPTIONS="branch $CVS_FORCE"
1493
1494 cd "$PACKAGE_DIR"
1495 git $OPTIONS $TAG || exit
1496}
1497
1498
1499# this function should exit early if package can't be built for this arch
1500# this avoids unneccessary BR filling.
1501check_buildarch() {
1502 local out ret
1503 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1504 ret=$?
1505 if [ $ret -ne 0 ]; then
1506 echo >&2 "$out"
1507 exit $ret
1508 fi
1509}
1510
1511# from relup.sh
1512set_release() {
1513 local specfile="$1"
1514 local rel="$2"
1515 local newrel="$3"
1516 sed -i -e "
1517 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1518 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1519 " $specfile
1520}
1521
1522set_version() {
1523 local specfile="$1"
1524 local ver="$2" subver=$ver
1525 local newver="$3" newsubver=$newver
1526
1527 # try handling subver, everything that's not numeric-dotted in version
1528 if grep -Eq '%define\s+subver' $specfile; then
1529 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1530 ver=${ver%$subver}
1531 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1532 newver=${newver%$newsubver}
1533 fi
1534 sed -i -e "
1535 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1536 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1537 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1538 " $specfile
1539}
1540
1541# try to upgrade .spec to new version
1542# if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1543#
1544# return 1: if .spec was updated
1545# return 0: no changes to .spec
1546# exit 1 in case of error
1547try_upgrade() {
1548 if [ -z "$TRY_UPGRADE" ]; then
1549 return 0
1550 fi
1551
1552 local TNOTIFY TNEWVER TOLDVER
1553 update_shell_title "build_package: try_upgrade"
1554
1555 cd "$PACKAGE_DIR"
1556
1557 if [ "$UPGRADE_VERSION" ]; then
1558 TNEWVER=$UPGRADE_VERSION
1559 echo "Updating spec file to version $TNEWVER"
1560 else
1561 if [ -n "$FLOAT_VERSION" ]; then
1562 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1563 else
1564 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1565 fi
1566
1567 # pldnotify.awk does not set exit codes, but it has match for ERROR
1568 # in output which means so.
1569 if [[ "$TNOTIFY" = *ERROR* ]]; then
1570 echo >&2 "$TNOTIFY"
1571 exit 1
1572 fi
1573
1574 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1575 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1576
1577 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1578 fi
1579
1580 if [ -z "$TNEWVER" ]; then
1581 return 0
1582 fi
1583
1584 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1585 cp -f $SPECFILE $SPECFILE.bak
1586 fi
1587 chmod +w $SPECFILE
1588 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1589 set_release $SPECFILE $PACKAGE_RELEASE 1
1590 parse_spec
1591 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1592 echo >&2 "Upgrading version failed, you need to update spec yourself"
1593 exit 1
1594 fi
1595 return 1
1596}
1597
1598build_package() {
1599 update_shell_title "build_package"
1600 if [ -n "$DEBUG" ]; then
1601 set -x
1602 set -v
1603 fi
1604
1605 cd "$PACKAGE_DIR"
1606
1607 case "$COMMAND" in
1608 build )
1609 BUILD_SWITCH="-ba" ;;
1610 build-binary )
1611 BUILD_SWITCH="-bb" ;;
1612 build-source )
1613 BUILD_SWITCH="-bs --nodeps" ;;
1614 build-prep )
1615 BUILD_SWITCH="-bp --nodeps" ;;
1616 build-build )
1617 BUILD_SWITCH="-bc" ;;
1618 build-install )
1619 BUILD_SWITCH="-bi" ;;
1620 build-list )
1621 BUILD_SWITCH="-bl" ;;
1622
1623 esac
1624
1625 update_shell_title "build_package: $COMMAND"
1626 local logfile retval
1627 if [ -n "$LOGFILE" ]; then
1628 logfile=`eval echo $LOGFILE`
1629 if [ -d "$logfile" ]; then
1630 echo "Log file $logfile is a directory."
1631 echo "Parse error in the spec?"
1632 Exit_error err_build_fail
1633 fi
1634 if [ -n "$LASTLOG_FILE" ]; then
1635 echo "LASTLOG=$logfile" > $LASTLOG_FILE
1636 fi
1637 fi
1638
1639 local specdir=$(insert_gitlog $SPECFILE)
1640 # FIXME: eval here is exactly why?
1641 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
1642 retval=$?
1643 rm -r $specdir
1644
1645 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1646 if [ "$retval" -eq "0" ]; then
1647 mv $logfile $LOGDIROK
1648 else
1649 mv $logfile $LOGDIRFAIL
1650 fi
1651 fi
1652
1653 if [ "$retval" -ne "0" ]; then
1654 if [ -n "$TRY_UPGRADE" ]; then
1655 echo "\nUpgrade package to new version failed."
1656 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1657 echo "Restoring old spec file."
1658 mv -f $SPECFILE.bak $SPECFILE
1659 fi
1660 echo ""
1661 fi
1662 Exit_error err_build_fail
1663 fi
1664 unset BUILD_SWITCH
1665}
1666
1667nourl() {
1668 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1669}
1670
1671install_required_packages() {
1672 run_poldek -vi $1
1673 return $?
1674}
1675
1676find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1677 local SPEC="$1"
1678 awk -F"\n" '
1679 /^%changelog/ { exit }
1680 /^%bcond_with/{
1681 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1682 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1683 gsub(/[ \t]+/, "_", bcond);
1684 print bcond
1685 }' $SPEC | LC_ALL=C sort -u
1686}
1687
1688process_bcondrc() {
1689 # expand bconds from ~/.bcondrc
1690 # The file structure is like gentoo's package.use:
1691 # ---
1692 # * -selinux
1693 # samba -mysql -pgsql
1694 # w32codec-installer license_agreement
1695 # php +mysqli
1696 # ---
1697 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1698 :
1699 else
1700 return
1701 fi
1702
1703 SN=${SPECFILE%%\.spec}
1704
1705 local bcondrc=$HOME/.bcondrc
1706 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1707
1708 local bcond_avail=$(find_spec_bcond $SPECFILE)
1709
1710 while read pkg flags; do
1711 # ignore comments
1712 [[ "$pkg" == \#* ]] && continue
1713
1714 # any package or current package?
1715 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1716 for flag in $flags; do
1717 local opt=${flag#[+-]}
1718
1719 # use only flags which are in this package.
1720 if [[ $bcond_avail = *${opt}* ]]; then
1721 if [[ $flag = -* ]]; then
1722 if [[ $BCOND != *--with?${opt}* ]]; then
1723 BCOND="$BCOND --without $opt"
1724 fi
1725 else
1726 if [[ $BCOND != *--without?${opt}* ]]; then
1727 BCOND="$BCOND --with $opt"
1728 fi
1729 fi
1730 fi
1731 done
1732 fi
1733 done < $bcondrc
1734 update_shell_title "parse ~/.bcondrc: DONE!"
1735}
1736
1737set_bconds_values() {
1738 update_shell_title "set bcond values"
1739
1740 AVAIL_BCONDS_WITHOUT=""
1741 AVAIL_BCONDS_WITH=""
1742
1743 if grep -Eq '^# *_with' ${SPECFILE}; then
1744 echo >&2 "ERROR: This spec has old style bconds."
1745 exit 1
1746 fi
1747
1748 if ! grep -q '^%bcond' ${SPECFILE}; then
1749 return
1750 fi
1751
1752 local bcond_avail=$(find_spec_bcond $SPECFILE)
1753 process_bcondrc "$SPECFILE"
1754
1755 update_shell_title "parse bconds"
1756
1757 local opt bcond
1758 for opt in $bcond_avail; do
1759 case "$opt" in
1760 without_*)
1761 bcond=${opt#without_}
1762 case "$BCOND" in
1763 *--without?${bcond}*)
1764 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1765 ;;
1766 *)
1767 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1768 ;;
1769 esac
1770 ;;
1771 with_*)
1772 bcond=${opt#with_}
1773 case "$BCOND" in
1774 *--with?${bcond}*)
1775 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1776 ;;
1777 *)
1778 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1779 ;;
1780 esac
1781 ;;
1782 *)
1783 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1784 exit 1
1785 ;;
1786 esac
1787 done
1788}
1789
1790run_sub_builder() {
1791 package_name="${1}"
1792 update_shell_title "run_sub_builder $package_name"
1793 #
1794 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1795 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
1796 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1797 # jakby nie bylo tego kawalka kodu.
1798 #
1799 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1800 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
1801 #
1802 #
1803 # y0shi.
1804 # kurwa. translate that ^^^^
1805
1806 parent_spec_name=''
1807
1808 # Istnieje taki spec? ${package}.spec
1809 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1810 parent_spec_name=${package}.spec
1811 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1812 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1813 else
1814 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1815 echo $provides_line
1816 done
1817 fi
1818
1819 if [ "${parent_spec_name}" != "" ]; then
1820 spawn_sub_builder $parent_spec_name
1821 fi
1822 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1823}
1824
1825# install package with poldek
1826# @return exit code from poldek
1827#
1828# this requires following sudo rules:
1829# - poldek --noask --caplookup -uG
1830poldek_install() {
1831 LANG=C $POLDEK_CMD --noask --caplookup --uniq -uG "$@"
1832}
1833
1834# install packages
1835#
1836# this requires following sudo rules:
1837# - poldek -q --update --upa
1838install_packages() {
1839 # sync poldek indexes once per invocation
1840 if [ -z "$package_indexes_updated" ]; then
1841 update_shell_title "poldek: update indexes"
1842 $POLDEK_CMD -q --update --upa
1843 package_indexes_updated=true
1844 fi
1845
1846 update_shell_title "install packages: $*"
1847 poldek_install "$@" && return
1848
1849 # retry install, install packages one by one
1850 # this is slower one
1851 local rc=0 package
1852 for package in $*; do
1853 package=$(depspecname $package)
1854 update_shell_title "install package: $package"
1855 poldek_install "$package" || rc=$?
1856 done
1857 return $rc
1858}
1859
1860uninstall_packages() {
1861 update_shell_title "uninstall packages: $*"
1862 $POLDEK_CMD --noask --nofollow -ev "$@"
1863}
1864
1865spawn_sub_builder() {
1866 package_name="${1}"
1867 update_shell_title "spawn_sub_builder $package_name"
1868
1869 sub_builder_opts=''
1870 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1871 sub_builder_opts="${sub_builder_opts} -R"
1872 fi
1873 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1874 sub_builder_opts="${sub_builder_opts} -RB"
1875 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1876 sub_builder_opts="${sub_builder_opts} -FRB"
1877 fi
1878 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1879 sub_builder_opts="${sub_builder_opts} -Upi"
1880 fi
1881
1882 cd "${PACKAGE_DIR}"
1883 ./builder ${sub_builder_opts} "$@"
1884}
1885
1886remove_build_requires() {
1887 if [ "$INSTALLED_PACKAGES" != "" ]; then
1888 case "$REMOVE_BUILD_REQUIRES" in
1889 "force")
1890 run_poldek --noask -ve $INSTALLED_PACKAGES
1891 ;;
1892 "nice")
1893 run_poldek --ask -ve $INSTALLED_PACKAGES
1894 ;;
1895 *)
1896 echo You may want to manually remove following BuildRequires fetched:
1897 echo $INSTALLED_PACKAGES
1898 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1899 ;;
1900 esac
1901 fi
1902}
1903
1904display_bconds() {
1905 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1906 if [ "$BCOND" ]; then
1907 echo ""
1908 echo "Building $SPECFILE with the following conditional flags:"
1909 echo -n "$BCOND"
1910 else
1911 echo ""
1912 echo "No conditional flags passed"
1913 fi
1914 echo ""
1915 echo "from available:"
1916 echo "--with :\t$AVAIL_BCONDS_WITH"
1917 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1918 echo ""
1919 fi
1920}
1921
1922display_branches() {
1923 echo -n "Available branches: "
1924 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
1925}
1926
1927# checks a given list of packages/files/provides against current rpmdb.
1928# outputs all dependencies which current rpmdb doesn't satisfy.
1929# input can be either STDIN or parameters
1930_rpm_prov_check() {
1931 local deps out
1932
1933 if [ $# -gt 0 ]; then
1934 deps="$@"
1935 else
1936 deps=$(cat)
1937 fi
1938
1939 out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1)
1940
1941 # packages
1942 echo "$out" | awk '/^no package provides/ { print $NF }'
1943
1944 # other deps (files)
1945 echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p'
1946}
1947
1948# checks if given package/files/provides exists in rpmdb.
1949# input can be either stdin or parameters
1950# returns packages which are present in the rpmdb
1951_rpm_cnfl_check() {
1952 local DEPS
1953
1954 if [ $# -gt 0 ]; then
1955 DEPS="$@"
1956 else
1957 DEPS=$(cat)
1958 fi
1959
1960 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1961}
1962
1963# install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1964install_build_requires_rpmdeps() {
1965 local DEPS CNFL
1966 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1967 # TODO: Conflicts list doesn't check versions
1968 CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1969 DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1970 fi
1971 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1972 CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1973 DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1974 fi
1975
1976 if [ -n "$CNFL" ]; then
1977 echo "Uninstall conflicting packages: $CNFL"
1978 uninstall_packages $CNFL
1979 fi
1980
1981 if [ -n "$DEPS" ]; then
1982 echo "Install dependencies: $DEPS"
1983 install_packages $DEPS
1984 fi
1985}
1986
1987fetch_build_requires()
1988{
1989 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1990 return
1991 fi
1992
1993 update_shell_title "fetch build requires"
1994 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1995 install_build_requires_rpmdeps
1996 return
1997 fi
1998
1999 die "need rpm-getdeps tool"
2000}
2001
2002init_repository() {
2003 local remoterepo=$1
2004 local localrepo=$2
2005
2006 if [ ! -e $localrepo ]; then
2007 git clone -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
2008 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2009 fi
2010}
2011
2012init_rpm_dir() {
2013 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2014 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2015 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2016 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2017 local TEMPLATES=template-specs
2018 local tmp
2019
2020 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
2021 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2022
2023 cd "$TOP_DIR"
2024 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2025 init_repository projects/$TEMPLATES ../$TEMPLATES
2026 for a in adapter builder fetchsrc_request compile repackage; do
2027 ln -sf ../rpm-build-tools/${a}.sh $a
2028 done
2029 for a in md5; do
2030 ln -sf ../rpm-build-tools/${a} $a
2031 done
2032 ln -sf ../rpm-build-tools/mirrors mirrors
2033 init_builder
2034}
2035
2036mr_proper() {
2037 init_builder
2038 NOCVSSPEC="yes"
2039 DONT_PRINT_REVISION="yes"
2040
2041 # remove spec and sources
2042 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
2043 rm -rf $PACKAGE_DIR/{.git,.gitignore}
2044 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
2045}
2046
2047#---------------------------------------------
2048# main()
2049
2050if [ $# = 0 ]; then
2051 usage
2052 exit 1
2053fi
2054
2055# stuff global $BUILDER_OPTS from env as args
2056if [ "$BUILDER_OPTS" ]; then
2057 set -- "$BUILDER_OPTS" "$@"
2058fi
2059
2060while [ $# -gt 0 ]; do
2061 case "${1}" in
2062 -4|-6)
2063 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2064 # unfortunately $GETURI is already formed
2065 GETURI="$GETURI $1"
2066 shift
2067 ;;
2068 -5 | --update-md5)
2069 COMMAND="update_md5"
2070 NODIST="yes"
2071 NOCVSSPEC="yes"
2072 shift ;;
2073 -a5 | --add-md5 )
2074 COMMAND="update_md5"
2075 NODIST="yes"
2076 NOCVSSPEC="yes"
2077 ADD5="yes"
2078 shift ;;
2079 -n5 | --no-md5 )
2080 NO5="yes"
2081 shift ;;
2082 -D | --debug )
2083 DEBUG="yes"; shift ;;
2084 -V | --version )
2085 COMMAND="version"; shift ;;
2086 --short-version )
2087 COMMAND="short-version"; shift ;;
2088 -a | --add_cvs)
2089 COMMAND="add_cvs";
2090 shift ;;
2091 --all-branches )
2092 ALL_BRANCHES="yes"
2093 shift ;;
2094 -b | -ba | --build )
2095 COMMAND="build"; shift ;;
2096 -bb | --build-binary )
2097 COMMAND="build-binary"; shift ;;
2098 -bc )
2099 COMMAND="build-build"; shift ;;
2100 -bi )
2101 COMMAND="build-install"; shift ;;
2102 -bl )
2103 COMMAND="build-list"; shift ;;
2104 -bp | --build-prep )
2105 COMMAND="build-prep"; shift ;;
2106 -bs | --build-source )
2107 COMMAND="build-source"; shift ;;
2108 -B | --branch )
2109 COMMAND="branch"; shift; TAG="${1}"; shift;;
2110 -c | --clean )
2111 CLEAN="--clean"; shift ;;
2112 -cf | --cvs-force )
2113 CVS_FORCE="-f"; shift;;
2114 --depth )
2115 DEPTH="--depth=$2"
2116 shift 2
2117 ;;
2118 -g | --get )
2119 COMMAND="get"; shift ;;
2120 -h | --help )
2121 COMMAND="usage"; shift ;;
2122 --ftp )
2123 PROTOCOL="ftp"; shift ;;
2124 --http )
2125 PROTOCOL="http"; shift ;;
2126 -j)
2127 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2128 shift 2
2129 ;;
2130 -j[0-9]*)
2131 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2132 shift
2133 ;;
2134 -p)
2135 PARALLEL_DOWNLOADS=$2
2136 shift 2
2137 ;;
2138 -p[0-9])
2139 PARALLEL_DOWNLOADS=${1#-p}
2140 shift
2141 ;;
2142 -l | --logtofile )
2143 shift; LOGFILE="${1}"; shift ;;
2144 -ni| --nice )
2145 shift; DEF_NICE_LEVEL=${1}; shift ;;
2146 -ske | --skip-existing-files)
2147 SKIP_EXISTING_FILES="yes"; shift ;;
2148 -m | --mr-proper )
2149 COMMAND="mr-proper"; shift ;;
2150 -ncs | --no-cvs-specs )
2151 NOCVSSPEC="yes"; shift ;;
2152 -nd | --no-distfiles )
2153 NODIST="yes"; shift ;;
2154 -nm | --no-mirrors )
2155 NOMIRRORS="yes"; shift ;;
2156 -nu | --no-urls )
2157 NOURLS="yes"; shift ;;
2158 -ns | --no-srcs )
2159 NOSRCS="yes"; shift ;;
2160 -ns0 | --no-source0 )
2161 NOSOURCE0="yes"; shift ;;
2162 -nn | --no-net )
2163 NOCVSSPEC="yes"
2164 NODIST="yes"
2165 NOMIRRORS="yes"
2166 NOURLS="yes"
2167 NOSRCS="yes"
2168 ALWAYS_CVSUP="no"
2169 shift;;
2170 -pm | --prefer-mirrors )
2171 PREFMIRRORS="yes"
2172 shift;;
2173 --noinit | --no-init )
2174 NOINIT="yes"
2175 shift;;
2176 --opts )
2177 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2178 --nopatch | -np )
2179 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2180 --skip-patch | -sp )
2181 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2182 --topdir)
2183 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2184 shift 2
2185 ;;
2186 --with | --without )
2187 case $GROUP_BCONDS in
2188 "yes")
2189 COND=${1}
2190 shift
2191 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2192 while ! `echo ${1}|grep -qE '(^-|spec)'`
2193 do
2194 BCOND="$BCOND $COND $1"
2195 shift
2196 done;;
2197 "no")
2198 if [[ "$2" = *,* ]]; then
2199 for a in $(echo "$2" | tr , ' '); do
2200 BCOND="$BCOND $1 $a"
2201 done
2202 else
2203 BCOND="$BCOND $1 $2"
2204 fi
2205 shift 2 ;;
2206 esac
2207 ;;
2208 --target )
2209 shift; TARGET="${1}"; shift ;;
2210 --target=* )
2211 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2212 -q | --quiet )
2213 QUIET="--quiet"; shift ;;
2214 --date )
2215 CVSDATE="${2}"; shift 2
2216 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2217 ;;
2218 -r | --cvstag )
2219 CVSTAG="$2"
2220 shift 2
2221 ;;
2222 -A)
2223 shift
2224 CVSTAG="master"
2225 ;;
2226 -R | --fetch-build-requires)
2227 FETCH_BUILD_REQUIRES="yes"
2228 NOT_INSTALLED_PACKAGES=
2229 shift ;;
2230 -RB | --remove-build-requires)
2231 REMOVE_BUILD_REQUIRES="nice"
2232 shift ;;
2233 -FRB | --force-remove-build-requires)
2234 REMOVE_BUILD_REQUIRES="force"
2235 shift ;;
2236 -sc | --source-cvs)
2237 COMMAND="list-sources-cvs"
2238 shift ;;
2239 -sd | --source-distfiles)
2240 COMMAND="list-sources-distfiles"
2241 shift ;;
2242 -sdp | --source-distfiles-paths)
2243 COMMAND="list-sources-distfiles-paths"
2244 shift ;;
2245 -sf | --source-files)
2246 COMMAND="list-sources-files"
2247 shift ;;
2248 -lsp | --source-paths)
2249 COMMAND="list-sources-local-paths"
2250 shift ;;
2251 -su | --source-urls)
2252 COMMAND="list-sources-urls"
2253 shift ;;
2254 -Tvs | --tag-version-stable )
2255 COMMAND="tag"
2256 TAG="STABLE"
2257 TAG_VERSION="yes"
2258 shift;;
2259 -Ts | --tag-stable )
2260 COMMAND="tag"
2261 TAG="STABLE"
2262 TAG_VERSION="no"
2263 shift;;
2264 -Tv | --tag-version )
2265 COMMAND="tag"
2266 TAG=""
2267 TAG_VERSION="yes"
2268 shift;;
2269 -Tp | --tag-prefix )
2270 TAG_PREFIX="$2"
2271 shift 2;;
2272 -tt | --test-tag )
2273 TEST_TAG="yes"
2274 shift;;
2275 -T | --tag )
2276 COMMAND="tag"
2277 shift
2278 TAG="$1"
2279 TAG_VERSION="no"
2280 shift;;
2281 -ir | --integer-release-only )
2282 INTEGER_RELEASE="yes"
2283 shift;;
2284 -U | --update )
2285 COMMAND="update_md5"
2286 UPDATE="yes"
2287 NOCVSSPEC="yes"
2288 NODIST="yes"
2289 shift ;;
2290 -Upi | --update-poldek-indexes )
2291 UPDATE_POLDEK_INDEXES="yes"
2292 shift ;;
2293 --init-rpm-dir)
2294 COMMAND="init_rpm_dir"
2295 shift ;;
2296 -u | --try-upgrade )
2297 TRY_UPGRADE="1"; shift ;;
2298 --upgrade-version )
2299 shift; UPGRADE_VERSION="$1"; shift;;
2300 -un | --try-upgrade-with-float-version )
2301 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2302 -v | --verbose )
2303 BE_VERBOSE="1"; shift ;;
2304 --define)
2305 shift
2306 MACRO="${1}"
2307 shift
2308 if echo "${MACRO}" | grep -q '\W'; then
2309 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2310 else
2311 VALUE="${1}"
2312 shift
2313 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2314 fi
2315 ;;
2316 --alt_kernel)
2317 shift
2318 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\""
2319 shift
2320 ;;
2321 --short-circuit)
2322 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2323 shift
2324 ;;
2325 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2326 COMMAND="show_bconds"
2327 shift
2328 ;;
2329 --show-bcond-args)
2330 COMMAND="show_bcond_args"
2331 shift
2332 ;;
2333 --show-avail-bconds)
2334 COMMAND="show_avail_bconds"
2335 shift
2336 ;;
2337 --nodeps)
2338 shift
2339 RPMOPTS="${RPMOPTS} --nodeps"
2340 ;;
2341 -debug)
2342 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2343 ;;
2344 -*)
2345 Exit_error err_invalid_cmdline "$1"
2346 ;;
2347 *)
2348 SPECFILE=${1%/}; shift
2349 # check if specname was passed as specname:cvstag
2350 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2351 CVSTAG="${SPECFILE##*:}"
2352 SPECFILE="${SPECFILE%%:*}"
2353 fi
2354 # always have SPECFILE ending with .spec extension
2355 SPECFILE=${SPECFILE%%.spec}.spec
2356 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2357 esac
2358done
2359
2360if [ "$CVSTAG" ]; then
2361 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2362 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2363fi
2364
2365if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2366 echo >&2 "--all branches requires --depth <number>"
2367 Exit_error err_invalid_cmdline
2368fi
2369
2370if [ -n "$DEBUG" ]; then
2371 set -x
2372 set -v
2373fi
2374
2375if [ -n "$TARGET" ]; then
2376 case "$RPMBUILD" in
2377 "rpmbuild")
2378 TARGET_SWITCH="--target $TARGET" ;;
2379 "rpm")
2380 TARGET_SWITCH="--target=$TARGET" ;;
2381 esac
2382fi
2383
2384if [ "$SCHEDTOOL" != "no" ]; then
2385 NICE_COMMAND="$SCHEDTOOL"
2386else
2387 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2388fi
2389
2390# see time(1) for output format that could be used
2391TIME_COMMAND="time -p"
2392
2393update_shell_title "$COMMAND"
2394case "$COMMAND" in
2395 "show_bconds")
2396 init_builder
2397 if [ -z "$SPECFILE" ]; then
2398 Exit_error err_no_spec_in_cmdl
2399 fi
2400 get_spec > /dev/null
2401 parse_spec
2402 set_bconds_values
2403 display_bconds
2404 ;;
2405 "show_bcond_args")
2406 init_builder
2407 if [ -z "$SPECFILE" ]; then
2408 Exit_error err_no_spec_in_cmdl
2409 fi
2410 get_spec > /dev/null
2411 parse_spec
2412 set_bconds_values
2413 echo "$BCOND"
2414 ;;
2415 "show_avail_bconds")
2416 init_builder
2417 if [ -z "$SPECFILE" ]; then
2418 Exit_error err_no_spec_in_cmdl
2419 fi
2420
2421 get_spec > /dev/null
2422 parse_spec
2423 local bcond_avail=$(find_spec_bcond $SPECFILE)
2424 local opt bcond bconds
2425 for opt in $bcond_avail; do
2426 case "$opt" in
2427 without_*)
2428 bcond=${opt#without_}
2429 bconds="$bconds $bcond"
2430 ;;
2431 with_*)
2432 bcond=${opt#with_}
2433 bconds="$bconds $bcond"
2434 ;;
2435 *)
2436 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2437 exit 1
2438 ;;
2439 esac
2440 done
2441 echo $bconds
2442
2443 ;;
2444 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2445 init_builder
2446 if [ -z "$SPECFILE" ]; then
2447 Exit_error err_no_spec_in_cmdl
2448 fi
2449
2450 # display SMP make flags if set
2451 smp_mflags=$(rpm -E %{?_smp_mflags})
2452 if [ "$smp_mflags" ]; then
2453 echo "builder: SMP make flags are set to $smp_mflags"
2454 fi
2455
2456 get_spec
2457 parse_spec
2458 set_bconds_values
2459 display_bconds
2460 display_branches
2461 if [ "$COMMAND" != "build-source" ]; then
2462 check_buildarch
2463 fi
2464 fetch_build_requires
2465 if [ "$INTEGER_RELEASE" = "yes" ]; then
2466 echo "Checking release $PACKAGE_RELEASE..."
2467 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2468 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2469 fi
2470 fi
2471
2472 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2473 if [ -n "$TEST_TAG" ]; then
2474 local TAGVER=`make_tagver`
2475 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
2476 # check also tags created in CVS
2477 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
2478 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2479 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2480 || Exit_error err_tag_exists $TAGVER_CVS
2481 # - do not allow to build from HEAD when XX-branch exists
2482 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
2483 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2484 TAG_BRANCH="${TREE_PREFIX}-branch"
2485 if [ -n "$DEPTH" ]; then
2486 cmd_branches="git ls-remote --heads"
2487 ref_prefix=refs/heads
2488 else
2489 cmd_branches="git show-ref"
2490 ref_prefix=refs/remotes/${REMOTE_PLD}
2491 fi
2492 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2493 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
2494 Exit_error err_branch_exists "$TAG_STATUS"
2495 fi
2496 fi
2497
2498 fi
2499
2500 if [ -n "$NOSOURCE0" ] ; then
2501 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2502 fi
2503 try_upgrade
2504 case $? in
2505 0)
2506 get_files $SOURCES $PATCHES
2507 check_md5 $SOURCES $PATCHES
2508 ;;
2509 *)
2510 NODIST="yes" get_files $SOURCES $PATCHES
2511 update_md5 $SOURCES $PATCHES
2512 ;;
2513 esac
2514 build_package
2515 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
2516 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
2517 fi
2518 remove_build_requires
2519 ;;
2520 "branch" )
2521 init_builder
2522 if [ -z "$SPECFILE" ]; then
2523 Exit_error err_no_spec_in_cmdl
2524 fi
2525
2526 get_spec
2527 parse_spec
2528 branch_files $TAG
2529 ;;
2530 "add_cvs" )
2531 init_builder
2532 if [ -z "$SPECFILE" ]; then
2533 Exit_error err_no_spec_in_cmdl
2534 fi
2535
2536 create_git_repo
2537 if [ -n "$NEW_REPO" ]; then
2538 parse_spec
2539 local file
2540 for file in $SOURCES $PATCHES; do
2541 if [ -z $(src_md5 "$file") ]; then
2542 git add $file || Exit_error err_no_source_in_repo $file
2543 else
2544 cvsignore_df `nourl $file`
2545 fi
2546 done
2547 git add $SPECFILE
2548 echo "When you are ready commit your changes and run git push origin master"
2549 else
2550 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
2551 fi
2552 ;;
2553 "get" )
2554 init_builder
2555 if [ -z "$SPECFILE" ]; then
2556 Exit_error err_no_spec_in_cmdl
2557 fi
2558
2559 get_spec
2560 parse_spec
2561
2562 if [ -n "$NOSOURCE0" ] ; then
2563 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2564 fi
2565 get_files $SOURCES $PATCHES
2566 check_md5 $SOURCES
2567 ;;
2568 "update_md5" )
2569 init_builder
2570 if [ -z "$SPECFILE" ]; then
2571 Exit_error err_no_spec_in_cmdl
2572 fi
2573
2574 get_spec
2575 parse_spec
2576
2577 if [ -n "$NOSOURCE0" ] ; then
2578 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2579 fi
2580 update_md5 $SOURCES $PATCHES
2581 ;;
2582 "tag" )
2583 NOURLS=1
2584 NODIST="yes"
2585 init_builder
2586 if [ -z "$SPECFILE" ]; then
2587 Exit_error err_no_spec_in_cmdl
2588 fi
2589
2590 parse_spec
2591 if [ ! -d .git ]; then
2592 echo "No git reposiotory" >&2
2593 exit 101
2594 fi
2595 tag_files
2596 ;;
2597 "mr-proper" )
2598 mr_proper
2599 ;;
2600 "list-sources-files" )
2601 init_builder
2602 NOCVSSPEC="yes"
2603 DONT_PRINT_REVISION="yes"
2604 get_spec
2605 parse_spec
2606 for SAP in $SOURCES $PATCHES; do
2607 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2608 done
2609 ;;
2610 "list-sources-urls" )
2611 init_builder >&2
2612 NOCVSSPEC="yes"
2613 DONT_PRINT_REVISION="yes"
2614 get_spec >&2
2615 parse_spec >&2
2616 SAPS="$SOURCES $PATCHES"
2617 for SAP in $SAPS; do
2618 echo $SAP
2619 done
2620 ;;
2621 "list-sources-local-paths" )
2622 init_builder
2623 NOCVSSPEC="yes"
2624 DONT_PRINT_REVISION="yes"
2625 get_spec
2626 parse_spec
2627 for SAP in $SOURCES $PATCHES; do
2628 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2629 done
2630 ;;
2631 "list-sources-distfiles-paths" )
2632 init_builder
2633 NOCVSSPEC="yes"
2634 DONT_PRINT_REVISION="yes"
2635 get_spec
2636 parse_spec
2637 for SAP in $SOURCES $PATCHES; do
2638 if [ -n "$(src_md5 "$SAP")" ]; then
2639 distfiles_path "$SAP"
2640 fi
2641 done
2642 ;;
2643 "list-sources-distfiles" )
2644 init_builder
2645 NOCVSSPEC="yes"
2646 DONT_PRINT_REVISION="yes"
2647 get_spec
2648 parse_spec
2649 for SAP in $SOURCES $PATCHES; do
2650 if [ -n "$(src_md5 "$SAP")" ]; then
2651 distfiles_url "$SAP"
2652 fi
2653 done
2654 ;;
2655 "list-sources-cvs" )
2656 init_builder
2657# NOCVSSPEC="yes"
2658 DONT_PRINT_REVISION="yes"
2659 get_spec
2660 parse_spec
2661 for SAP in $SOURCES $PATCHES; do
2662 if [ -z "$(src_md5 "$SAP")" ]; then
2663 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2664 fi
2665 done
2666 ;;
2667 "init_rpm_dir")
2668 init_rpm_dir
2669 ;;
2670 "usage" )
2671 usage
2672 ;;
2673 "short-version" )
2674 echo "$VERSION"
2675 ;;
2676 "version" )
2677 echo "$VERSIONSTRING"
2678 ;;
2679esac
2680if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2681 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2682fi
2683cd "$__PWD"
2684
2685# vi:syntax=sh:ts=4:sw=4:noet
This page took 0.091317 seconds and 4 git commands to generate.