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