Gentoo Archives: gentoo-dev

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

Attachments

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