Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH 07/18] Add tentative support for EAPI6 eapply function
Date: Mon, 01 Dec 2014 21:30:09
Message-Id: 1417469316-25052-8-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 00/18] Updated EAPI 6 patch set by "Michał Górny"
1 Add the eapply patch applying function.
2 ---
3 bin/eapi.sh | 4 ++++
4 bin/phase-helpers.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
5 2 files changed, 66 insertions(+)
6
7 diff --git a/bin/eapi.sh b/bin/eapi.sh
8 index 978a410..8ffffbb 100644
9 --- a/bin/eapi.sh
10 +++ b/bin/eapi.sh
11 @@ -72,6 +72,10 @@ ___eapi_has_einstalldocs() {
12 [[ ! ${1-${EAPI}} =~ ^(0|1|2|3|4|4-python|4-slot-abi|5|5-hdepend|5-progress)$ ]]
13 }
14
15 +___eapi_has_eapply() {
16 + [[ ! ${1-${EAPI}} =~ ^(0|1|2|3|4|4-python|4-slot-abi|5|5-hdepend|5-progress)$ ]]
17 +}
18 +
19 ___eapi_has_master_repositories() {
20 [[ ${1-${EAPI}} =~ ^(5-progress)$ ]]
21 }
22 diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
23 index e401676..e9fbbb4 100644
24 --- a/bin/phase-helpers.sh
25 +++ b/bin/phase-helpers.sh
26 @@ -924,6 +924,68 @@ if ___eapi_has_einstalldocs; then
27 }
28 fi
29
30 +if ___eapi_has_eapply; then
31 + eapply() {
32 + _eapply_patch() {
33 + local f=${1}
34 + local prefix=${2}
35 +
36 + started_applying=1
37 + ebegin "${prefix:-Applying }${f##*/}"
38 + # -p1 as a sane default
39 + # -f to avoid interactivity
40 + # -s to silence progress output
41 + patch -p1 -f -s "${patch_options[@]}" < "${f}"
42 + if ! eend ${?}; then
43 + __helpers_die "patch -p1 ${patch_options[*]} failed with ${f}"
44 + failed=1
45 + fi
46 + }
47 +
48 + local f patch_options=() failed started_applying options_terminated
49 + for f; do
50 + if [[ ${f} == -* && -z ${options_terminated} ]]; then
51 + if [[ -n ${started_applying} ]]; then
52 + die "eapply: options need to be specified before files"
53 + fi
54 + if [[ ${f} == -- ]]; then
55 + options_terminated=1
56 + else
57 + patch_options+=( ${f} )
58 + fi
59 + elif [[ -d ${f} ]]; then
60 + _eapply_get_files() {
61 + local LC_ALL=POSIX
62 + local prev_shopt=$(shopt -p nullglob)
63 + shopt -s nullglob
64 + files=( "${f}"/*.{patch,diff} )
65 + ${prev_shopt}
66 + }
67 +
68 + local files
69 + _eapply_get_files
70 + [[ -z ${files[@]} ]] && die "No *.{patch,diff} files in directory ${f}"
71 +
72 + einfo "Applying patches from ${f} ..."
73 + local f2
74 + for f2 in "${files[@]}"; do
75 + _eapply_patch "${f2}" ' '
76 +
77 + # in case of nonfatal
78 + [[ -n ${failed} ]] && return 1
79 + done
80 + else
81 + _eapply_patch "${f}"
82 +
83 + # in case of nonfatal
84 + [[ -n ${failed} ]] && return 1
85 + fi
86 + done
87 +
88 + return 0
89 + }
90 +fi
91 +
92 if ___eapi_has_master_repositories; then
93 master_repositories() {
94 local output repository=$1 retval
95 --
96 2.1.3