From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 35415158089 for ; Mon, 9 Oct 2023 10:55:00 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 679A82BC025; Mon, 9 Oct 2023 10:54:59 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 4AE592BC025 for ; Mon, 9 Oct 2023 10:54:59 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 482FF335D12 for ; Mon, 9 Oct 2023 10:54:58 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8EDC2F22 for ; Mon, 9 Oct 2023 10:54:56 +0000 (UTC) From: "Florian Schmaus" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Florian Schmaus" Message-ID: <1696848846.844eece34638a7b93a55d610d32254504bd2be63.flow@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/, eclass/tests/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/multiprocessing.eclass eclass/tests/multiprocessing_makeopts_jobs.sh X-VCS-Directories: eclass/tests/ eclass/ X-VCS-Committer: flow X-VCS-Committer-Name: Florian Schmaus X-VCS-Revision: 844eece34638a7b93a55d610d32254504bd2be63 X-VCS-Branch: master Date: Mon, 9 Oct 2023 10:54:56 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 73218797-17df-4e7e-95fb-5a9547898787 X-Archives-Hash: b7ce231611c96e6cddff50694262e859 commit: 844eece34638a7b93a55d610d32254504bd2be63 Author: Florian Schmaus gentoo org> AuthorDate: Mon Jul 24 18:54:46 2023 +0000 Commit: Florian Schmaus gentoo org> CommitDate: Mon Oct 9 10:54:06 2023 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=844eece3 multiprocessing.eclass: consider (GNU)MAKEFLAGS, add get_makeopts_{jobs,loadavg} Since --load-average may not be found in other Make implementations besides GNU Make, it is potentially found in GNUMAKEFLAGS and not in MAKEOPTS. Also, Portage is probably soon setting --load-average in GNUMAKEFLAGS as default. Thanks to floppym and mgorny for feedback. Signed-off-by: Florian Schmaus gentoo.org> eclass/multiprocessing.eclass | 38 +++++++++++++++++++++++---- eclass/tests/multiprocessing_makeopts_jobs.sh | 24 +++++++++++++++-- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass index e55be636a02c..13d6a92f2f2e 100644 --- a/eclass/multiprocessing.eclass +++ b/eclass/multiprocessing.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2022 Gentoo Authors +# Copyright 1999-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: multiprocessing.eclass @@ -64,17 +64,35 @@ get_nproc() { fi } +# @FUNCTION: _get_all_makeopts +# @INTERNAL +# @DESCRIPTION: +# Returns ${MAKEOPTS} ${GNUMAKEFLAGS} ${MAKEFLAGS}. +_get_all_makeopts() { + echo "${MAKEOPTS} ${GNUMAKEFLAGS} ${MAKEFLAGS}" +} + +# @FUNCTION: get_makeopts_jobs +# @USAGE: [default-jobs] +# @DESCRIPTION: +# Return the number of jobs extracted from the make options (MAKEOPTS, +# GNUMAKEFLAGS, MAKEFLAGS). If the make options do not specify a number, +# then either the provided default is returned, or 1. +get_makeopts_jobs() { + makeopts_jobs "$(_get_all_makeopts)" "${1:-1}" +} + # @FUNCTION: makeopts_jobs # @USAGE: [${MAKEOPTS}] [${inf:-$(( $(get_nproc) + 1 ))}] # @DESCRIPTION: -# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number +# Searches the arguments (or sensible defaults) and extracts the jobs number # specified therein. Useful for running non-make tools in parallel too. # i.e. if the user has MAKEOPTS=-j9, this will echo "9" -- we can't return the # number as bash normalizes it to [0, 255]. If the flags haven't specified a # -j flag, then "1" is shown as that is the default `make` uses. If the flags # specify -j without a number, ${inf} is returned (defaults to nproc). makeopts_jobs() { - [[ $# -eq 0 ]] && set -- "${MAKEOPTS}" + [[ $# -eq 0 ]] && set -- "$(_get_all_makeopts)" # This assumes the first .* will be more greedy than the second .* # since POSIX doesn't specify a non-greedy match (i.e. ".*?"). local jobs=$(echo " $* " | sed -r -n \ @@ -83,10 +101,20 @@ makeopts_jobs() { echo ${jobs:-1} } +# @FUNCTION: get_makeopts_loadavg +# @USAGE: [default-loadavg] +# @DESCRIPTION: +# Return the value for the load-average extracted from the make options (MAKEOPTS, +# GNUMAKEFLAGS, MAKEFLAGS). If the make options do not specify a value, then +# either the optional provided default is returned, or 999. +get_makeopts_loadavg() { + makeopts_loadavg "$(_get_all_makeopts)" "${1:-999}" +} + # @FUNCTION: makeopts_loadavg # @USAGE: [${MAKEOPTS}] [${inf:-999}] # @DESCRIPTION: -# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the value set +# Searches the arguments (or sensible defaults) and extracts the value set # for load-average. For make and ninja based builds this will mean new jobs are # not only limited by the jobs-value, but also by the current load - which might # get excessive due to I/O and not just due to CPU load. @@ -95,7 +123,7 @@ makeopts_jobs() { # If no limit is specified or --load-average is used without a number, ${inf} # (defaults to 999) is returned. makeopts_loadavg() { - [[ $# -eq 0 ]] && set -- "${MAKEOPTS}" + [[ $# -eq 0 ]] && set -- "$(_get_all_makeopts)" # This assumes the first .* will be more greedy than the second .* # since POSIX doesn't specify a non-greedy match (i.e. ".*?"). local lavg=$(echo " $* " | sed -r -n \ diff --git a/eclass/tests/multiprocessing_makeopts_jobs.sh b/eclass/tests/multiprocessing_makeopts_jobs.sh index 37d5a7257775..56d73ef48b3c 100755 --- a/eclass/tests/multiprocessing_makeopts_jobs.sh +++ b/eclass/tests/multiprocessing_makeopts_jobs.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 1999-2021 Gentoo Authors +# Copyright 1999-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=7 @@ -9,7 +9,13 @@ inherit multiprocessing test-makeopts_jobs() { local exp=$1; shift - tbegin "makeopts_jobs($1${2+; inf=${2}}) == ${exp}" + local targs + if [[ -v 1 ]]; then + targs="$1${2+; inf=${2}}" + else + targs="MAKEOPTS=\"${MAKEOPTS}\" GNUMAKEFLAGS=\"${GNUMAKEFLAGS}\" MAKEFLAGS=\"${MAKEFLAGS}\"" + fi + tbegin "makeopts_jobs(${targs}) == ${exp}" local indirect=$(MAKEOPTS="$*" makeopts_jobs) local direct=$(makeopts_jobs "$@") if [[ "${direct}" != "${indirect}" ]] ; then @@ -50,6 +56,20 @@ for (( i = 0; i < ${#tests[@]}; i += 2 )) ; do test-makeopts_jobs "${tests[i]}" "${tests[i+1]}" done +tests=( + 7 "" "--jobs 7" "" + # MAKEFLAGS override GNUMAKEFLAGS + 8 "" "--jobs 7" "--jobs 8" +) + +for (( i = 0; i < ${#tests[@]}; i += 4 )) ; do + MAKEOPTS="${tests[i+1]}" + GNUMAKEFLAGS="${tests[i+2]}" + MAKEFLAGS="${tests[i+3]}" + test-makeopts_jobs "${tests[i]}" + unset MAKEOPTS GNUMAKEFLAGS MAKEFLAGS +done + # test custom inf value test-makeopts_jobs 645 "-j" 645