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