/[gentoo-x86]/eclass/virtualx.eclass
Gentoo

Contents of /eclass/virtualx.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.43 - (hide annotations) (download)
Wed Oct 3 22:47:12 2012 UTC (18 months, 2 weeks ago) by chithanh
Branch: MAIN
CVS Tags: HEAD
Changes since 1.42: +8 -3 lines
Unbreak EAPI=2 and 3 users of virtualx.eclass, bug #406353

1 chithanh 1.41 # Copyright 1999-2012 Gentoo Foundation
2 vapier 1.9 # Distributed under the terms of the GNU General Public License v2
3 chithanh 1.43 # $Header: /var/cvsroot/gentoo-x86/eclass/virtualx.eclass,v 1.42 2012/10/02 08:14:36 kensington Exp $
4 dirtyepic 1.35
5     # @ECLASS: virtualx.eclass
6     # @MAINTAINER:
7 scarabeus 1.36 # x11@gentoo.org
8 vapier 1.40 # @AUTHOR:
9     # Original author: Martin Schlemmer <azarah@gentoo.org>
10 dirtyepic 1.35 # @BLURB: This eclass can be used for packages that needs a working X environment to build.
11    
12     # @ECLASS-VARIABLE: VIRTUALX_REQUIRED
13     # @DESCRIPTION:
14 scarabeus 1.36 # Variable specifying the dependency on xorg-server and xhost.
15     # Possible special values are "always" and "manual", which specify
16     # the dependency to be set unconditionaly or not at all.
17     # Any other value is taken as useflag desired to be in control of
18     # the dependency (eg. VIRTUALX_REQUIRED="kde" will add the dependency
19     # into "kde? ( )" and add kde into IUSE.
20     : ${VIRTUALX_REQUIRED:=test}
21 abcd 1.32
22 scarabeus 1.36 # @ECLASS-VARIABLE: VIRTUALX_DEPEND
23 dirtyepic 1.35 # @DESCRIPTION:
24 scarabeus 1.36 # Dep string available for use outside of eclass, in case a more
25     # complicated dep is needed.
26     # You can specify the variable BEFORE inherit to add more dependencies.
27     VIRTUALX_DEPEND="${VIRTUALX_DEPEND}
28 mattst88 1.39 !prefix? ( x11-base/xorg-server[xvfb] )
29 scarabeus 1.36 x11-apps/xhost
30     "
31 abcd 1.30
32 scarabeus 1.36 # @ECLASS-VARIABLE: VIRTUALX_COMMAND
33 dirtyepic 1.35 # @DESCRIPTION:
34 scarabeus 1.36 # Command (or eclass function call) to be run in the X11 environment
35     # (within virtualmake function).
36     : ${VIRTUALX_COMMAND:="emake"}
37    
38     has "${EAPI:-0}" 0 1 && die "virtualx eclass require EAPI=2 or newer."
39 abcd 1.30
40     case ${VIRTUALX_REQUIRED} in
41 scarabeus 1.36 manual)
42     ;;
43 abcd 1.30 always)
44     DEPEND="${VIRTUALX_DEPEND}"
45     RDEPEND=""
46     ;;
47 abcd 1.32 optional|tests)
48 scarabeus 1.36 # deprecated section YAY.
49     ewarn "QA: VIRTUALX_REQUIRED=optional and VIRTUALX_REQUIRED=tests are deprecated."
50     ewarn "QA: You can drop the variable definition completely from ebuild,"
51     ewarn "QA: because it is default behaviour."
52    
53     if [[ -n ${VIRTUALX_USE} ]]; then
54     # so they like to specify the useflag
55     ewarn "QA: VIRTUALX_USE variable is deprecated."
56     ewarn "QA: Please read eclass manpage to find out how to use VIRTUALX_REQUIRED"
57     ewarn "QA: to achieve the same behaviour."
58     fi
59    
60     [[ -z ${VIRTUALX_USE} ]] && VIRTUALX_USE="test"
61 abcd 1.32 DEPEND="${VIRTUALX_USE}? ( ${VIRTUALX_DEPEND} )"
62 abcd 1.30 RDEPEND=""
63 abcd 1.32 IUSE="${VIRTUALX_USE}"
64 abcd 1.30 ;;
65     *)
66 scarabeus 1.36 DEPEND="${VIRTUALX_REQUIRED}? ( ${VIRTUALX_DEPEND} )"
67     RDEPEND=""
68     IUSE="${VIRTUALX_REQUIRED}"
69 abcd 1.30 ;;
70     esac
71 azarah 1.1
72 scarabeus 1.36 # @FUNCTION: virtualmake
73 vapier 1.40 # @DESCRIPTION:
74 scarabeus 1.36 # Function which attach to running X session or start new Xvfb session
75     # where the VIRTUALX_COMMAND variable content gets executed.
76 azarah 1.1 virtualmake() {
77 scarabeus 1.36 debug-print-function ${FUNCNAME} "$@"
78    
79     local i=0
80 azarah 1.1 local retval=0
81 abcd 1.33 local OLD_SANDBOX_ON="${SANDBOX_ON}"
82 azarah 1.20 local XVFB=$(type -p Xvfb)
83     local XHOST=$(type -p xhost)
84 chithanh 1.41 local xvfbargs="-screen 0 1280x1024x24"
85 scarabeus 1.36
86     # backcompat for maketype
87     if [[ -n ${maketype} ]]; then
88     ewarn "QA: ebuild is exporting \$maketype=${maketype}"
89     ewarn "QA: Ebuild should be migrated to use VIRTUALX_COMMAND=${maketype} instead."
90     ewarn "QA: Setting VIRTUALX_COMMAND to \$maketype conveniently for now."
91     VIRTUALX_COMMAND=${maketype}
92     fi
93 azarah 1.1
94 azarah 1.20 # If $DISPLAY is not set, or xhost cannot connect to an X
95     # display, then do the Xvfb hack.
96     if [[ -n ${XVFB} && -n ${XHOST} ]] && \
97 scarabeus 1.36 ( [[ -z ${DISPLAY} ]] || ! (${XHOST} &>/dev/null) ) ; then
98     debug-print "${FUNCNAME}: running Xvfb hack"
99 azarah 1.3 export XAUTHORITY=
100 azarah 1.4 # The following is derived from Mandrake's hack to allow
101     # compiling without the X display
102    
103 seemant 1.25 einfo "Scanning for an open DISPLAY to start Xvfb ..."
104 azarah 1.5 # If we are in a chrooted environment, and there is already a
105     # X server started outside of the chroot, Xvfb will fail to start
106     # on the same display (most cases this is :0 ), so make sure
107     # Xvfb is started, else bump the display number
108     #
109     # Azarah - 5 May 2002
110 scarabeus 1.36 XDISPLAY=$(i=0; while [[ -f /tmp/.X${i}-lock ]] ; do ((i++));done; echo ${i})
111     debug-print "${FUNCNAME}: XDISPLAY=${XDISPLAY}"
112    
113     # We really do not want SANDBOX enabled here
114     export SANDBOX_ON="0"
115    
116     debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}"
117     ${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null &
118 azarah 1.5 sleep 2
119 swegener 1.23
120 jrray 1.10 local start=${XDISPLAY}
121 scarabeus 1.36 while [[ ! -f /tmp/.X${XDISPLAY}-lock ]]; do
122 jrray 1.10 # Stop trying after 15 tries
123 abcd 1.30 if ((XDISPLAY - start > 15)) ; then
124 scarabeus 1.36 eerror "'${XVFB} :${XDISPLAY} ${xvfbargs}' returns:"
125     echo
126     ${XVFB} :${XDISPLAY} ${xvfbargs}
127     echo
128 jrray 1.10 eerror "If possible, correct the above error and try your emerge again."
129 scarabeus 1.36 die "Unable to start Xvfb"
130 jrray 1.10 fi
131    
132 abcd 1.30 ((XDISPLAY++))
133 scarabeus 1.36 debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}"
134     ${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null &
135 azarah 1.5 sleep 2
136     done
137    
138 azarah 1.8 # Now enable SANDBOX again if needed.
139 abcd 1.33 export SANDBOX_ON="${OLD_SANDBOX_ON}"
140 azarah 1.8
141 azarah 1.6 einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..."
142 swegener 1.23
143 azarah 1.1 export DISPLAY=:${XDISPLAY}
144 scarabeus 1.36 # Do not break on error, but setup $retval, as we need
145     # to kill Xvfb
146     debug-print "${FUNCNAME}: ${VIRTUALX_COMMAND} \"$@\""
147 chithanh 1.43 if has "${EAPI}" 2 3; then
148     ${VIRTUALX_COMMAND} "$@"
149     retval=$?
150     else
151     nonfatal ${VIRTUALX_COMMAND} "$@"
152     retval=$?
153     fi
154 azarah 1.1
155 scarabeus 1.36 # Now kill Xvfb
156 azarah 1.1 kill $(cat /tmp/.X${XDISPLAY}-lock)
157     else
158 scarabeus 1.36 debug-print "${FUNCNAME}: attaching to running X display"
159     # Normal make if we can connect to an X display
160     debug-print "${FUNCNAME}: ${VIRTUALX_COMMAND} \"$@\""
161     ${VIRTUALX_COMMAND} "$@"
162 azarah 1.1 retval=$?
163     fi
164 azarah 1.8
165 scarabeus 1.36 # die if our command failed
166 scarabeus 1.37 [[ ${retval} -ne 0 ]] && die "${FUNCNAME}: the ${VIRTUALX_COMMAND} failed."
167 scarabeus 1.38
168     return 0 # always return 0, it can be altered by failed kill for Xvfb
169 azarah 1.1 }
170    
171 dirtyepic 1.35 # @FUNCTION: Xmake
172 vapier 1.40 # @DESCRIPTION:
173 scarabeus 1.36 # Same as "make", but set up the Xvfb hack if needed.
174     # Deprecated call.
175 azarah 1.2 Xmake() {
176 scarabeus 1.36 debug-print-function ${FUNCNAME} "$@"
177    
178     ewarn "QA: you should not execute make directly"
179     ewarn "QA: rather execute Xemake -j1 if you have issues with parallel make"
180     VIRTUALX_COMMAND="emake -j1" virtualmake "$@"
181 azarah 1.1 }
182    
183 dirtyepic 1.35 # @FUNCTION: Xemake
184 vapier 1.40 # @DESCRIPTION:
185 scarabeus 1.36 # Same as "emake", but set up the Xvfb hack if needed.
186 azarah 1.2 Xemake() {
187 scarabeus 1.36 debug-print-function ${FUNCNAME} "$@"
188    
189     VIRTUALX_COMMAND="emake" virtualmake "$@"
190 azarah 1.1 }
191    
192 dirtyepic 1.35 # @FUNCTION: Xeconf
193 vapier 1.40 # @DESCRIPTION:
194     # Same as "econf", but set up the Xvfb hack if needed.
195 jje 1.14 Xeconf() {
196 scarabeus 1.36 debug-print-function ${FUNCNAME} "$@"
197    
198     VIRTUALX_COMMAND="econf" virtualmake "$@"
199 jje 1.14 }

  ViewVC Help
Powered by ViewVC 1.1.20