• [gentoo-dev] [PATCH v2] multiprocessing.eclass: Default makeopts_jobs t

    From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Thu Apr 28 15:40:01 2022
    Change the default value for 'inf' argument to makeopts_jobs from 999
    to $(get_nproc) + 1. This means that if MAKEOPTS specifies a `-j`
    argument without a specific value, nproc will be used rather than
    infinity-ish number of jobs.

    The old default made sense for ebuilds using both makeopts_jobs
    and makeopts_loadavg. However, these are very rare — only 4 packages
    and 3 eclass at this time. For the remaining ebuilds, they meant uncontrollably using up to 999 jobs.

    The new default is both safer and more correct for the vast majority
    of Gentoo packages, removing the necessity of repeating:

    $(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)")

    The ebuilds and eclasses using makeopts_loadavg have been updated
    to pass the old default.

    Signed-off-by: Michał Górny <mgorny@gentoo.org>
    ---
    eclass/multiprocessing.eclass | 9 ++++-----
    eclass/tests/multiprocessing_makeopts_jobs.sh | 15 ++++++++++-----
    2 files changed, 14 insertions(+), 10 deletions(-)

    Changes in v2:
    - changed the default to nproc+1 as suggested by Flow, thanks!

    diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass index c32bfaac2e6b..b235c74a5baa 100644
    --- a/eclass/multiprocessing.eclass
    +++ b/eclass/multiprocessing.eclass
    @@ -65,22 +65,21 @@ get_nproc() {
    }

    # @FUNCTION: makeopts_jobs
    -# @USAGE: [${MAKEOPTS}] [${inf:-999}]
    +# @USAGE: [${MAKEOPTS}] [${inf:-$(( $(get_nproc) + 1 ))}]
    # @DESCRIPTION:
    # Searches the arguments (defaults to ${MAKEOPTS}) 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