Gentoo Archives: gentoo-dev

From: Dan Douglas <ormaaj@×××××.com>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [PATCH] git-r3.eclass: Make EGIT_LIVE_* associative arrays
Date: Wed, 22 Jun 2016 23:23:27
Message-Id: 8ab81d74-fc21-cfa7-4606-fbcddf8060fe@gmail.com
1 This creates new associative arrays for each "live" variable if bash4 /
2 eapi6 is available. Mainly for user convenience in a bashrc as an
3 alternative to magic variable names.
4 ---
5 eclass/git-r3.eclass | 68 ++++++++++++++++++++++++++++++----------------------
6 1 file changed, 39 insertions(+), 29 deletions(-)
7
8 diff --git a/eclass/git-r3.eclass b/eclass/git-r3.eclass
9 index 0ac9d90..220054e 100644
10 --- a/eclass/git-r3.eclass
11 +++ b/eclass/git-r3.eclass
12 @@ -112,14 +112,19 @@ fi
13 # @ECLASS-VARIABLE: EGIT_REPO_URI
14 # @REQUIRED
15 # @DESCRIPTION:
16 -# URIs to the repository, e.g. git://foo, https://foo. If multiple URIs
17 -# are provided, the eclass will consider them as fallback URIs to try
18 -# if the first URI does not work. For supported URI syntaxes, read up
19 -# the manpage for git-clone(1).
20 +# URIs to the repository, e.g. git://foo, https://foo. If multiple URIs are
21 +# provided, the eclass will consider them as fallback URIs to try if the first
22 +# URI does not work. For supported URI syntaxes, read up the manpage for
23 +# git-clone(1). EGIT_REPO_URI can also be a whitespace-separated list or an
24 +# array.
25 #
26 -# It can be overriden via env using ${PN}_LIVE_REPO variable.
27 -#
28 -# Can be a whitespace-separated list or an array.
29 +# It can be overriden via env using the ${PN}_LIVE_REPO variable. Hyphens and
30 +# pluses in ${PN} must be substituted for underscores to form a valid variable
31 +# name.
32 +
33 +# Additionally, a .bashrc or hook function can use the EGIT_LIVE_REPO[${PN}]
34 +# associative array (bash 4 only). Its value can be a whitespace-spearated
35 +# list. EGIT_LIVE_REPO takes precedence over ${PN}_LIVE_REPO.
36 #
37 # Example:
38 # @CODE
39 @@ -148,7 +153,8 @@ fi
40 # The branch name to check out. If unset, the upstream default (HEAD)
41 # will be used.
42 #
43 -# It can be overridden via env using ${PN}_LIVE_BRANCH variable.
44 +# It can be overridden via env using ${PN}_LIVE_BRANCH variable or via
45 +# EGIT_LIVE_BRANCH[${PN}] associative array.
46
47 # @ECLASS-VARIABLE: EGIT_COMMIT
48 # @DEFAULT_UNSET
49 @@ -157,7 +163,8 @@ fi
50 # commit from the branch will be used. If set, EGIT_BRANCH will
51 # be ignored.
52 #
53 -# It can be overridden via env using ${PN}_LIVE_COMMIT variable.
54 +# It can be overridden via env using ${PN}_LIVE_COMMIT variable or via
55 +# EGIT_LIVE_COMMIT[${PN}] associative array.
56
57 # @ECLASS-VARIABLE: EGIT_COMMIT_DATE
58 # @DEFAULT_UNSET
59 @@ -172,7 +179,8 @@ fi
60 # will be considered alike a single commit with date corresponding
61 # to the merge commit date.
62 #
63 -# It can be overridden via env using ${PN}_LIVE_COMMIT_DATE variable.
64 +# It can be overridden via env using ${PN}_LIVE_COMMIT_DATE variable or via
65 +# EGIT_LIVE_COMMIT_DATE[${PN}] associative array.
66
67 # @ECLASS-VARIABLE: EGIT_CHECKOUT_DIR
68 # @DESCRIPTION:
69 @@ -251,28 +259,30 @@ _git-r3_env_setup() {
70 die 'EGIT_SUBMODULES must be an array.'
71 fi
72
73 - local esc_pn livevar
74 - esc_pn=${PN//[-+]/_}
75 -
76 - livevar=${esc_pn}_LIVE_REPO
77 - EGIT_REPO_URI=${!livevar-${EGIT_REPO_URI}}
78 - [[ ${!livevar} ]] \
79 - && ewarn "Using ${livevar}, no support will be provided"
80 + # Pairs of variable names associating eclass variables with the
81 + # user-configurable variables for overriding them.
82 + local -a livevars=(
83 + EGIT_REPO_URI LIVE_REPO
84 + {EGIT,LIVE}_BRANCH
85 + {EGIT,LIVE}_COMMIT
86 + {EGIT,LIVE}_COMMIT_DATE
87 + )
88
89 - livevar=${esc_pn}_LIVE_BRANCH
90 - EGIT_BRANCH=${!livevar-${EGIT_BRANCH}}
91 - [[ ${!livevar} ]] \
92 - && ewarn "Using ${livevar}, no support will be provided"
93 + local idx ref esc_pn=${PN//[-+]/_}
94 + for ((idx = 0; idx <= ${#livevars[@]}; idx += 2)); do
95 + [[
96 + ( BASH_VERSINFO[0] -ge 4 || EAPI -ge 6 ) &&
97 + $(declare -p "EGIT_${livevars[idx+1]}" 2>/dev/null) == 'declare -A'*
98 + ]] && ref=EGIT_${livevars[idx+1]}[\$PN]
99
100 - livevar=${esc_pn}_LIVE_COMMIT
101 - EGIT_COMMIT=${!livevar-${EGIT_COMMIT}}
102 - [[ ${!livevar} ]] \
103 - && ewarn "Using ${livevar}, no support will be provided"
104 + [[ ${!ref} ]] || ref=${esc_pn}_${livevars[idx+1]}
105
106 - livevar=${esc_pn}_LIVE_COMMIT_DATE
107 - EGIT_COMMIT_DATE=${!livevar-${EGIT_COMMIT_DATE}}
108 - [[ ${!livevar} ]] \
109 - && ewarn "Using ${livevar}, no support will be provided"
110 + if [[ ${!ref} ]]; then
111 + ewarn "Using ${livevars[idx]} = ${!ref}. This build is unsupported."
112 + printf -v "${livevars[idx]}" -- %s "${!ref}"
113 + fi
114 + unset -v ref
115 + done
116
117 if [[ ${EGIT_COMMIT} && ${EGIT_COMMIT_DATE} ]]; then
118 die "EGIT_COMMIT and EGIT_COMMIT_DATE can not be specified simultaneously"
119 --
120 2.9.0

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies