1 |
commit: 251c1c036407953a719149c40d958f269e8937e5 |
2 |
Author: Johannes Huber <johu <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Jun 10 14:42:00 2018 +0000 |
4 |
Commit: Johannes Huber <johu <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Jun 10 14:42:00 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/kde.git/commit/?id=251c1c03 |
7 |
|
8 |
virtualx.eclass: Drop prefix access w/o define |
9 |
|
10 |
eclass/virtualx.eclass | 260 +++++++++++++++++++++++++++++++++++++++++++++++++ |
11 |
1 file changed, 260 insertions(+) |
12 |
|
13 |
diff --git a/eclass/virtualx.eclass b/eclass/virtualx.eclass |
14 |
new file mode 100644 |
15 |
index 0000000000..749c051bf1 |
16 |
--- /dev/null |
17 |
+++ b/eclass/virtualx.eclass |
18 |
@@ -0,0 +1,260 @@ |
19 |
+# Copyright 1999-2018 Gentoo Foundation |
20 |
+# Distributed under the terms of the GNU General Public License v2 |
21 |
+ |
22 |
+# @ECLASS: virtualx.eclass |
23 |
+# @MAINTAINER: |
24 |
+# x11@g.o |
25 |
+# @AUTHOR: |
26 |
+# Original author: Martin Schlemmer <azarah@g.o> |
27 |
+# @BLURB: This eclass can be used for packages that needs a working X environment to build. |
28 |
+ |
29 |
+if [[ ! ${_VIRTUAL_X} ]]; then |
30 |
+ |
31 |
+case "${EAPI:-0}" in |
32 |
+ 0|1|2|3) |
33 |
+ die "virtualx.eclass: EAPI ${EAPI} is too old." |
34 |
+ ;; |
35 |
+ 4|5|6) |
36 |
+ ;; |
37 |
+ *) |
38 |
+ die "virtualx.eclass: EAPI ${EAPI} is not supported yet." |
39 |
+ ;; |
40 |
+esac |
41 |
+ |
42 |
+[[ ${EAPI} == [45] ]] && inherit eutils |
43 |
+ |
44 |
+# @ECLASS-VARIABLE: VIRTUALX_REQUIRED |
45 |
+# @DESCRIPTION: |
46 |
+# Variable specifying the dependency on xorg-server and xhost. |
47 |
+# Possible special values are "always" and "manual", which specify |
48 |
+# the dependency to be set unconditionaly or not at all. |
49 |
+# Any other value is taken as useflag desired to be in control of |
50 |
+# the dependency (eg. VIRTUALX_REQUIRED="kde" will add the dependency |
51 |
+# into "kde? ( )" and add kde into IUSE. |
52 |
+: ${VIRTUALX_REQUIRED:=test} |
53 |
+ |
54 |
+# @ECLASS-VARIABLE: VIRTUALX_DEPEND |
55 |
+# @DESCRIPTION: |
56 |
+# Dep string available for use outside of eclass, in case a more |
57 |
+# complicated dep is needed. |
58 |
+# You can specify the variable BEFORE inherit to add more dependencies. |
59 |
+VIRTUALX_DEPEND="${VIRTUALX_DEPEND} |
60 |
+ x11-apps/xhost |
61 |
+ x11-base/xorg-server[xvfb] |
62 |
+" |
63 |
+ |
64 |
+# @ECLASS-VARIABLE: VIRTUALX_COMMAND |
65 |
+# @DESCRIPTION: |
66 |
+# Command (or eclass function call) to be run in the X11 environment |
67 |
+# (within virtualmake function). |
68 |
+: ${VIRTUALX_COMMAND:="emake"} |
69 |
+ |
70 |
+case ${VIRTUALX_REQUIRED} in |
71 |
+ manual) |
72 |
+ ;; |
73 |
+ always) |
74 |
+ DEPEND="${VIRTUALX_DEPEND}" |
75 |
+ RDEPEND="" |
76 |
+ ;; |
77 |
+ optional|tests) |
78 |
+ [[ ${EAPI} == [45] ]] \ |
79 |
+ || die 'Values "optional" and "tests" for VIRTUALX_REQUIRED are banned in EAPI > 5' |
80 |
+ # deprecated section YAY. |
81 |
+ eqawarn "VIRTUALX_REQUIRED=optional and VIRTUALX_REQUIRED=tests are deprecated." |
82 |
+ eqawarn "You can drop the variable definition completely from ebuild," |
83 |
+ eqawarn "because it is default behaviour." |
84 |
+ |
85 |
+ if [[ -n ${VIRTUALX_USE} ]]; then |
86 |
+ # so they like to specify the useflag |
87 |
+ eqawarn "VIRTUALX_USE variable is deprecated." |
88 |
+ eqawarn "Please read eclass manpage to find out how to use VIRTUALX_REQUIRED" |
89 |
+ eqawarn "to achieve the same behaviour." |
90 |
+ fi |
91 |
+ |
92 |
+ [[ -z ${VIRTUALX_USE} ]] && VIRTUALX_USE="test" |
93 |
+ DEPEND="${VIRTUALX_USE}? ( ${VIRTUALX_DEPEND} )" |
94 |
+ RDEPEND="" |
95 |
+ IUSE="${VIRTUALX_USE}" |
96 |
+ ;; |
97 |
+ *) |
98 |
+ DEPEND="${VIRTUALX_REQUIRED}? ( ${VIRTUALX_DEPEND} )" |
99 |
+ RDEPEND="" |
100 |
+ IUSE="${VIRTUALX_REQUIRED}" |
101 |
+ ;; |
102 |
+esac |
103 |
+ |
104 |
+# @FUNCTION: virtualmake |
105 |
+# @DESCRIPTION: |
106 |
+# Function which start new Xvfb session |
107 |
+# where the VIRTUALX_COMMAND variable content gets executed. |
108 |
+virtualmake() { |
109 |
+ debug-print-function ${FUNCNAME} "$@" |
110 |
+ |
111 |
+ [[ ${EAPI} == [45] ]] \ |
112 |
+ || die "${FUNCNAME} is unsupported in EAPI > 5, please use virtx" |
113 |
+ |
114 |
+ # backcompat for maketype |
115 |
+ if [[ -n ${maketype} ]]; then |
116 |
+ [[ ${EAPI} == [45] ]] || die "maketype is banned in EAPI > 5" |
117 |
+ eqawarn "ebuild is exporting \$maketype=${maketype}" |
118 |
+ eqawarn "Ebuild should be migrated to use 'virtx command' instead." |
119 |
+ VIRTUALX_COMMAND=${maketype} |
120 |
+ fi |
121 |
+ |
122 |
+ virtx "${VIRTUALX_COMMAND}" "${@}" |
123 |
+} |
124 |
+ |
125 |
+ |
126 |
+# @FUNCTION: virtx |
127 |
+# @USAGE: <command> [command arguments] |
128 |
+# @DESCRIPTION: |
129 |
+# Start new Xvfb session and run commands in it. |
130 |
+# |
131 |
+# IMPORTANT: The command is run nonfatal !!! |
132 |
+# |
133 |
+# This means we are checking for the return code and raise an exception if it |
134 |
+# isn't 0. So you need to make sure that all commands return a proper |
135 |
+# code and not just die. All eclass function used should support nonfatal |
136 |
+# calls properly. |
137 |
+# |
138 |
+# The rational behind this is the tear down of the started Xfvb session. A |
139 |
+# straight die would leave a running session behind. |
140 |
+# |
141 |
+# Example: |
142 |
+# |
143 |
+# @CODE |
144 |
+# src_test() { |
145 |
+# virtx default |
146 |
+# } |
147 |
+# @CODE |
148 |
+# |
149 |
+# @CODE |
150 |
+# python_test() { |
151 |
+# virtx py.test --verbose |
152 |
+# } |
153 |
+# @CODE |
154 |
+# |
155 |
+# @CODE |
156 |
+# my_test() { |
157 |
+# some_command |
158 |
+# return $? |
159 |
+# } |
160 |
+# |
161 |
+# src_test() { |
162 |
+# virtx my_test |
163 |
+# } |
164 |
+# @CODE |
165 |
+virtx() { |
166 |
+ debug-print-function ${FUNCNAME} "$@" |
167 |
+ |
168 |
+ [[ $# -lt 1 ]] && die "${FUNCNAME} needs at least one argument" |
169 |
+ |
170 |
+ local i=0 |
171 |
+ local retval=0 |
172 |
+ local OLD_SANDBOX_ON="${SANDBOX_ON}" |
173 |
+ local XVFB XHOST XDISPLAY |
174 |
+ local xvfbargs="-screen 0 1280x1024x24 +extension RANDR" |
175 |
+ XVFB=$(type -p Xvfb) || die |
176 |
+ XHOST=$(type -p xhost) || die |
177 |
+ |
178 |
+ debug-print "${FUNCNAME}: running Xvfb hack" |
179 |
+ export XAUTHORITY= |
180 |
+ # The following is derived from Mandrake's hack to allow |
181 |
+ # compiling without the X display |
182 |
+ |
183 |
+ einfo "Scanning for an open DISPLAY to start Xvfb ..." |
184 |
+ # If we are in a chrooted environment, and there is already a |
185 |
+ # X server started outside of the chroot, Xvfb will fail to start |
186 |
+ # on the same display (most cases this is :0 ), so make sure |
187 |
+ # Xvfb is started, else bump the display number |
188 |
+ # |
189 |
+ # Azarah - 5 May 2002 |
190 |
+ XDISPLAY=$(i=0; while [[ -f /tmp/.X${i}-lock ]] ; do ((i++));done; echo ${i}) |
191 |
+ debug-print "${FUNCNAME}: XDISPLAY=${XDISPLAY}" |
192 |
+ |
193 |
+ # We really do not want SANDBOX enabled here |
194 |
+ export SANDBOX_ON="0" |
195 |
+ |
196 |
+ debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}" |
197 |
+ ${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null & |
198 |
+ sleep 2 |
199 |
+ |
200 |
+ local start=${XDISPLAY} |
201 |
+ while [[ ! -f /tmp/.X${XDISPLAY}-lock ]]; do |
202 |
+ # Stop trying after 15 tries |
203 |
+ if ((XDISPLAY - start > 15)) ; then |
204 |
+ eerror "'${XVFB} :${XDISPLAY} ${xvfbargs}' returns:" |
205 |
+ echo |
206 |
+ ${XVFB} :${XDISPLAY} ${xvfbargs} |
207 |
+ echo |
208 |
+ eerror "If possible, correct the above error and try your emerge again." |
209 |
+ die "Unable to start Xvfb" |
210 |
+ fi |
211 |
+ ((XDISPLAY++)) |
212 |
+ debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}" |
213 |
+ ${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null & |
214 |
+ sleep 2 |
215 |
+ done |
216 |
+ |
217 |
+ # Now enable SANDBOX again if needed. |
218 |
+ export SANDBOX_ON="${OLD_SANDBOX_ON}" |
219 |
+ |
220 |
+ einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..." |
221 |
+ |
222 |
+ export DISPLAY=:${XDISPLAY} |
223 |
+ # Do not break on error, but setup $retval, as we need |
224 |
+ # to kill Xvfb |
225 |
+ debug-print "${FUNCNAME}: $@" |
226 |
+ nonfatal "$@" |
227 |
+ retval=$? |
228 |
+ |
229 |
+ # Now kill Xvfb |
230 |
+ kill $(cat /tmp/.X${XDISPLAY}-lock) |
231 |
+ |
232 |
+ # die if our command failed |
233 |
+ [[ ${retval} -ne 0 ]] && die "Failed to run '$@'" |
234 |
+ |
235 |
+ return 0 # always return 0, it can be altered by failed kill for Xvfb |
236 |
+} |
237 |
+ |
238 |
+# @FUNCTION: Xmake |
239 |
+# @DESCRIPTION: |
240 |
+# Same as "make", but set up the Xvfb hack if needed. |
241 |
+# Deprecated call. |
242 |
+Xmake() { |
243 |
+ debug-print-function ${FUNCNAME} "$@" |
244 |
+ |
245 |
+ [[ ${EAPI} == [45] ]] \ |
246 |
+ || die "${FUNCNAME} is unsupported in EAPI > 5, please use 'virtx emake -j1 ....'" |
247 |
+ |
248 |
+ eqawarn "you should not execute make directly" |
249 |
+ eqawarn "rather execute Xemake -j1 if you have issues with parallel make" |
250 |
+ VIRTUALX_COMMAND="emake -j1" virtualmake "$@" |
251 |
+} |
252 |
+ |
253 |
+# @FUNCTION: Xemake |
254 |
+# @DESCRIPTION: |
255 |
+# Same as "emake", but set up the Xvfb hack if needed. |
256 |
+Xemake() { |
257 |
+ debug-print-function ${FUNCNAME} "$@" |
258 |
+ |
259 |
+ [[ ${EAPI} == [45] ]] \ |
260 |
+ || die "${FUNCNAME} is unsupported in EAPI > 5, please use 'virtx emake ....'" |
261 |
+ |
262 |
+ VIRTUALX_COMMAND="emake" virtualmake "$@" |
263 |
+} |
264 |
+ |
265 |
+# @FUNCTION: Xeconf |
266 |
+# @DESCRIPTION: |
267 |
+# Same as "econf", but set up the Xvfb hack if needed. |
268 |
+Xeconf() { |
269 |
+ debug-print-function ${FUNCNAME} "$@" |
270 |
+ |
271 |
+ [[ ${EAPI} == [45] ]] \ |
272 |
+ || die "${FUNCNAME} is unsupported in EAPI > 5, please use 'virtx econf ....'" |
273 |
+ |
274 |
+ VIRTUALX_COMMAND="econf" virtualmake "$@" |
275 |
+} |
276 |
+ |
277 |
+_VIRTUAL_X=1 |
278 |
+fi |