[pacman-dev] [PATCH v6 7/9] bacman: add option to specify the number of jobs

Gordian Edenhofer gordian.edenhofer at gmail.com
Fri Sep 2 14:50:12 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 b636cb6..120bece 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
 }
@@ -89,8 +90,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
@@ -104,6 +105,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)
@@ -190,7 +199,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
@@ -265,7 +278,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
@@ -353,7 +370,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