1 |
On Tue, 13 Dec 2016 10:36:16 +0100 Michał Górny wrote: |
2 |
> Support passing custom values for 'infinity' in makeopts_jobs() |
3 |
> and makeopts_loadavg(). This can be used e.g. when a build system does |
4 |
> not support --loadavg, and therefore '--jobs 999' would most likely |
5 |
> be a really bad idea. Combined with get_nproc(), this can be used to |
6 |
> provide a sane replacement instead. |
7 |
> --- |
8 |
> eclass/multiprocessing.eclass | 17 ++++++++++------- |
9 |
> 1 file changed, 10 insertions(+), 7 deletions(-) |
10 |
> |
11 |
> diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass |
12 |
> index 0d241cdc15b6..b7d5f435f888 100644 |
13 |
> --- a/eclass/multiprocessing.eclass |
14 |
> +++ b/eclass/multiprocessing.eclass |
15 |
> @@ -79,26 +79,27 @@ get_nproc() { |
16 |
> } |
17 |
> |
18 |
> # @FUNCTION: makeopts_jobs |
19 |
> -# @USAGE: [${MAKEOPTS}] |
20 |
> +# @USAGE: [${MAKEOPTS}] [${inf:-999}] |
21 |
> # @DESCRIPTION: |
22 |
> # Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number |
23 |
> # specified therein. Useful for running non-make tools in parallel too. |
24 |
> # i.e. if the user has MAKEOPTS=-j9, this will echo "9" -- we can't return the |
25 |
> # number as bash normalizes it to [0, 255]. If the flags haven't specified a |
26 |
> # -j flag, then "1" is shown as that is the default `make` uses. Since there's |
27 |
> -# no way to represent infinity, we return 999 if the user has -j without a number. |
28 |
> +# no way to represent infinity, we return ${inf} (defaults to 999) if the user |
29 |
> +# has -j without a number. |
30 |
> makeopts_jobs() { |
31 |
> [[ $# -eq 0 ]] && set -- ${MAKEOPTS} |
32 |
> # This assumes the first .* will be more greedy than the second .* |
33 |
> # since POSIX doesn't specify a non-greedy match (i.e. ".*?"). |
34 |
> local jobs=$(echo " $* " | sed -r -n \ |
35 |
> -e 's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \ |
36 |
> - -e 's:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:999:p') |
37 |
> + -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-999}:p") |
38 |
> echo ${jobs:-1} |
39 |
> } |
40 |
> |
41 |
> # @FUNCTION: makeopts_loadavg |
42 |
> -# @USAGE: [${MAKEOPTS}] |
43 |
> +# @USAGE: [${MAKEOPTS}] [${inf:-999}] |
44 |
> # @DESCRIPTION: |
45 |
> # Searches the arguments (defaults to ${MAKEOPTS}) and extracts the value set |
46 |
> # for load-average. For make and ninja based builds this will mean new jobs are |
47 |
> @@ -106,15 +107,17 @@ makeopts_jobs() { |
48 |
> # get excessive due to I/O and not just due to CPU load. |
49 |
> # Be aware that the returned number might be a floating-point number. Test |
50 |
> # whether your software supports that. |
51 |
> +# If no limit is specified or --load-average is used without a number, ${inf} |
52 |
> +# (defaults to 999) is returned. |
53 |
|
54 |
Why not to feed default ${inf} from get_nproc() by default? |
55 |
This will make ebuild writing easier. |
56 |
|
57 |
> makeopts_loadavg() { |
58 |
> [[ $# -eq 0 ]] && set -- ${MAKEOPTS} |
59 |
> # This assumes the first .* will be more greedy than the second .* |
60 |
> # since POSIX doesn't specify a non-greedy match (i.e. ".*?"). |
61 |
> local lavg=$(echo " $* " | sed -r -n \ |
62 |
> -e 's:.*[[:space:]](-[a-z]*l|--(load-average|max-load)[=[:space:]])[[:space:]]*([0-9]+|[0-9]+\.[0-9]+).*:\3:p' \ |
63 |
> - -e 's:.*[[:space:]](-[a-z]*l|--(load-average|max-load))[[:space:]].*:999:p') |
64 |
> - # Default to 999 since the default is to not use a load limit. |
65 |
> - echo ${lavg:-999} |
66 |
> + -e "s:.*[[:space:]](-[a-z]*l|--(load-average|max-load))[[:space:]].*:${2:-999}:p") |
67 |
> + # Default to ${inf} since the default is to not use a load limit. |
68 |
> + echo ${lavg:-${2:-999}} |
69 |
> } |
70 |
> |
71 |
> # @FUNCTION: multijob_init |
72 |
|
73 |
|
74 |
Best regards, |
75 |
Andrew Savchenko |