SOURCES: builder - copied v0.17 from r1.467

glen glen at pld-linux.org
Fri Dec 1 12:08:02 CET 2006


Author: glen                         Date: Fri Dec  1 11:08:02 2006 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- copied v0.17 from r1.467

---- Files affected:
SOURCES:
   builder (1.14 -> 1.15) 

---- Diffs:

================================================================
Index: SOURCES/builder
diff -u SOURCES/builder:1.14 SOURCES/builder:1.15
--- SOURCES/builder:1.14	Mon May 22 22:51:26 2006
+++ SOURCES/builder	Fri Dec  1 12:07:57 2006
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/ksh
 # -----------
 # $Id$
 # Exit codes:
@@ -22,7 +22,7 @@
 
 VERSION="\
 Build package utility from PLD Linux CVS repository
-v0.16 (C) 1999-2006 Free Penguins".
+v0.17 (C) 1999-2006 Free Penguins".
 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
 
 COMMAND="build"
@@ -39,7 +39,6 @@
 NODIST=""
 NOINIT=""
 UPDATE=""
-UPDATE5=""
 ADD5=""
 NO5=""
 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
@@ -79,6 +78,7 @@
 
 CVSTAG=""
 RES_FILE=""
+CVS_FORCE=""
 
 CVS_SERVER="cvs.pld-linux.org"
 DISTFILES_SERVER="://distfiles.pld-linux.org"
@@ -92,6 +92,10 @@
 # let get_files skip over files which are present to get those damn files fetched
 SKIP_EXISTING_FILES="no"
 
+TRY_UPGRADE=""
+# should the specfile be restored if upgrade failed?
+REVERT_BROKEN_UPGRADE="yes"
+
 if [ -x /usr/bin/rpm-getdeps ]; then
 	FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
 else
@@ -189,13 +193,11 @@
 	if [ -n "$DEBUG" ]; then set -xv; fi
 	echo "\
 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
-
 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
-[{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
-[-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
-[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
-[-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
-[-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
+[{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
+[-g|--get] [-h|--help] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
+[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
+[-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag]
@@ -220,6 +222,7 @@
 -B, --branch        - add branch
 -c, --clean         - clean all temporarily created files (in BUILD, SOURCES,
                       SPECS and \$RPM_BUILD_ROOT),
+-cf, --cvs-force	- use -F when tagging (useful when moving branches)
 -d <cvsroot>, --cvsroot <cvsroot>
                     - setup \$CVSROOT,
 --define <macro> <value>
@@ -250,6 +253,7 @@
 --date yyyy-mm-dd   - build package using resources from specified CVS date,
 -r <cvstag>, --cvstag <cvstag>
                     - build package using resources from specified CVS tag,
+-A                  - build package using CVS resources as any sticky tags/date/kopts being reset.
 -R, --fetch-build-requires
                     - fetch what is BuildRequired,
 -RB, --remove-build-requires
@@ -277,12 +281,8 @@
                     - add cvs tag <cvstag> for files,
 -Tvs, --tag-version-stable
                     - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
--Tvn, --tag-version-nest
-                    - add cvs tags NEST and NAME-VERSION-RELEASE for files,
 -Ts, --tag-stable
                     - add cvs tag STABLE for files,
--Tn, --tag-nest
-                    - add cvs tag NEST for files,
 -Tv, --tag-version
                     - add cvs tag NAME-VERSION-RELEASE for files,
 -Tp, --tag-prefix <prefix>
@@ -302,6 +302,9 @@
                     - don't apply <patchnumber>
 --show-bconds       - show available conditional builds, which can be used
                     - with --with and/or --without switches.
+--show-bcond-args   - show active bconds, from ~/.bcondrc. this is used by
+                      ./repackage.sh script. in other words, the output is
+                      parseable by scripts.
 --with/--without <feature>
                     - conditional build package depending on %_with_<feature>/
                       %_without_<feature> macro switch.  You may now use
@@ -360,10 +363,10 @@
 }
 
 cache_rpm_dump () {
-	 if [ -n "$DEBUG" ]; then
-		  set -x;
-		  set -v;
-	 fi
+	if [ -n "$DEBUG" ]; then
+		set -x
+		set -v
+	fi
 
 	update_shell_title "cache_rpm_dump"
 	local rpm_dump
@@ -396,6 +399,8 @@
 %php_major_version ERROR
 %php_api_version ERROR
 %py_ver ERROR
+%perl_vendorarch ERROR
+%perl_vendorlib ERROR
 EOF
 	case "$RPMBUILD" in
 	rpm)
@@ -416,7 +421,7 @@
 	if [ $? -gt 0 ]; then
 		error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
 		echo "$error" >&2
-		Exit_error err_build_fail;
+		Exit_error err_build_fail
 	fi
 
 	# make small dump cache
@@ -432,7 +437,7 @@
 
 rpm_dump () {
 	if [ -z "$rpm_dump_cache" ] ; then
-		echo "internal error: cache_rpm_dump not called!" 1>&2
+		echo "internal error: cache_rpm_dump not called! (missing %prep?)" 1>&2
 	fi
 	echo "$rpm_dump_cache"
 }
@@ -445,19 +450,19 @@
 		return
 	fi
 
-	rpm_dump_cache="kalasaba" NODIST="yes" UPDATE5= get_files $ICONS
+	rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
 }
 
 parse_spec()
 {
 	update_shell_title "parsing specfile"
 	if [ -n "$DEBUG" ]; then
-		set -x;
-		set -v;
+		set -x
+		set -v
 	fi
 
 	# icons are needed for successful spec parse
-	get_icons;
+	get_icons
 
 	cd $SPECS_DIR
 	cache_rpm_dump
@@ -499,8 +504,8 @@
 Exit_error()
 {
 	if [ -n "$DEBUG" ]; then
-		set -x;
-		set -v;
+		set -x
+		set -v
 	fi
 
 	cd "$__PWD"
@@ -508,19 +513,19 @@
 	case "$1" in
 		"err_no_spec_in_cmdl" )
 			remove_build_requires
-			echo "ERROR: spec file name not specified.";
+			echo "ERROR: spec file name not specified."
 			exit 2 ;;
 		"err_no_spec_in_repo" )
 			remove_build_requires
-			echo "Error: spec file not stored in CVS repo.";
+			echo "Error: spec file not stored in CVS repo."
 			exit 3 ;;
 		"err_no_source_in_repo" )
 			remove_build_requires
-			echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
+			echo "Error: some source, patch or icon files not stored in CVS repo. ($2)"
 			exit 4 ;;
 		"err_build_fail" )
 			remove_build_requires
-			echo "Error: package build failed. (${2:-no more info})";
+			echo "Error: package build failed. (${2:-no more info})"
 			exit 5 ;;
 		"err_no_package_data" )
 			remove_build_requires
@@ -528,27 +533,27 @@
 			exit 6 ;;
 		"err_tag_exists" )
 			remove_build_requires
-			echo "Tag ${2} already exists (spec release: ${3}).";
+			echo "Tag ${2} already exists (spec release: ${3})."
 			exit 9 ;;
 		"err_fract_rel" )
 			remove_build_requires
-			echo "Release ${2} not integer and not a snapshot.";
+			echo "Release ${2} not integer and not a snapshot."
 			exit 10 ;;
 		"err_branch_exists" )
 			remove_build_requires
-			echo "Tree branch already exists (${2}).";
+			echo "Tree branch already exists (${2})."
 			exit 11 ;;
 
 	esac
-   echo "Unknown error."
-   exit 100
+	echo "Unknown error."
+	exit 100
 }
 
 init_builder()
 {
 	if [ -n "$DEBUG" ]; then
-		set -x;
-		set -v;
+		set -x
+		set -v
 	fi
 
 	if [ "$NOINIT" != "yes" ] ; then
@@ -568,13 +573,13 @@
 	update_shell_title "get_spec"
 
 	if [ -n "$DEBUG" ]; then
-		set -x;
-		set -v;
+		set -x
+		set -v
 	fi
 
 	cd "$SPECS_DIR"
 	if [ ! -f "$SPECFILE" ]; then
-		SPECFILE="`basename $SPECFILE .spec`.spec";
+		SPECFILE="`basename $SPECFILE .spec`.spec"
 	fi
 	if [ "$NOCVSSPEC" != "yes" ]; then
 
@@ -587,7 +592,7 @@
 	fi
 
 	if [ ! -f "$SPECFILE" ]; then
-		Exit_error err_no_spec_in_repo;
+		Exit_error err_no_spec_in_repo
 	fi
 
 	if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
@@ -625,6 +630,7 @@
 	echo "$url"
 }
 
+# Warning: unpredictable results if same URL used twice
 src_no ()
 {
 	cd $SPECS_DIR
@@ -634,38 +640,44 @@
 	head -n 1 | xargs
 }
 
-src_md5 ()
+src_md5()
 {
-	[ X"$NO5" = X"yes" ] && return
+	[ "$NO5" = "yes" ] && return
 	no=$(src_no "$1")
 	[ -z "$no" ] && return
 	cd $SPECS_DIR
-	spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
-	if [ -z "$spec_rev" ]; then
-		spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
-	fi
-	spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
-	md5=$(grep -s -v '^#' additional-md5sums | \
-	grep -E "[ 	]$(basename "$1")[ 	]+${spec}([ 	,]|\$)" | \
-	sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
-	grep -E '^[0-9a-f]{32}$')
-	if [ X"$md5" = X"" ] ; then
-		source_md5=`grep -i "#[ 	]*Source$no-md5[ 	]*:" $SPECFILE | sed -e 's/.*://'`
-		if [ ! -z "$source_md5" ] ; then
-			echo $source_md5;
-		else
-			# we have empty SourceX-md5, but it is still possible
-			# that we have NoSourceX-md5 AND NoSource: X
-			nosource_md5=`grep -i "#[	 ]*NoSource$no-md5[	 ]*:" $SPECFILE | sed -e 's/.*://'`
-			if [ ! -z "$nosource_md5" -a ! X"`grep -i "^NoSource:[	 ]*$no$" $SPECFILE`" = X"" ] ; then
-				echo $nosource_md5;
-			fi;
-		fi;
+	local md5
+
+	if [ -f additional-md5sums ]; then
+		local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
+		if [ -z "$spec_rev" ]; then
+			spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
+		fi
+		local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
+		md5=$(grep -s -v '^#' additional-md5sums | \
+		grep -E "[ 	]$(basename "$1")[ 	]+${spec}([ 	,]|\$)" | \
+		sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
+		grep -E '^[0-9a-f]{32}$')
+
+		if [ "$md5" ]; then
+			if [ $(echo "$md5" | wc -l) != 1 ] ; then
+				echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
+			fi
+			echo "$md5" | tail -n 1
+			return
+		fi
+	fi
+
+	source_md5=`grep -i "#[ 	]*Source$no-md5[ 	]*:" $SPECFILE | sed -e 's/.*://'`
+	if [ -n "$source_md5" ]; then
+		echo $source_md5
 	else
-		if [ $(echo "$md5" | wc -l) != 1 ] ; then
-			echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
+		# we have empty SourceX-md5, but it is still possible
+		# that we have NoSourceX-md5 AND NoSource: X
+		nosource_md5=`grep -i "#[	 ]*NoSource$no-md5[	 ]*:" $SPECFILE | sed -e 's/.*://'`
+		if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[	 ]*$no$" $SPECFILE`" ] ; then
+			echo $nosource_md5
 		fi
-		echo "$md5" | tail -n 1
 	fi
 }
 
@@ -752,13 +764,96 @@
 	return $result
 }
 
+# returns true if "$1" is ftp, http or https protocol url
+is_url()
+{
+	case "$1" in
+	ftp://*|http://*|https://*)
+		return 0
+	;;
+	esac
+	return 1
+}
+
+update_md5()
+{
+	if [ $# -eq 0 ]; then
+		return
+	fi
+
+	update_shell_title "update md5"
+	if [ -n "$DEBUG" ]; then
+		set -x
+		set -v
+	fi
+
+	cd "$SOURCE_DIR"
+
+	# pass 1: check files to be fetched
+	local todo
+	local need_files
+	for i in "$@"; do
+		local fp=$(nourl "$i")
+		local srcno=$(src_no "$i")
+		if [ -n "$ADD5" ]; then
+			[ "$fp" = "$i" ] && continue # FIXME what is this check doing?
+			grep -qiE '^#[ 	]*Source'$srcno'-md5[ 	]*:' $SPECS_DIR/$SPECFILE && continue
+		else
+			grep -qiE '^#[ 	]*Source'$srcno'-md5[ 	]*:' $SPECS_DIR/$SPECFILE || continue
+		fi
+		if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
+			need_files="$need_files $i"
+		fi
+	done
+
+	# pass 1a: get needed files
+	if [ "$need_files" ]; then
+		get_files $need_files
+	fi
+
+	# pass 2: proceed with md5 adding or updating
+	for i in "$@"; do
+		local fp=$(nourl "$i")
+		local srcno=$(src_no "$i")
+		local md5=$(grep -iE '^#[ 	]*(No)?Source'$srcno'-md5[ 	]*:' $SPECS_DIR/$SPECFILE )
+		if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
+			local tag="Source$srcno-md5"
+			if [[ "$md5" == *NoSource* ]]; then
+				tag="NoSource$srcno-md5"
+			fi
+			md5=$(md5sum "$fp" | cut -f1 -d' ')
+			echo "Updating $tag ($md5: $fp)."
+			perl -i -ne '
+				print unless /^\s*#\s*(No)?Source'$srcno'-md5\s*:/i;
+				print "# '$tag':\t'$md5'\n" if /^Source'$srcno'\s*:\s+/;
+			' \
+			$SPECS_DIR/$SPECFILE
+		fi
+	done
+}
+
+check_md5()
+{
+	update_shell_title "check md5"
+
+	for i in "$@"; do
+		if good_md5 "$i" && good_size "$i"; then
+			continue
+		fi
+
+		echo "MD5 sum mismatch or 0 size.  Use -U to refetch sources,"
+		echo "or -5 to update md5 sums, if you're sure files are correct."
+		Exit_error err_no_source_in_repo $i
+	done
+}
+
 get_files()
 {
 	update_shell_title "get_files"
 
 	if [ -n "$DEBUG" ]; then
-		set -x;
-		set -v;
+		set -x
+		set -v
 	fi
 
 	if [ $# -gt 0 ]; then
@@ -777,33 +872,34 @@
 			SHELL_TITLE_PREFIX="get_files[$nc/$#]"
 			update_shell_title "$i"
 			local fp=`nourl "$i"`
-			if [ -f "$fp" ] && [ "$SKIP_EXISTING_FILES" = "yes" ]; then
+			if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
 				continue
 			fi
-			if [ -n "$UPDATE5" ]; then
-				if [ -n "$ADD5" ]; then
-					[ "$fp" = "$i" ] && continue
-					grep -qiE '^#[ 	]*Source'$(src_no $i)'-md5[ 	]*:' $SPECS_DIR/$SPECFILE && continue
-				else
-					grep -qiE '^#[ 	]*Source'$(src_no $i)'-md5[ 	]*:' $SPECS_DIR/$SPECFILE || continue
-				fi
-			fi
+
 			FROM_DISTFILES=0
+			local srcmd5=$(src_md5 "$i")
+
+			# we know if source/patch is present in cvs/distfiles
+			# - has md5 (in distfiles)
+			# - in cvs... ideas?
+
+			# CHECK: local file didn't exist or always cvs up (first) requested.
 			if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
 				if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
 					echo "Warning: no URL given for $i"
 				fi
 
-				if [ -z "$NODIST" ] && [ -n "$(src_md5 "$i")" ]; then
+				if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
 					if good_md5 "$i" && good_size "$i"; then
-						echo "$(nourl "$i") having proper md5sum already exists"
+						echo "$fp having proper md5sum already exists"
 						continue
 					fi
 					target="$fp"
 					url=$(distfiles_url "$i")
 					url_attic=$(distfiles_attic_url "$i")
 					FROM_DISTFILES=1
-					if [ "`echo $url | grep -E '^(\.|/)'`" ]; then
+					# is $url local file?
+					if [[ "$url" = [./]* ]]; then
 						update_shell_title "${GETLOCAL%% *}: $url"
 						${GETLOCAL} $url $target
 					else
@@ -817,7 +913,9 @@
 							${GETURI2} ${OUTFILEOPT} "$target" "$url"
 						fi
 					fi
-					if ! test -s "$target"; then
+
+					# is it empty file?
+					if [ ! -s "$target" ]; then
 						rm -f "$target"
 						if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
 							update_shell_title "${GETLOCAL%% *}: $url_attic"
@@ -834,13 +932,14 @@
 							fi
 						fi
 					fi
-					if test -s "$target"; then
+
+					if [ -s "$target" ]; then
 						cvsignore_df $target
 					else
 						rm -f "$target"
 						FROM_DISTFILES=0
 					fi
-				elif [ "$NOCVS" != "yes" -a -z "$(src_md5 "$i")" ]; then
+				elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
 					if [ $# -gt 1 ]; then
 						get_files_cvs="$get_files_cvs $fp"
 						update_shell_title "$fp (will cvs up later)"
@@ -869,24 +968,13 @@
 				fi
 
 			fi
-			srcno=$(src_no $i)
+
+			# the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
 			if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
-				Exit_error err_no_source_in_repo $i;
-			elif [ -n "$UPDATE5" ] && \
-				( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
-				[ -z "$(grep -E -i '^NoSource[ 	]*:[ 	]*'$i'([ 	]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
-				grep -q -i -E '^#[ 	]*source'$(src_no $i)'-md5[ 	]*:' $SPECS_DIR/$SPECFILE )
-			then
-				echo "Updating source-$srcno md5."
-				md5=$(md5sum "$fp" | cut -f1 -d' ')
-				perl -i -ne '
-				print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
-				print "# Source'$srcno'-md5:\t'$md5'\n"
-				if /^Source'$srcno'\s*:\s+/;
-				' \
-				$SPECS_DIR/$SPECFILE
+				Exit_error err_no_source_in_repo $i
 			fi
 
+			# we check md5 here just only to refetch immediately
 			if good_md5 "$i" && good_size "$i"; then
 				:
 			elif [ "$FROM_DISTFILES" = 1 ]; then
@@ -901,7 +989,7 @@
 					update_shell_title "${GETURI2%% *}: $url"
 					${GETURI2} ${OUTFILEOPT} "$target" "$url"
 				fi
-				if ! test -s "$target"; then
+				if [ ! -s "$target" ]; then
 					rm -f "$target"
 					update_shell_title "${GETURI%% *}: $url_attic"
 					${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
@@ -912,14 +1000,6 @@
 				fi
 				test -s "$target" || rm -f "$target"
 			fi
-
-			if good_md5 "$i" && good_size "$i" ; then
-				:
-			else
-				echo "MD5 sum mismatch or 0 size.  Use -U to refetch sources,"
-				echo "or -5 to update md5 sums, if you're sure files are correct."
-				Exit_error err_no_source_in_repo $i
-			fi
 		done
 		SHELL_TITLE_PREFIX=""
 
@@ -938,8 +1018,8 @@
 
 make_tagver() {
 	if [ -n "$DEBUG" ]; then
-		set -x;
-		set -v;
+		set -x
+		set -v
 	fi
 
 	# Check whether first character of PACKAGE_NAME is legal for tag name
@@ -958,54 +1038,59 @@
 	TAG_FILES="$@"
 
 	if [ -n "$DEBUG" ]; then
-		set -x;
-		set -v;
+		set -x
+		set -v
 	fi
 
-	if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
-		echo "Version: $PACKAGE_VERSION"
-		echo "Release: $PACKAGE_RELEASE"
+	echo "Version: $PACKAGE_VERSION"
<<Diff was trimmed, longer than 597 lines>>

---- CVS-web:
    http://cvs.pld-linux.org/SOURCES/builder?r1=1.14&r2=1.15&f=u



More information about the pld-cvs-commit mailing list