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