[pacman-dev] [PATCH v8 03/12] bacman: parallel packaging

Gordian Edenhofer gordian.edenhofer at gmail.com
Sun Sep 4 16:13:58 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 e7a7f57..0c71541 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -354,8 +354,29 @@ fakebuild() {
 	rm -rf "$work_dir"
 }
 
+# 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
 msg "Done."
 
 exit 0
-- 
2.9.3


More information about the pacman-dev mailing list