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