From b264c7f1c771790c53561f5d3f4de589e0000c05 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sun, 10 Sep 2023 00:00:27 +0200 Subject: feat(util): parallelize srcinfo generation Heavily improve the runtime of huge split packages, by creating an own parallelized high level implementation of the makepkg low level building blocks for srcinfo generation. This reduces the runtine to generate the srcinfo file for thunderbird from 24 seconds down to 1 second. --- src/lib/util/srcinfo.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/lib/util/srcinfo.sh (limited to 'src/lib/util/srcinfo.sh') diff --git a/src/lib/util/srcinfo.sh b/src/lib/util/srcinfo.sh new file mode 100644 index 0000000..b646dc3 --- /dev/null +++ b/src/lib/util/srcinfo.sh @@ -0,0 +1,69 @@ +#!/hint/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later + +[[ -z ${DEVTOOLS_INCLUDE_UTIL_SRCINFO_SH:-} ]] || return 0 +DEVTOOLS_INCLUDE_UTIL_SRCINFO_SH=1 + +_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} +# shellcheck source=src/lib/common.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh + +source /usr/share/makepkg/util/util.sh +source /usr/share/makepkg/srcinfo.sh + +set -eo pipefail + + +print_srcinfo() { + local pkgpath=${1:-.} + local outdir pkg pid + local pids=() + + # source the PKGBUILD + # shellcheck source=contrib/makepkg/PKGBUILD.proto + . "${pkgpath}"/PKGBUILD + + # run without parallelization for single packages + if (( ${#pkgname[@]} == 1 )); then + write_srcinfo_content + return 0 + fi + + [[ -z ${WORKDIR:-} ]] && setup_workdir + outdir=$(mktemp --directory --tmpdir="${WORKDIR}" pkgctl-srcinfo.XXXXXXXXXX) + + # fork workload for each split pkgname + for pkg in "${pkgname[@]}"; do + ( + # deactivate errexit to avoid makepkg abort on grep_function + set +e + srcinfo_write_package "$pkg" > "${outdir}/${pkg}" + )& + pids+=($!) + done + + # join workload + for pid in "${pids[@]}"; do + if ! wait "${pid}"; then + return 1 + fi + done + + # collect output + srcinfo_write_global + for pkg in "${pkgname[@]}"; do + srcinfo_separate_section + cat "${outdir}/${pkg}" + done +} + +write_srcinfo_file() { + local pkgpath=${1:-.} + stat_busy 'Generating .SRCINFO' + if ! print_srcinfo "${pkgpath}" > "${pkgpath}"/.SRCINFO; then + error 'Failed to write .SRCINFO file' + return 1 + fi + stat_done +} -- cgit v1.2.3-54-g00ecf