Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] eapply_user: combine sort for all dirs (bug 608880)
Date: Sun, 06 Aug 2017 09:03:16
Message-Id: 20170806090052.10401-1-zmedico@gentoo.org
1 Combine the patch basenames from all matched directories into a
2 list, and apply them in POSIX sorted order. This allows patches in
3 more-specific directories to override patches of the same basename found
4 in less-specific directories. An empty patch (or /dev/null symlink)
5 negates a patch with the same basename found in a less-specific
6 directory.
7
8 This behavior is much more flexible and intuitive than the previous one,
9 while remaining backward-compatible to some extent.
10
11 NOTE: The implementation uses an associative array, which requires bash
12 version 4 or later.
13
14 X-Gentoo-bug: 608880
15 X-Gentoo-bug-url: https://bugs.gentoo.org/608880
16 ---
17 bin/phase-helpers.sh | 31 +++++++++++++++++++++++++------
18 1 file changed, 25 insertions(+), 6 deletions(-)
19
20 diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
21 index 4b9b12b70..f8c2c34d4 100644
22 --- a/bin/phase-helpers.sh
23 +++ b/bin/phase-helpers.sh
24 @@ -1094,22 +1094,41 @@ if ___eapi_has_eapply_user; then
25
26 local basedir=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
27
28 - local d applied
29 + local applied d f
30 + local -A _eapply_user_patches
31 local prev_shopt=$(shopt -p nullglob)
32 shopt -s nullglob
33
34 - # possibilities:
35 + # Patches from all matched directories are combined into a
36 + # sorted (POSIX order) list of the patch basenames. Patches
37 + # in more-specific directories override patches of the same
38 + # basename found in less-specific directories. An empty patch
39 + # (or /dev/null symlink) negates a patch with the same
40 + # basename found in a less-specific directory.
41 + #
42 + # order of specificity:
43 # 1. ${CATEGORY}/${P}-${PR} (note: -r0 desired to avoid applying
44 # ${P} twice)
45 # 2. ${CATEGORY}/${P}
46 # 3. ${CATEGORY}/${PN}
47 # all of the above may be optionally followed by a slot
48 - for d in "${basedir}"/${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT%/*}}; do
49 - if [[ -n $(echo "${d}"/*.diff) || -n $(echo "${d}"/*.patch) ]]; then
50 - eapply "${d}"
51 + for d in "${basedir}"/${CATEGORY}/{${P}-${PR},${P},${PN}}{:${SLOT%/*},}; do
52 + for f in "${d}"/*; do
53 + if [[ ( ${f} == *.diff || ${f} == *.patch ) &&
54 + -z ${_eapply_user_patches[${f##*/}]} ]]; then
55 + _eapply_user_patches[${f##*/}]=${f}
56 + fi
57 + done
58 + done
59 +
60 + while read -r -d '' f; do
61 + f=${_eapply_user_patches[${f}]}
62 + if [[ -s ${f} ]]; then
63 + eapply "${f}"
64 applied=1
65 fi
66 - done
67 + done < <(printf -- "%s\0" "${!_eapply_user_patches[@]}" |
68 + LC_ALL=C sort -z)
69
70 ${prev_shopt}
71
72 --
73 2.13.0