1 |
llvm.org eclass is meant to provide helper routines for maintaining |
2 |
LLVM packages. It takes care of covering the differences between |
3 |
release, prerelease and git ebuilds in a unified API. This will make |
4 |
maintenance much easier. |
5 |
|
6 |
Initially, the eclass takes care of fetching and unpacking the archives. |
7 |
Later on, I will work on moving some more common stuff there. |
8 |
|
9 |
Signed-off-by: Michał Górny <mgorny@g.o> |
10 |
--- |
11 |
eclass/llvm.org.eclass | 198 +++++++++++++++++++++++++++++++++++++++++ |
12 |
1 file changed, 198 insertions(+) |
13 |
create mode 100644 eclass/llvm.org.eclass |
14 |
|
15 |
// I'm following this up with a few example updates to ebuilds. This |
16 |
// patchset neither covers all ebuilds nor is final. |
17 |
|
18 |
diff --git a/eclass/llvm.org.eclass b/eclass/llvm.org.eclass |
19 |
new file mode 100644 |
20 |
index 000000000000..5a704c1d9805 |
21 |
--- /dev/null |
22 |
+++ b/eclass/llvm.org.eclass |
23 |
@@ -0,0 +1,198 @@ |
24 |
+# Copyright 2019 Gentoo Authors |
25 |
+# Distributed under the terms of the GNU General Public License v2 |
26 |
+ |
27 |
+# @ECLASS: llvm.org.eclass |
28 |
+# @MAINTAINER: |
29 |
+# Michał Górny <mgorny@g.o> |
30 |
+# @AUTHOR: |
31 |
+# Michał Górny <mgorny@g.o> |
32 |
+# @BLURB: Common bits for fetching & unpacking llvm.org projects |
33 |
+# @DESCRIPTION: |
34 |
+# The llvm.org eclass provides common code to fetch and unpack parts |
35 |
+# of the llvm.org project tree. It takes care of handling both git |
36 |
+# checkouts and source tarballs, making it possible to unify the code |
37 |
+# of live and release ebuilds and effectively reduce the work needed |
38 |
+# to package new releases/RCs/branches. |
39 |
+# |
40 |
+# In order to use this eclass, the ebuild needs to declare |
41 |
+# LLVM_COMPONENTS and then call llvm.org_set_globals. If tests require |
42 |
+# additional components, they need to be listed in LLVM_TEST_COMPONENTS. |
43 |
+# The eclass exports an implementation of src_unpack() phase. |
44 |
+# |
45 |
+# Example: |
46 |
+# @CODE |
47 |
+# inherit llvm.org |
48 |
+# |
49 |
+# LLVM_COMPONENTS=( lld ) |
50 |
+# LLVM_TEST_COMPONENTS=( llvm/utils/lit ) |
51 |
+# llvm.org_set_globals |
52 |
+# @CODE |
53 |
+ |
54 |
+case "${EAPI:-0}" in |
55 |
+ 7) |
56 |
+ ;; |
57 |
+ *) |
58 |
+ die "Unsupported EAPI=${EAPI} for ${ECLASS}" |
59 |
+ ;; |
60 |
+esac |
61 |
+ |
62 |
+ |
63 |
+# == internal control bits == |
64 |
+ |
65 |
+# @ECLASS-VARIABLE: _LLVM_MASTER_MAJOR |
66 |
+# @INTERNAL |
67 |
+# @DESCRIPTION: |
68 |
+# The major version of current LLVM trunk. Used to determine |
69 |
+# the correct branch to use. |
70 |
+_LLVM_MASTER_MAJOR=10 |
71 |
+ |
72 |
+# @ECLASS-VARIABLE: _LLVM_SOURCE_TYPE |
73 |
+# @INTERNAL |
74 |
+# @DESCRIPTION: |
75 |
+# Source type to use: 'git' or 'tar'. |
76 |
+if [[ -z ${_LLVM_SOURCE_TYPE+1} ]]; then |
77 |
+ if [[ ${PV} == *.9999 ]]; then |
78 |
+ _LLVM_SOURCE_TYPE=git |
79 |
+ else |
80 |
+ _LLVM_SOURCE_TYPE=tar |
81 |
+ fi |
82 |
+fi |
83 |
+ |
84 |
+[[ ${_LLVM_SOURCE_TYPE} == git ]] && inherit git-r3 |
85 |
+ |
86 |
+[[ ${PV} == ${_LLVM_MASTER_MAJOR}.* && ${_LLVM_SOURCE_TYPE} == tar ]] && |
87 |
+ die "${ECLASS}: Release ebuild for master branch?!" |
88 |
+ |
89 |
+ |
90 |
+# == control variables == |
91 |
+ |
92 |
+# @ECLASS-VARIABLE: LLVM_COMPONENTS |
93 |
+# @REQUIRED |
94 |
+# @DESCRIPTION: |
95 |
+# List of components needed unconditionally. Specified as bash array |
96 |
+# with paths relative to llvm-project git. Automatically translated |
97 |
+# for tarball releases. |
98 |
+# |
99 |
+# The first path specified is used to construct default S. |
100 |
+ |
101 |
+# @ECLASS-VARIABLE: LLVM_TEST_COMPONENTS |
102 |
+# @DEFAULT_UNSET |
103 |
+# @DESCRIPTION: |
104 |
+# List of additional components needed for tests. |
105 |
+ |
106 |
+ |
107 |
+# == global scope logic == |
108 |
+ |
109 |
+# @FUNCTION: _llvm.org_get_archives |
110 |
+# @USAGE: <components> |
111 |
+# @INTERNAL |
112 |
+# @DESCRIPTION: |
113 |
+# Set 'archives' array to list of unique archive filenames |
114 |
+# for components passed as parameters. |
115 |
+_llvm.org_get_archives() { |
116 |
+ local c |
117 |
+ archives=() |
118 |
+ |
119 |
+ for c; do |
120 |
+ local cn=${c%%/*} |
121 |
+ case ${cn} in |
122 |
+ clang) cn=cfe;; |
123 |
+ esac |
124 |
+ |
125 |
+ local a=${cn}-${PV}.src.tar.xz |
126 |
+ has "${a}" "${archives[@]}" || archives+=( "${a}" ) |
127 |
+ done |
128 |
+} |
129 |
+ |
130 |
+# @FUNCTION: llvm.org_set_globals |
131 |
+# @DESCRIPTION: |
132 |
+# Set global variables. This must be called after setting LLVM_* |
133 |
+# variables used by the eclass. |
134 |
+llvm.org_set_globals() { |
135 |
+ if [[ $(declare -p LLVM_COMPONENTS) != "declare -a"* ]]; then |
136 |
+ die 'LLVM_COMPONENTS must be an array.' |
137 |
+ fi |
138 |
+ if declare -p LLVM_TEST_COMPONENTS &>/dev/null; then |
139 |
+ if [[ $(declare -p LLVM_TEST_COMPONENTS) != "declare -a"* ]]; then |
140 |
+ die 'LLVM_TEST_COMPONENTS must be an array.' |
141 |
+ fi |
142 |
+ fi |
143 |
+ |
144 |
+ if [[ ${_LLVM_SOURCE_TYPE} == git ]]; then |
145 |
+ EGIT_REPO_URI="https://github.com/llvm/llvm-project.git" |
146 |
+ |
147 |
+ [[ ${PV} != ${_LLVM_MASTER_MAJOR}.* ]] && |
148 |
+ EGIT_BRANCH="release/${PV%%.*}.x" |
149 |
+ elif [[ ${_LLVM_SOURCE_TYPE} == tar ]]; then |
150 |
+ local a archives=() |
151 |
+ _llvm.org_get_archives "${LLVM_COMPONENTS[@]}" |
152 |
+ for a in "${archives[@]}"; do |
153 |
+ SRC_URI+=" |
154 |
+ https://releases.llvm.org/${PV}/${a}" |
155 |
+ done |
156 |
+ else |
157 |
+ die "Invalid _LLVM_SOURCE_TYPE: ${LLVM_SOURCE_TYPE}" |
158 |
+ fi |
159 |
+ |
160 |
+ S=${WORKDIR}/${LLVM_COMPONENTS[0]} |
161 |
+ |
162 |
+ if [[ -n ${LLVM_TEST_COMPONENTS+1} ]]; then |
163 |
+ IUSE+=" test" |
164 |
+ RESTRICT+=" !test? ( test )" |
165 |
+ |
166 |
+ if [[ ${_LLVM_SOURCE_TYPE} == tar ]]; then |
167 |
+ SRC_URI+=" |
168 |
+ test? (" |
169 |
+ |
170 |
+ _llvm.org_get_archives "${LLVM_TEST_COMPONENTS[@]}" |
171 |
+ for a in "${archives[@]}"; do |
172 |
+ SRC_URI+=" |
173 |
+ https://releases.llvm.org/${PV}/${a}" |
174 |
+ done |
175 |
+ |
176 |
+ SRC_URI+=" |
177 |
+ )" |
178 |
+ fi |
179 |
+ fi |
180 |
+ |
181 |
+ _LLVM_ORG_SET_GLOBALS_CALLED=1 |
182 |
+} |
183 |
+ |
184 |
+ |
185 |
+# == phase functions == |
186 |
+ |
187 |
+EXPORT_FUNCTIONS src_unpack |
188 |
+ |
189 |
+# @FUNCTION: llvm.org_src_unpack |
190 |
+# @DESCRIPTION: |
191 |
+# Unpack or checkout requested LLVM components. |
192 |
+llvm.org_src_unpack() { |
193 |
+ if [[ ! ${_LLVM_ORG_SET_GLOBALS_CALLED} ]]; then |
194 |
+ die "llvm.org_set_globals must be called in global scope" |
195 |
+ fi |
196 |
+ |
197 |
+ local components=( "${LLVM_COMPONENTS[@]}" ) |
198 |
+ if [[ ${LLVM_TEST_COMPONENTS+1} ]] && use test; then |
199 |
+ components+=( "${LLVM_TEST_COMPONENTS[@]}" ) |
200 |
+ fi |
201 |
+ |
202 |
+ if [[ ${_LLVM_SOURCE_TYPE} == git ]]; then |
203 |
+ git-r3_fetch |
204 |
+ git-r3_checkout '' . '' "${components[@]}" |
205 |
+ else |
206 |
+ local c archives |
207 |
+ # TODO: optimize this |
208 |
+ for c in "${components[@]}"; do |
209 |
+ local top_dir=${c%%/*} |
210 |
+ _llvm.org_get_archives "${c}" |
211 |
+ local sub_path=${archives[0]%.tar.xz} |
212 |
+ [[ ${c} == */* ]] && sub_path+=/${c#*/} |
213 |
+ |
214 |
+ ebegin "Unpacking ${sub_path} from ${archives[0]}" |
215 |
+ mkdir -p "${top_dir}" || die |
216 |
+ tar -C "${top_dir}" -x -J -o --strip-components 1 \ |
217 |
+ -f "${DISTDIR}/${archives[0]}" "${sub_path}" || die |
218 |
+ eend |
219 |
+ done |
220 |
+ fi |
221 |
+} |
222 |
-- |
223 |
2.23.0 |