[pacman-dev] makepkg with gettext support

Dan McGee dpmcgee at gmail.com
Tue Mar 27 22:51:16 EDT 2007


On 3/27/07, Giovanni Scafora <linuxmania at gmail.com> wrote:
> Hi guys,
>
> I send my initial work on makepkg with gettext support.
> I guess that it's not still perfect, but I would appreciate a lot the
> contribution of all the translators and the pacman developers.
> All the suggestions are appreciated.

I've inlined it so I can comment on it. Comments are near whatever I
have a comment on. :)

+. gettext.sh
+
+TEXTDOMAIN=makepkg
...

Can you smash this stuff into one block with a nice comment like "#
gettext initialization"? And it might be more clear to use 'source'
instead of '.' for consistency with the rest of makepkg.

@@ -98,6 +105,7 @@ error() {
 	if [ ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
 		echo -e "\033[1;31m==> ERROR:\033[1;0m \033[1;1m$1\033[1;0m" >&2
 	else
+		error=$1
 		echo "==> ERROR: $1" >&2

What is this for? It is the only function that got changed, is it debug code?

@@ -177,6 +185,9 @@ in_array() {
 }

 checkdeps() {
+	local missdep=""
+	local deplist=""
+

I think this is old code, along with a few of the things below. Try to
sync with the latest in CVS or GIT.

@@ -193,31 +204,24 @@ checkdeps() {
 handledeps() {
 	local missingdeps=0
 	local deplist="$*"
-	local depstrip=""
-	local striplist=""
 	local haveperm=0
 	if [ \( "$EUID" = "0" -a "$INFAKEROOT" != "1" \) -o "$SUDO" = 1 ]; then
 		haveperm=1
 	fi

-	for dep in $deplist; do
-		depstrip=$(echo $dep | sed 's|=.*$||' | sed 's|>.*$||' | sed 's|<.*$||')
-		striplist="$striplist $depstrip"
-	done
-
 	if [ "$deplist" != "" -a $haveperm -eq 1 ]; then
 		if [ "$DEP_BIN" = "1" -a "$SUDO" = "1" ]; then
 			# install missing deps from binary packages (using pacman -S and sudo)
-			msg "Installing missing dependencies..."
+			msg "$(gettext "Installing missing dependencies...")"
 			if [ "$INFAKEROOT" = "1" ]; then
 				# kinda hacky, but we need to make pacman think that we're NOT
 				# in fakeroot so it will go ahead and install the dependencies.
 				FAKEROOTKEY2=$FAKEROOTKEY
 				unset FAKEROOTKEY
 			fi
-			sudo pacman $PACMAN_OPTS -S $striplist
+			sudo pacman $PACMAN_OPTS -S $deplist
 			if [ $? -eq 1 ]; then
-				error "Pacman failed to install missing dependencies."
+				error "$(gettext "Failed to install missing dependencies.")"
 				exit 1
 			fi
 			if [ "$INFAKEROOT" = "1" ]; then
@@ -226,25 +230,25 @@ handledeps() {
 			fi
 		elif [ "$DEP_BIN" = "1" ]; then
 			# install missing deps from binary packages (using pacman -S)
-			msg "Installing missing dependencies..."
-			pacman $PACMAN_OPTS -S $striplist
+			msg "$(gettext "Installing missing dependencies...")"
+			pacman $PACMAN_OPTS -S $deplist
 			if [ $? -eq 1 ]; then
-				error "Pacman failed to install missing dependencies."
+				error "$(gettext "Failed to install missing dependencies.")"
 				exit 1
 			fi
 		elif [ "$DEP_SRC" = "1" ]; then
 			# install missing deps by building them from source.
 			# we look for each package name in $SRCROOT and build it.
 			if [ "$SRCROOT" = "" ]; then
-				error "Source root cannot be found - please make sure it is
specified in /etc/makepkg.conf"
+				error "$(gettext "Source root cannot be found - please make sure
it is specified in /etc/makepkg.conf")"
 				exit 1
 			fi
 			# TODO: handle version comparators (eg, glibc>=2.2.5)
-			msg "Building missing dependencies..."
-			for dep in $striplist; do
+			msg "$(gettext "Building missing dependencies...")"
+			for dep in $deplist; do
 				candidates=$(find $SRCROOT -type d -name "$dep")
 				if [ "$candidates" = "" ]; then
-					error "Could not find \"$dep\" under $SRCROOT"
+					error "$(eval_gettext "Could not find \"\$dep\" under \$SRCROOT")"
 					exit 1
 				fi
 				success=0
@@ -252,9 +256,9 @@ handledeps() {
 					if [ -f "$pkgdir/$BUILDSCRIPT" ]; then
 						cd "$pkgdir"
 						if [ "$RMDEPS" = "1" ]; then
-							PKGDEST="$PKGDEST" makepkg -i -c -b -r
+							makepkg -i -c -b -r -w $PKGDEST
 						else
-							PKGDEST="$PKGDEST" makepkg -i -c -b
+							makepkg -i -c -b -w $PKGDEST
 						fi
 						if [ $? -eq 0 ]; then
 							success=1
@@ -263,7 +267,7 @@ handledeps() {
 					fi
 				done
 				if [ "$success" = "0" ]; then
-					error "Failed to build \"$dep\""
+					error "$(eval_gettext "Failed to build \"\$dep\"")"
 					exit 1
 				fi
 			done

@@ -290,27 +294,21 @@ handledeps() {
 }

 resolvedeps() {
-	deplist=""
-	newdeplist=""
-
 	deplist=$(checkdeps $*)
 	if [ -n "${deplist}" ]; then
 		handledeps $deplist
 		if [ $? -eq 0 ]; then
 			# check deps again to make sure they were resolved
-			newdeplist=$(checkdeps $*)
-			if [ -n "${newdeplist}" ]; then
-				error "Failed to install all missing dependencies."
+			deplist=$(checkdeps ${depends[@]})
+			if [ -n "${deplist}" ]; then
+				error "$(gettext "Failed to install missing dependencies.")"
 			fi
-		else
-			newdeplist="$deplist"
 		fi
 	fi

-	# if new dep list is not empty, print the list
-	if [ -n "${newdeplist}" ]; then
-		msg "Missing Dependencies:"
-		for dep in ${newdeplist}; do
+	if [ -n "${deplist}" ]; then
+		msg "$(gettext "Missing Dependencies:")"
+		for dep in ${deplist}; do
 			msg2 "${dep}"
 		done
 		return 1
@@ -321,36 +319,26 @@ resolvedeps() {

 # fix flyspray bug #5923
 removedeps() {
-	# runtimedeps and buildtimedeps are set when resolving deps
-	local deplist="$runtimedeps $buildtimedeps"
-	local depstrip=""
-	local striplist=""
-
-	for dep in $deplist; do
-		depstrip=$(echo $dep | sed 's|=.*$||' | sed 's|>.*$||' | sed 's|<.*$||')
-		striplist="$striplist $depstrip"
-	done
-
-	if [ "$RMDEPS" = "1" -a "$SUDO" = "1" -a -n "$deplist" ]; then
-		msg "Removing installed dependencies..."
+	if [ "$RMDEPS" = "1" -a "$SUDO" = "1" -a \( ! -z "$deplist" -o ! -z
"$makedeplist" \) ]; then
+		msg "$(gettext "Removing installed dependencies...")"
 		if [ "$INFAKEROOT" = "1" ]; then
 			export FAKEROOTKEY2=$FAKEROOTKEY
 			unset FAKEROOTKEY
 		fi
-		sudo pacman $PACMAN_OPTS -Rs $striplist
+		sudo pacman $PACMAN_OPTS -Rs $makedeplist $deplist
 		if [ "$INFAKEROOT" = "1" ]; then
 			export FAKEROOTKEY=$FAKEROOTKEY2
 			unset FAKEROOTKEY2
 		fi
-	elif [ "$RMDEPS" = "1" -a "$EUID" = "0" -a "$INFAKEROOT" != "1" -a
-n "$deplist" ]; then
-		msg "Removing installed dependencies..."
-		pacman $PACMAN_OPTS -Rs $striplist
+	elif [ "$RMDEPS" = "1" -a "$EUID" = "0" -a "$INFAKEROOT" != "1" -a
\( ! -z "$deplist" -o ! -z "$makedeplist" \) ]; then
+		msg "$(gettext "Removing installed dependencies...")"
+		pacman $PACMAN_OPTS -Rs $makedeplist $deplist
 	fi
 }

@@ -500,36 +489,36 @@ done

 # check for sudo
 if [ "$SUDO" = "1" -a ! "$(type -p sudo)" ]; then
-	error "Cannot find the sudo binary! Is sudo installed?"
+	error "$(gettext "Cannot find the sudo binary! Is sudo installed?")"
 	exit 1
 fi

 if [ "$CLEANCACHE" = "1" ]; then
 	#fix flyspray feature request #5223
 	if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then
-		msg "Cleaning up ALL files from $SRCDEST."
-		echo -n "    Are you sure you wish to do this? [Y/n] "
+		msg "$(eval_gettext "Cleaning up ALL files from \$SRCDEST.")"
+		echo -n "$(gettext "    Are you sure you wish to do this? [Y/n] ")"
 		read answer
 		answer=$(echo $answer | tr [:upper:] [:lower:])
 		if [ "$answer" = "yes" -o "$answer" = "y" ]; then

If you translate the question, you have to translate the "yes" and "y"
strings as well.


@@ -599,111 +588,106 @@ fi
 if [ "$EUID" != "0" ]; then
 	if [ "$(check_buildenv fakeroot)" = "y" ]; then
 		if [ $(type -p fakeroot) ]; then
-			msg "Entering fakeroot environment"
+			msg "$(gettext "Entering fakeroot environment")"
 			fakeroot -- $0 -F $ARGLIST
 			exit $?
 		else
-			warning "Fakeroot is not installed. Building as an unprivileged user"
-			plain "will result in non-root ownership of the packaged files. Install"
-			plain "the fakeroot package to correctly build as a non-root user."
+			warning "$(gettext "Fakeroot is not installed. Building as an
unprivileged user")"
+			plain "$(gettext "will result in non-root ownership of the
packaged files. Install")"
+			plain "$(gettext "the fakeroot package to correctly build as a
non-root user.")"

Note- we should figure out a better way of doing this and getting it
all in one string, but that may have to wait until we get different
message functions that can handle it.

+unset deplist makedeplist

More holdover code. It comes up below in a - part of the patch.

 # fix flyspray bug #5973
 if [ "$NODEPS" = "1" -o "$GENINTEG" = "1" -o "$NOBUILD" = "1" -o
"$REPKG" = "1" ]; then
 	if [ "$NODEPS" = "1" ]; then
-		warning "skipping dependency checks"
+		warning "$(gettext "skipping dependency checks")"
 	fi
 	# skip printing a warning message for the others: geninteg, nobuild, repkg
 elif [ $(type -p pacman) ]; then
 	deperr=0
-	# these two variables are needed later by removedeps
-	unset runtimedeps buildtimedeps

-	msg "Checking Runtime Dependencies..."
+	msg "$(gettext "Checking Runtime Dependencies...")"
 	resolvedeps ${depends[@]}
-	ret=$?
-	# deplist is a global variable set by resolvedeps
-	runtimedeps="$deplist"
-	if [ "$ret" != "0" ]; then
+	if [ $? -ne 0 ]; then
 		deperr=1
 	fi

-	msg "Checking Buildtime Dependencies..."
+	msg "$(gettext "Checking Buildtime Dependencies...")"
 	resolvedeps ${makedepends[@]}
-	ret=$?
-	# deplist is a global variable set by resolvedeps
-	buildtimedeps="$deplist"
-	if [ "$ret" != "0" ]; then
+	if [ $? -ne 0 ]; then
 		deperr=1
 	fi

 	if [ $deperr -eq 1 ]; then
-		error "could not resolve all dependencies."
+		error "$(gettext "could not resolve all dependencies.")"
 		exit 1
 	fi
 else
-	warning "pacman was not found in PATH. skipping dependency checks."
+	warning "$(gettext "pacman was not found in PATH. skipping
dependency checks.")"
 fi

 cd "$startdir"


@@ -883,7 +867,6 @@ else
 	echo $SHELLOPTS | grep errexit 2>&1 >/dev/null
 	set_e=$?

-	ret=0
 	if [ "$LOGGING" = "1" ]; then
 		BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log"
 		if [ -f "$BUILDLOG" ]; then
@@ -900,24 +883,30 @@ else

 		#use 'errexit' to bail on syntax error
 		[ $set_e -eq 1 ] && set -e
-		build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]}
+		build 2>&1 | tee "$BUILDLOG"
 		[ $set_e -eq 1 ] && set +e
+
+		if [ ${PIPESTATUS[0]} -gt 0 ]; then
+			error "$(gettext "Build Failed.  Aborting...")"
+			removedeps
+			exit 2
+		fi
 	else
 		#use 'errexit' to bail on syntax error
 		[ $set_e -eq 1 ] && set -e
-		build 2>&1 || ret=$?
+		build 2>&1
 		[ $set_e -eq 1 ] && set +e
-	fi
-	if [ $ret -gt 0 ]; then
-		error "Build Failed.  Aborting..."
-		removedeps
-		exit 2
+		if [ $? -gt 0 ]; then
+			error "$(gettext "Build Failed.  Aborting...")"
+			removedeps
+			exit 2
+		fi
 	fi
 fi

Old code.

 # write the .PKGINFO file
-msg "Generating .PKGINFO file..."
+msg "$(gettext "Generating .PKGINFO file...")"
 cd "$startdir/pkg"
-echo "# Generated by makepkg $myver" >.PKGINFO
+echo "$(eval_gettext "# Generated by makepkg \$myver")" >.PKGINFO

Leave this one out of gettext- its a debug message and goes into the
package itself.

-Dan




More information about the pacman-dev mailing list