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

Diff of /eclass/virtualx.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.35 Revision 1.38
1# Copyright 1999-2010 Gentoo Foundation 1# Copyright 1999-2010 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/virtualx.eclass,v 1.35 2010/05/15 05:40:46 dirtyepic Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/virtualx.eclass,v 1.38 2011/03/13 19:37:28 scarabeus Exp $
4 4
5# Original author: Martin Schlemmer <azarah@gentoo.org> 5# Original author: Martin Schlemmer <azarah@gentoo.org>
6 6
7# @ECLASS: virtualx.eclass 7# @ECLASS: virtualx.eclass
8# @MAINTAINER: 8# @MAINTAINER:
9# x11@gentoo.org 9# x11@gentoo.org
10# @BLURB: This eclass can be used for packages that needs a working X environment to build. 10# @BLURB: This eclass can be used for packages that needs a working X environment to build.
11 11
12# @ECLASS-VARIABLE: VIRTUALX_REQUIRED 12# @ECLASS-VARIABLE: VIRTUALX_REQUIRED
13# @DESCRIPTION: 13# @DESCRIPTION:
14# Is a dependency on xorg-server and xhost needed? 14# Variable specifying the dependency on xorg-server and xhost.
15# Valid values are "always", "optional", and "manual". 15# Possible special values are "always" and "manual", which specify
16# "tests" is a synonym for "optional". 16# the dependency to be set unconditionaly or not at all.
17: ${VIRTUALX_REQUIRED:=optional} 17# Any other value is taken as useflag desired to be in control of
18 18# the dependency (eg. VIRTUALX_REQUIRED="kde" will add the dependency
19# @ECLASS-VARIABLE: VIRTUALX_USE 19# into "kde? ( )" and add kde into IUSE.
20# @DESCRIPTION:
21# If VIRTUALX_REQUIRED=optional, what USE flag should control
22# the dependency?
23: ${VIRTUALX_USE:=test} 20: ${VIRTUALX_REQUIRED:=test}
24 21
25# @ECLASS-VARIABLE: VIRTUALX_DEPEND 22# @ECLASS-VARIABLE: VIRTUALX_DEPEND
26# @DESCRIPTION: 23# @DESCRIPTION:
27# Dep string available for use outside of eclass, in case a more 24# Dep string available for use outside of eclass, in case a more
28# complicated dep is needed. 25# complicated dep is needed.
29VIRTUALX_DEPEND="!prefix? ( x11-base/xorg-server ) 26# You can specify the variable BEFORE inherit to add more dependencies.
27VIRTUALX_DEPEND="${VIRTUALX_DEPEND}
28 !prefix? ( x11-base/xorg-server[-minimal] )
30 x11-apps/xhost" 29 x11-apps/xhost
30"
31
32# @ECLASS-VARIABLE: VIRTUALX_COMMAND
33# @DESCRIPTION:
34# Command (or eclass function call) to be run in the X11 environment
35# (within virtualmake function).
36: ${VIRTUALX_COMMAND:="emake"}
37
38has "${EAPI:-0}" 0 1 && die "virtualx eclass require EAPI=2 or newer."
31 39
32case ${VIRTUALX_REQUIRED} in 40case ${VIRTUALX_REQUIRED} in
41 manual)
42 ;;
33 always) 43 always)
34 DEPEND="${VIRTUALX_DEPEND}" 44 DEPEND="${VIRTUALX_DEPEND}"
35 RDEPEND="" 45 RDEPEND=""
36 ;; 46 ;;
37 optional|tests) 47 optional|tests)
48 # 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"
38 DEPEND="${VIRTUALX_USE}? ( ${VIRTUALX_DEPEND} )" 61 DEPEND="${VIRTUALX_USE}? ( ${VIRTUALX_DEPEND} )"
39 RDEPEND="" 62 RDEPEND=""
40 IUSE="${VIRTUALX_USE}" 63 IUSE="${VIRTUALX_USE}"
41 ;; 64 ;;
42 manual)
43 ;;
44 *) 65 *)
45 eerror "Invalid value (${VIRTUALX_REQUIRED}) for VIRTUALX_REQUIRED" 66 DEPEND="${VIRTUALX_REQUIRED}? ( ${VIRTUALX_DEPEND} )"
46 eerror "Valid values are:" 67 RDEPEND=""
47 eerror " always" 68 IUSE="${VIRTUALX_REQUIRED}"
48 eerror " optional (default if unset)"
49 eerror " manual"
50 die "Invalid value (${VIRTUALX_REQUIRED}) for VIRTUALX_REQUIRED"
51 ;; 69 ;;
52esac 70esac
53 71
72# @FUNCTION: virtualmake
73# @DESCRIPTION:
74# Function which attach to running X session or start new Xvfb session
75# where the VIRTUALX_COMMAND variable content gets executed.
54virtualmake() { 76virtualmake() {
77 debug-print-function ${FUNCNAME} "$@"
78
79 local i=0
55 local retval=0 80 local retval=0
56 local OLD_SANDBOX_ON="${SANDBOX_ON}" 81 local OLD_SANDBOX_ON="${SANDBOX_ON}"
57 local XVFB=$(type -p Xvfb) 82 local XVFB=$(type -p Xvfb)
58 local XHOST=$(type -p xhost) 83 local XHOST=$(type -p xhost)
84 local xvfbargs="-screen 0 800x600x24"
85
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
59 93
60 # If $DISPLAY is not set, or xhost cannot connect to an X 94 # If $DISPLAY is not set, or xhost cannot connect to an X
61 # display, then do the Xvfb hack. 95 # display, then do the Xvfb hack.
62 if [[ -n ${XVFB} && -n ${XHOST} ]] && \ 96 if [[ -n ${XVFB} && -n ${XHOST} ]] && \
63 ( [[ -z ${DISPLAY} ]] || ! (${XHOST} &>/dev/null) ) ; then 97 ( [[ -z ${DISPLAY} ]] || ! (${XHOST} &>/dev/null) ) ; then
98 debug-print "${FUNCNAME}: running Xvfb hack"
64 export XAUTHORITY= 99 export XAUTHORITY=
65 # The following is derived from Mandrake's hack to allow 100 # The following is derived from Mandrake's hack to allow
66 # compiling without the X display 101 # compiling without the X display
67 102
68 einfo "Scanning for an open DISPLAY to start Xvfb ..." 103 einfo "Scanning for an open DISPLAY to start Xvfb ..."
69
70 # We really do not want SANDBOX enabled here
71 export SANDBOX_ON="0"
72
73 local i=0
74 XDISPLAY=$(i=0; while [[ -f /tmp/.X${i}-lock ]] ; do ((i++));done; echo ${i})
75
76 # If we are in a chrooted environment, and there is already a 104 # If we are in a chrooted environment, and there is already a
77 # X server started outside of the chroot, Xvfb will fail to start 105 # X server started outside of the chroot, Xvfb will fail to start
78 # on the same display (most cases this is :0 ), so make sure 106 # on the same display (most cases this is :0 ), so make sure
79 # Xvfb is started, else bump the display number 107 # Xvfb is started, else bump the display number
80 # 108 #
81 # Azarah - 5 May 2002 109 # Azarah - 5 May 2002
82 # 110 XDISPLAY=$(i=0; while [[ -f /tmp/.X${i}-lock ]] ; do ((i++));done; echo ${i})
83 # Changed the mode from 800x600x32 to 800x600x24 because the mfb 111 debug-print "${FUNCNAME}: XDISPLAY=${XDISPLAY}"
84 # support has been dropped in Xvfb in the xorg-x11 pre-releases. 112
85 # For now only depths up to 24-bit are supported. 113 # We really do not want SANDBOX enabled here
86 # 114 export SANDBOX_ON="0"
87 # Sven Wegener <swegener@gentoo.org> - 22 Aug 2004 115
88 # 116 debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}"
89 # Use "-fp built-ins" because it's only part of the default font path 117 ${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null &
90 # for Xorg but not the other DDXs (Xvfb, Kdrive, etc). Temporarily fixes
91 # bug 278487 until xorg-server is properly patched
92 #
93 # RĂ©mi Cardona <remi@gentoo.org> (10 Aug 2009)
94 ${XVFB} :${XDISPLAY} -fp built-ins -screen 0 800x600x24 &>/dev/null &
95 sleep 2 118 sleep 2
96 119
97 local start=${XDISPLAY} 120 local start=${XDISPLAY}
98 while [[ ! -f /tmp/.X${XDISPLAY}-lock ]] ; do 121 while [[ ! -f /tmp/.X${XDISPLAY}-lock ]]; do
99 # Stop trying after 15 tries 122 # Stop trying after 15 tries
100 if ((XDISPLAY - start > 15)) ; then 123 if ((XDISPLAY - start > 15)) ; then
101 124 eerror "'${XVFB} :${XDISPLAY} ${xvfbargs}' returns:"
102 eerror "" 125 echo
103 eerror "Unable to start Xvfb." 126 ${XVFB} :${XDISPLAY} ${xvfbargs}
104 eerror "" 127 echo
105 eerror "'${XVFB} :${XDISPLAY} -fp built-ins -screen 0 800x600x24' returns:"
106 eerror ""
107 ${XVFB} :${XDISPLAY} -fp built-ins -screen 0 800x600x24
108 eerror ""
109 eerror "If possible, correct the above error and try your emerge again." 128 eerror "If possible, correct the above error and try your emerge again."
110 eerror "" 129 die "Unable to start Xvfb"
111 die
112 fi 130 fi
113 131
114 ((XDISPLAY++)) 132 ((XDISPLAY++))
115 ${XVFB} :${XDISPLAY} -fp built-ins -screen 0 800x600x24 &>/dev/null & 133 debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}"
134 ${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null &
116 sleep 2 135 sleep 2
117 done 136 done
118 137
119 # Now enable SANDBOX again if needed. 138 # Now enable SANDBOX again if needed.
120 export SANDBOX_ON="${OLD_SANDBOX_ON}" 139 export SANDBOX_ON="${OLD_SANDBOX_ON}"
121 140
122 einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..." 141 einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..."
123 142
124 export DISPLAY=:${XDISPLAY} 143 export DISPLAY=:${XDISPLAY}
125 #Do not break on error, but setup $retval, as we need 144 # Do not break on error, but setup $retval, as we need
126 #to kill Xvfb 145 # to kill Xvfb
127 ${maketype} "$@" 146 debug-print "${FUNCNAME}: ${VIRTUALX_COMMAND} \"$@\""
147 ${VIRTUALX_COMMAND} "$@"
128 retval=$? 148 retval=$?
129 149
130 #Now kill Xvfb 150 # Now kill Xvfb
131 kill $(cat /tmp/.X${XDISPLAY}-lock) 151 kill $(cat /tmp/.X${XDISPLAY}-lock)
132 else 152 else
153 debug-print "${FUNCNAME}: attaching to running X display"
133 #Normal make if we can connect to an X display 154 # Normal make if we can connect to an X display
134 ${maketype} "$@" 155 debug-print "${FUNCNAME}: ${VIRTUALX_COMMAND} \"$@\""
156 ${VIRTUALX_COMMAND} "$@"
135 retval=$? 157 retval=$?
136 fi 158 fi
137 159
138 return ${retval} 160 # die if our command failed
161 [[ ${retval} -ne 0 ]] && die "${FUNCNAME}: the ${VIRTUALX_COMMAND} failed."
162
163 return 0 # always return 0, it can be altered by failed kill for Xvfb
139} 164}
140 165
141# @FUNCTION: Xmake 166# @FUNCTION: Xmake
142# @DESCRIPTION: 167# @DESCRIPTION:
143# Same as "make", but set up the Xvfb hack if needed. 168# Same as "make", but set up the Xvfb hack if needed.
169# Deprecated call.
144Xmake() { 170Xmake() {
145 export maketype="make" 171 debug-print-function ${FUNCNAME} "$@"
146 virtualmake "$@" 172
173 ewarn "QA: you should not execute make directly"
174 ewarn "QA: rather execute Xemake -j1 if you have issues with parallel make"
175 VIRTUALX_COMMAND="emake -j1" virtualmake "$@"
147} 176}
148 177
149# @FUNCTION: Xemake 178# @FUNCTION: Xemake
150# @DESCRIPTION: 179# @DESCRIPTION:
151# Same as "emake", but set up the Xvfb hack if needed. 180# Same as "emake", but set up the Xvfb hack if needed.
152Xemake() { 181Xemake() {
153 export maketype="emake" 182 debug-print-function ${FUNCNAME} "$@"
154 virtualmake "$@" 183
184 VIRTUALX_COMMAND="emake" virtualmake "$@"
155} 185}
156 186
157# @FUNCTION: Xeconf 187# @FUNCTION: Xeconf
158# @DESCRIPTION: 188# @DESCRIPTION:
159# Same as "econf", but set up the Xvfb hack if needed. 189# Same as "econf", but set up the Xvfb hack if needed.
160Xeconf() { 190Xeconf() {
161 export maketype="econf" 191 debug-print-function ${FUNCNAME} "$@"
162 virtualmake "$@" 192
193 VIRTUALX_COMMAND="econf" virtualmake "$@"
163} 194}

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.38

  ViewVC Help
Powered by ViewVC 1.1.20