[pacman-dev] [PATCH v8 10/12] bacman: add option to specify the number of jobs

Gordian Edenhofer gordian.edenhofer at gmail.com
Sun Sep 4 16:14:05 UTC 2016


Signed-off-by: Gordian Edenhofer <gordian.edenhofer at gmail.com>
---
 contrib/bacman.sh.in | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 7e511d6..d0c15c9 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,12 +57,13 @@ usage() {
 	printf -- "$(gettext "  -h, --help       Show this help message and exit")\n"
 	printf -- "$(gettext "  -q, --quiet      Silence most of the status reporting")\n"
 	printf -- "$(gettext "  -m, --nocolor    Disable colorized output messages")\n"
+	printf -- "$(gettext "  -j, --jobs <N>   Build in parallel with N jobs - you may want to set XZ_OPT")\n"
 	printf -- "$(gettext "  -o, --out <dir>  Write output to specified directory (instead of \$PKGDEST)")\n"
 	printf -- "$(gettext "  --pacnew         Package .pacnew files")\n"
 	echo
 	printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
 	printf -- "$(gettext "  %s gzip munge binutils -o ~/Downloads")\n" "$myname"
-	printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp gzip munge binutils")\n" "$myname"
+	printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp -j 5 gzip munge binutils")\n" "$myname"
 	printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
 	echo
 }
@@ -83,8 +84,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT=':o:qmv'
-OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT=':o:j:qmv'
+OPT_LONG=('out:' 'jobs:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
 	usage
 	exit 1
@@ -98,6 +99,14 @@ while :; do
 			pkg_dest=$2
 			[[ ! -d "$2" ]] && echo -e "The directory \e[39;1m$2\e[0m does not exist!" && exit 3
 			shift ;;
+		-j|--jobs)
+			if [[ $2 =~ ^-?[0-9]+$ ]]; then
+				MAX_JOBS=$2
+			else
+				echo -e "\e[39;1m$2\e[0m is not a valid integer!"
+				exit -1
+			fi
+			shift ;;
 		-q|--quiet)
 			QUIET=1 ;;
 		-m|--nocolor)
@@ -184,7 +193,11 @@ fakebuild() {
 	cd "$work_dir" || exit 1
 
 	# Assemble list of files which belong to the package and tar them
-	msg2 "Copying package files..."
+	if [[ $MAX_JOBS -gt 1 ]]; then
+		msg2 "${pkg_name}: Copying package files..."
+	else
+		msg2 "Copying package files..."
+	fi
 
 	while read i; do
 		if [[ -z $i ]]; then
@@ -259,7 +272,11 @@ fakebuild() {
 
 	# Reconstruct .PKGINFO from database
 	# TODO adopt makepkg's write_pkginfo() into this or scripts/library
-	msg2 "Generating .PKGINFO metadata..."
+	if [[ $MAX_JOBS -gt 1 ]]; then
+		msg2 "${pkg_name}: Generating .PKGINFO metadata..."
+	else
+		msg2 "Generating .PKGINFO metadata..."
+	fi
 	echo "# Generated by $myname $myver"    > .PKGINFO
 	if [[ $INFAKEROOT == "1" ]]; then
 		echo "# Using $(fakeroot -v)"    >> .PKGINFO
@@ -347,7 +364,11 @@ fakebuild() {
 	chmod 644 "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
 
 	# Generate the package
-	msg2 "Generating the package..."
+	if [[ $MAX_JOBS -gt 1 ]]; then
+		msg2 "${pkg_name}: Generating the package..."
+	else
+		msg2 "Generating the package..."
+	fi
 
 	pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
 	ret=0
-- 
2.9.3


More information about the pacman-dev mailing list