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

Diff of /eclass/virtualx.eclass

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

Revision 1.8 Revision 1.36
1# Copyright 1999-2002 Gentoo Technologies, Inc. 1# Copyright 1999-2010 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License, v2 or later 2# Distributed under the terms of the GNU General Public License v2
3# Author: Martin Schlemmer <azarah@gentoo.org>
4# $Header: /var/cvsroot/gentoo-x86/eclass/virtualx.eclass,v 1.8 2002/09/11 17:22:02 azarah Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/virtualx.eclass,v 1.36 2011/03/09 13:31:51 scarabeus Exp $
5# This eclass can be used for packages that needs a working X environment to build
6ECLASS=virtualx
7INHERITED="$INHERITED $ECLASS"
8newdepend virtual/x11
9 4
10DESCRIPTION="Based on the $ECLASS eclass" 5# Original author: Martin Schlemmer <azarah@gentoo.org>
11 6
12[ -z "${SANDBOX_DISABLED}" ] && export SANDBOX_DISABLED="0" || : 7# @ECLASS: virtualx.eclass
8# @MAINTAINER:
9# x11@gentoo.org
10# @BLURB: This eclass can be used for packages that needs a working X environment to build.
13 11
12# @ECLASS-VARIABLE: VIRTUALX_REQUIRED
13# @DESCRIPTION:
14# 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
22# @ECLASS-VARIABLE: VIRTUALX_DEPEND
23# @DESCRIPTION:
24# 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.
27VIRTUALX_DEPEND="${VIRTUALX_DEPEND}
28 !prefix? ( x11-base/xorg-server[-minimal] )
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."
39
40case ${VIRTUALX_REQUIRED} in
41 manual)
42 ;;
43 always)
44 DEPEND="${VIRTUALX_DEPEND}"
45 RDEPEND=""
46 ;;
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"
61 DEPEND="${VIRTUALX_USE}? ( ${VIRTUALX_DEPEND} )"
62 RDEPEND=""
63 IUSE="${VIRTUALX_USE}"
64 ;;
65 *)
66 DEPEND="${VIRTUALX_REQUIRED}? ( ${VIRTUALX_DEPEND} )"
67 RDEPEND=""
68 IUSE="${VIRTUALX_REQUIRED}"
69 ;;
70esac
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.
14virtualmake() { 76virtualmake() {
77 debug-print-function ${FUNCNAME} "$@"
78
79 local i=0
15 local retval=0 80 local retval=0
16 local OLD_SANDBOX_DISABLED="${SANDBOX_DISABLED}" 81 local OLD_SANDBOX_ON="${SANDBOX_ON}"
82 local XVFB=$(type -p Xvfb)
83 local XHOST=$(type -p xhost)
84 local xvfbargs="-screen 0 800x600x24"
17 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
93
18 #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
19 #display, then do the Xvfb hack. 95 # display, then do the Xvfb hack.
20 if [ -z "$DISPLAY" ] || ! (/usr/X11R6/bin/xhost &>/dev/null) 96 if [[ -n ${XVFB} && -n ${XHOST} ]] && \
21 then 97 ( [[ -z ${DISPLAY} ]] || ! (${XHOST} &>/dev/null) ) ; then
98 debug-print "${FUNCNAME}: running Xvfb hack"
22 export XAUTHORITY= 99 export XAUTHORITY=
23 # The following is derived from Mandrake's hack to allow 100 # The following is derived from Mandrake's hack to allow
24 # compiling without the X display 101 # compiling without the X display
25 102
26 einfo "Scanning for a open DISPLAY to start Xvfb..." 103 einfo "Scanning for an open DISPLAY to start Xvfb ..."
27
28 # We really do not want SANDBOX enabled here
29 export SANDBOX_DISABLED="1"
30
31 local i=0
32 XDISPLAY=$(i=0; while [ -f /tmp/.X${i}-lock ] ; do i=$((${i}+1));done; echo ${i})
33
34 # 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
35 # 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
36 # 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
37 # Xvfb is started, else bump the display number 107 # Xvfb is started, else bump the display number
38 # 108 #
39 # Azarah - 5 May 2002 109 # Azarah - 5 May 2002
40 # 110 XDISPLAY=$(i=0; while [[ -f /tmp/.X${i}-lock ]] ; do ((i++));done; echo ${i})
41 /usr/X11R6/bin/Xvfb :${XDISPLAY} -screen 0 800x600x32 &>/dev/null & 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 &
42 sleep 2 118 sleep 2
43 119
120 local start=${XDISPLAY}
44 while [ ! -f /tmp/.X${XDISPLAY}-lock ] 121 while [[ ! -f /tmp/.X${XDISPLAY}-lock ]]; do
45 do 122 # Stop trying after 15 tries
46 XDISPLAY=$((${XDISPLAY}+1)) 123 if ((XDISPLAY - start > 15)) ; then
47 /usr/X11R6/bin/Xvfb :${XDISPLAY} -screen 0 800x600x32 &>/dev/null & 124 eerror "'${XVFB} :${XDISPLAY} ${xvfbargs}' returns:"
125 echo
126 ${XVFB} :${XDISPLAY} ${xvfbargs}
127 echo
128 eerror "If possible, correct the above error and try your emerge again."
129 die "Unable to start Xvfb"
130 fi
131
132 ((XDISPLAY++))
133 debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}"
134 ${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null &
48 sleep 2 135 sleep 2
49 done 136 done
50 137
51 # Now enable SANDBOX again if needed. 138 # Now enable SANDBOX again if needed.
52 export SANDBOX_DISABLED="${OLD_SANDBOX_DISABLED}" 139 export SANDBOX_ON="${OLD_SANDBOX_ON}"
53 140
54 einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..." 141 einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..."
55 142
56 export DISPLAY=:${XDISPLAY} 143 export DISPLAY=:${XDISPLAY}
57 #Do not break on error, but setup $retval, as we need 144 # Do not break on error, but setup $retval, as we need
58 #to kill Xvfb 145 # to kill Xvfb
59 ${maketype} $* 146 debug-print "${FUNCNAME}: ${VIRTUALX_COMMAND} \"$@\""
147 ${VIRTUALX_COMMAND} "$@"
60 retval=$? 148 retval=$?
61 149
62 #Now kill Xvfb 150 # Now kill Xvfb
63 kill $(cat /tmp/.X${XDISPLAY}-lock) 151 kill $(cat /tmp/.X${XDISPLAY}-lock)
64 else 152 else
153 debug-print "${FUNCNAME}: attaching to running X display"
65 #Normal make if we can connect to an X display 154 # Normal make if we can connect to an X display
66 ${maketype} $* 155 debug-print "${FUNCNAME}: ${VIRTUALX_COMMAND} \"$@\""
156 ${VIRTUALX_COMMAND} "$@"
67 retval=$? 157 retval=$?
68 fi 158 fi
69 159
70 return $retval 160 # die if our command failed
161 [[ $? -ne 0 ]] && die "${FUNCNAME}: the ${VIRTALX_COMMAND} failed."
71} 162}
72 163
164# @FUNCTION: Xmake
165# @DESCRIPTION:
73#Same as "make", but setup the Xvfb hack if needed 166# Same as "make", but set up the Xvfb hack if needed.
167# Deprecated call.
74Xmake() { 168Xmake() {
75 export maketype="make" 169 debug-print-function ${FUNCNAME} "$@"
76 virtualmake "$*" 170
171 ewarn "QA: you should not execute make directly"
172 ewarn "QA: rather execute Xemake -j1 if you have issues with parallel make"
173 VIRTUALX_COMMAND="emake -j1" virtualmake "$@"
77} 174}
78 175
176# @FUNCTION: Xemake
177# @DESCRIPTION:
79#Same as "emake", but setup the Xvfb hack if needed 178# Same as "emake", but set up the Xvfb hack if needed.
80Xemake() { 179Xemake() {
81 export maketype="emake" 180 debug-print-function ${FUNCNAME} "$@"
82 virtualmake "$*" 181
182 VIRTUALX_COMMAND="emake" virtualmake "$@"
83} 183}
84 184
185# @FUNCTION: Xeconf
186# @DESCRIPTION:
187# Same as "econf", but set up the Xvfb hack if needed.
188Xeconf() {
189 debug-print-function ${FUNCNAME} "$@"
190
191 VIRTUALX_COMMAND="econf" virtualmake "$@"
192}

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.36

  ViewVC Help
Powered by ViewVC 1.1.20