[pacman-dev] [PATCH v3 2/8] bacman: parallel packaging

Gordian Edenhofer gordian.edenhofer at gmail.com
Wed Aug 31 21:05:33 UTC 2016


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

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a13f074..1241718 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -348,8 +348,29 @@ fakebuild() {
 	msg "Done."
 }
 
+# Run fakebuild in parralel with at maximum $MAX_JOBS jobs
+# By default only run one job
+MAX_JOBS=${MAX_JOBS:-1}
+# TODO: Use wait -n instead of this hack as soon as it is ok
+# to bump the version of the bash dependency
+parallelize() {
+	while [[ $# -gt 0 ]]; do
+		job_count=($(jobs -p))
+		if [[ ${#job_count[@]} -lt $MAX_JOBS ]] ; then
+			fakebuild "$1" &
+			shift
+		fi
+		sleep 0.1
+	done
+	wait
+}
 
-for PKG in $@; do fakebuild $PKG; done
+# Initiate assembly function
+if [[ $MAX_JOBS -gt "1" ]]; then
+	parallelize "$@"
+else
+	for PKG in $@; do fakebuild $PKG; done
+fi
 
 exit 0
 
-- 
2.9.3


More information about the pacman-dev mailing list