On Wed, 14 Dec 2016 15:30:06 +0300
Andrew Savchenko <birc...@gentoo.org> wrote:

> On Tue, 13 Dec 2016 10:36:16 +0100 Michał Górny wrote:
> > Support passing custom values for 'infinity' in makeopts_jobs()
> > and makeopts_loadavg(). This can be used e.g. when a build system does
> > not support --loadavg, and therefore '--jobs 999' would most likely
> > be a really bad idea. Combined with get_nproc(), this can be used to
> > provide a sane replacement instead.
> > ---
> >  eclass/multiprocessing.eclass | 17 ++++++++++-------
> >  1 file changed, 10 insertions(+), 7 deletions(-)
> > 
> > diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass
> > index 0d241cdc15b6..b7d5f435f888 100644
> > --- a/eclass/multiprocessing.eclass
> > +++ b/eclass/multiprocessing.eclass
> > @@ -79,26 +79,27 @@ get_nproc() {
> >  }
> >  
> >  # @FUNCTION: makeopts_jobs
> > -# @USAGE: [${MAKEOPTS}]
> > +# @USAGE: [${MAKEOPTS}] [${inf:-999}]
> >  # @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 `make` uses.  Since 
> > there's
> > -# no way to represent infinity, we return 999 if the user has -j without a 
> > number.
> > +# no way to represent infinity, we return ${inf} (defaults to 999) if the 
> > user
> > +# has -j without a number.
> >  makeopts_jobs() {
> >     [[ $# -eq 0 ]] && set -- ${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 \
> >             -e 
> > 's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \
> > -           -e 's:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:999:p')
> > +           -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-999}:p")
> >     echo ${jobs:-1}
> >  }
> >  
> >  # @FUNCTION: makeopts_loadavg
> > -# @USAGE: [${MAKEOPTS}]
> > +# @USAGE: [${MAKEOPTS}] [${inf:-999}]
> >  # @DESCRIPTION:
> >  # Searches the arguments (defaults to ${MAKEOPTS}) and extracts the value 
> > set
> >  # for load-average. For make and ninja based builds this will mean new 
> > jobs are
> > @@ -106,15 +107,17 @@ makeopts_jobs() {
> >  # get excessive due to I/O and not just due to CPU load.
> >  # Be aware that the returned number might be a floating-point number. Test
> >  # whether your software supports that.
> > +# If no limit is specified or --load-average is used without a number, 
> > ${inf}
> > +# (defaults to 999) is returned.  
> 
> Why not to feed default ${inf} from get_nproc() by default?
> This will make ebuild writing easier.

Maybe it would. However, I didn't want to change the existing behavior.

Most importantly, that would mean that for people with '-j -l XXX'
the eclass would suddenly changed from '-j 999 -l XXX' to
'-j 2 -l XXX', i.e. defeat the purpose of original --jobs.

As the commit message says, the main use for nproc is for stuff that
doesn't support --loadavg or follow regular rules. SCons, various
multiprocessing test suites...

-- 
Best regards,
Michał Górny
<http://dev.gentoo.org/~mgorny/>

Attachment: pgpBHNkM7RI9f.pgp
Description: OpenPGP digital signature

Reply via email to