From 36bfb42170c6dc09db52b99fa6464ef8a781cd43 Mon Sep 17 00:00:00 2001 From: Marcel Saegebarth Date: Wed, 14 Jun 2017 13:57:48 +0200 Subject: [PATCH] sqg: Parallelize building for selected packages Signed-off-by: Marcel Saegebarth --- src/usr/libexec/sbopkg/sqg/functions | 40 ++++++++++++++++++++++++++-- src/usr/sbin/sqg | 33 ++++++++++++++--------- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/usr/libexec/sbopkg/sqg/functions b/src/usr/libexec/sbopkg/sqg/functions index e8580ed..55ca1c2 100644 --- a/src/usr/libexec/sbopkg/sqg/functions +++ b/src/usr/libexec/sbopkg/sqg/functions @@ -1,8 +1,16 @@ #!/bin/sh -# use filesystem for caching SlackBuilds +# +# Use file system for caching SlackBuilds. +# SQG_TMP_DIR=${SQG_TMP_DIR:-/tmp/sqg} +# +# Sanity checks: +# - sbopkg.conf is available +# - slackbuilds.org was synced with `rsync` or `git` +# - directory checks +# sanity_checks () { if [ ! -e "$SBOPKG_CONF" ]; then echo "$SBOPKG_CONF not found." @@ -29,6 +37,9 @@ sanity_checks () { mkdir -p "$SQG_TMP_DIR" } +# +# Returns 1 if GNU Parallel is installed. Otherwise 0. +# has_parallel () { parallel --help &> /dev/null if [ $? -eq 0 ]; then @@ -38,11 +49,14 @@ has_parallel () { return 0 } +# +# Prints the help message. +# usage () { local SCRIPT="$1" cat << EOF -Usage: $SCRIPT -p | -a [-j] +Usage: $SCRIPT -p [-j #] | -a [-j #] Options are: -p package(s) Creates queuefile(s) for individual package(s). Multiple packages can be passed with quotes, @@ -63,6 +77,11 @@ EOF exit } +# +# Parses and validates the amount of parallel processes defined by option -j. +# Returns the amount of jobs if value is an unsigned integer. +# Otherwise exits with code 1. +# get_jobs () { local JOBS=${1:-1} @@ -76,6 +95,13 @@ get_jobs () { return $JOBS } +# +# Tries to find the dependency listed in the SlackBuilds .info file and writes +# the path into a temporary file. If the package was already found, it gets the +# path from inside the temporary file to speed up the overall process. +# If the package path of the dependent package isn't empty, the function +# returns 1. Otherwise 0. +# search_package () { local REPO_DIR="$1" local SRCHAPP="$2" @@ -95,6 +121,10 @@ search_package () { fi } +# +# Parses the REQUIRES variable inside the SlackBuild .info file and recursively +# writes the dependent package name into the queue file. +# parse_queuefile_requires () { local REPO_DIR="$1" local PARSEAPP="$2" @@ -129,6 +159,9 @@ parse_queuefile_requires () { fi } +# +# Starts the process of building the packages queue file. +# build_queuefile () { local REPO_DIR="$1" local QUEUEDIR="$2" @@ -149,6 +182,9 @@ build_queuefile () { fi } +# +# Processes all or given packages depending on option. +# execute_build () { local REPO_DIR="$1" local QUEUEDIR="$2" diff --git a/src/usr/sbin/sqg b/src/usr/sbin/sqg index 91c1bc6..56963d0 100755 --- a/src/usr/sbin/sqg +++ b/src/usr/sbin/sqg @@ -51,22 +51,29 @@ REPO_BRANCH=${REPO_BRANCH:-$(cat /etc/slackware-version | awk '{print $2}')} . /usr/libexec/sbopkg/sqg/functions SCRIPT=${0##*/} +OPT_JOBS=1 +OPT_ALL="no" +OPT_PACKAGES="" sanity_checks -case $1 in - -a) - if [ "$2" == "-j" ] && [ -n $3 ]; then - get_jobs $3 - JOBS=$? - fi - shift; - execute_build "$REPO_DIR" "$QUEUEDIR" "" "yes" $JOBS ;; - -p) - shift; - execute_build "$REPO_DIR" "$QUEUEDIR" "$@" "no" $JOBS ;; - *) usage $SCRIPT ;; -esac +while getopts "ap:j:h" OPT; do + case $OPT in + a ) OPT_ALL="yes" ;; + p ) OPT_PACKAGES=$OPTARG ;; + j ) get_jobs "$OPTARG"; OPT_JOBS=$?; ;; + h ) usage $SCRIPT; exit 0; ;; + ? ) exit 1; ;; + esac +done + +if [ $OPTIND -eq 1 ]; then + echo -e "Missing argument(s).\n" + usage $SCRIPT + exit 1 +fi + +execute_build "$REPO_DIR" "$QUEUEDIR" "$OPT_PACKAGES" "$OPT_ALL" $OPT_JOBS echo "Done." exit 0