1 |
commit: aecc59a5f2c05db09ee7e04a32875998adddf446 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Sep 20 18:18:44 2018 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Sep 20 18:48:37 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=aecc59a5 |
7 |
|
8 |
Move parallel xargs wrapping to isolated-functions.sh |
9 |
|
10 |
Move the parallel xargs support used in pngfix QA check |
11 |
to isolated-functions.sh, to be reused in ecompress. |
12 |
|
13 |
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> |
14 |
Reviewed-by: Zac Medico <zmedico <AT> gentoo.org> |
15 |
|
16 |
bin/helper-functions.sh | 9 +-------- |
17 |
bin/install-qa-check.d/60pngfix | 13 ++----------- |
18 |
bin/isolated-functions.sh | 22 ++++++++++++++++++++++ |
19 |
3 files changed, 25 insertions(+), 19 deletions(-) |
20 |
|
21 |
diff --git a/bin/helper-functions.sh b/bin/helper-functions.sh |
22 |
index 9b6e201aa..2d359762a 100644 |
23 |
--- a/bin/helper-functions.sh |
24 |
+++ b/bin/helper-functions.sh |
25 |
@@ -10,13 +10,6 @@ source "${PORTAGE_BIN_PATH}"/isolated-functions.sh || exit 1 |
26 |
# |
27 |
# API functions for doing parallel processing |
28 |
# |
29 |
-makeopts_jobs() { |
30 |
- # Copied from eutils.eclass:makeopts_jobs() |
31 |
- local jobs=$(echo " ${MAKEOPTS} " | \ |
32 |
- sed -r -n 's:.*[[:space:]](-j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p') |
33 |
- echo ${jobs:-1} |
34 |
-} |
35 |
- |
36 |
__multijob_init() { |
37 |
# Setup a pipe for children to write their pids to when they finish. |
38 |
# We have to allocate two fd's because POSIX has undefined behavior |
39 |
@@ -34,7 +27,7 @@ __multijob_init() { |
40 |
rm -f "${pipe}" |
41 |
|
42 |
# See how many children we can fork based on the user's settings. |
43 |
- mj_max_jobs=$(makeopts_jobs "$@") |
44 |
+ mj_max_jobs=$(___makeopts_jobs "$@") |
45 |
mj_num_jobs=0 |
46 |
} |
47 |
|
48 |
|
49 |
diff --git a/bin/install-qa-check.d/60pngfix b/bin/install-qa-check.d/60pngfix |
50 |
index b69c55614..a2e23d1d3 100644 |
51 |
--- a/bin/install-qa-check.d/60pngfix |
52 |
+++ b/bin/install-qa-check.d/60pngfix |
53 |
@@ -1,16 +1,7 @@ |
54 |
# Check for issues with PNG files |
55 |
|
56 |
-source "${PORTAGE_BIN_PATH}/helper-functions.sh" || exit 1 |
57 |
- |
58 |
pngfix_check() { |
59 |
- local chunksize=1 jobs pngfix=$(type -P pngfix) xargs=(${XARGS}) |
60 |
- |
61 |
- if "${xargs[@]}" --help | grep -q -- --max-procs=; then |
62 |
- jobs=$(makeopts_jobs) |
63 |
- if [[ ${jobs} -gt 1 ]]; then |
64 |
- xargs+=("--max-procs=${jobs}" -L "${chunksize}") |
65 |
- fi |
66 |
- fi |
67 |
+ local pngfix=$(type -P pngfix) |
68 |
|
69 |
if [[ -n ${pngfix} ]] ; then |
70 |
local pngout=() |
71 |
@@ -35,7 +26,7 @@ pngfix_check() { |
72 |
fi |
73 |
eqawarn " ${pngout[@]:7}: ${error}" |
74 |
fi |
75 |
- done < <(find "${ED}" -type f -name '*.png' -print0 | "${xargs[@]}" -0 "${pngfix}") |
76 |
+ done < <(find "${ED}" -type f -name '*.png' -print0 | ___parallel_xargs -0 "${pngfix}") |
77 |
fi |
78 |
} |
79 |
|
80 |
|
81 |
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh |
82 |
index cac42a4c5..39b0ad344 100644 |
83 |
--- a/bin/isolated-functions.sh |
84 |
+++ b/bin/isolated-functions.sh |
85 |
@@ -460,6 +460,28 @@ if [[ -z ${XARGS} ]] ; then |
86 |
esac |
87 |
fi |
88 |
|
89 |
+___makeopts_jobs() { |
90 |
+ # Copied from eutils.eclass:makeopts_jobs() |
91 |
+ local jobs=$(echo " ${MAKEOPTS} " | \ |
92 |
+ sed -r -n 's:.*[[:space:]](-j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p') |
93 |
+ echo ${jobs:-1} |
94 |
+} |
95 |
+ |
96 |
+# Run ${XARGS} in parallel for detected number of CPUs, if supported. |
97 |
+# Passes all arguments to xargs, and returns its exit code |
98 |
+___parallel_xargs() { |
99 |
+ local chunksize=1 jobs xargs=( ${XARGS} ) |
100 |
+ |
101 |
+ if "${xargs[@]}" --help | grep -q -- --max-procs=; then |
102 |
+ jobs=$(___makeopts_jobs) |
103 |
+ if [[ ${jobs} -gt 1 ]]; then |
104 |
+ xargs+=("--max-procs=${jobs}" -L "${chunksize}") |
105 |
+ fi |
106 |
+ fi |
107 |
+ |
108 |
+ "${xargs[@]}" "${@}" |
109 |
+} |
110 |
+ |
111 |
hasq() { |
112 |
has $EBUILD_PHASE prerm postrm || eqawarn \ |
113 |
"QA Notice: The 'hasq' function is deprecated (replaced by 'has')" |