From ccd1142d22b31ed85d8823b1bc9e11ccfd72b61f Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Mon, 12 Feb 2018 13:39:58 -0600 Subject: utils.py: add parallel make helpers The code to extract the integer number of parallel build threads and construct a new argument from them has started to be copied in multiple locations, so create two new helper utilities to aid recipes. The first helper (parallel_make()) extracts the integer number of parallel build threads from PARALLEL_MAKE. The second (parallel_make_argument()) does the same and then puts the result back into a format string, optionally clamping it to some maximum value. Additionally, rework the oe-core recipes that were manually doing this to use the new helper utilities. Signed-off-by: Joshua Watt Signed-off-by: Richard Purdie --- meta/lib/oe/utils.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'meta/lib/oe') diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py index 7a79d752b6..ec91927233 100644 --- a/meta/lib/oe/utils.py +++ b/meta/lib/oe/utils.py @@ -156,6 +156,49 @@ def any_distro_features(d, features, truevalue="1", falsevalue=""): """ return bb.utils.contains_any("DISTRO_FEATURES", features, truevalue, falsevalue, d) +def parallel_make(d): + """ + Return the integer value for the number of parallel threads to use when + building, scraped out of PARALLEL_MAKE. If no parallelization option is + found, returns None + + e.g. if PARALLEL_MAKE = "-j 10", this will return 10 as an integer. + """ + pm = (d.getVar('PARALLEL_MAKE') or '').split() + # look for '-j' and throw other options (e.g. '-l') away + while pm: + opt = pm.pop(0) + if opt == '-j': + v = pm.pop(0) + elif opt.startswith('-j'): + v = opt[2:].strip() + else: + continue + + return int(v) + + return None + +def parallel_make_argument(d, fmt, limit=None): + """ + Helper utility to construct a parallel make argument from the number of + parallel threads specified in PARALLEL_MAKE. + + Returns the input format string `fmt` where a single '%d' will be expanded + with the number of parallel threads to use. If `limit` is specified, the + number of parallel threads will be no larger than it. If no parallelization + option is found in PARALLEL_MAKE, returns an empty string + + e.g. if PARALLEL_MAKE = "-j 10", parallel_make_argument(d, "-n %d") will return + "-n 10" + """ + v = parallel_make(d) + if v: + if limit: + v = max(limit, v) + return fmt % v + return '' + def packages_filter_out_system(d): """ Return a list of packages from PACKAGES with the "system" packages such as -- cgit 1.2.3-korg