| 1 | # Copyright 1999-2004 Gentoo Foundation |
1 | # Copyright 1999-2009 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.29 2009/08/10 15:44:37 remi Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/virtualx.eclass,v 1.33 2009/12/21 17:27:28 abcd Exp $ |
| 4 | # |
4 | # |
| 5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
| 6 | # |
6 | # |
| 7 | # This eclass can be used for packages that needs a working X environment to build |
7 | # This eclass can be used for packages that needs a working X environment to build |
| 8 | |
8 | |
| 9 | DEPEND="X? ( x11-base/xorg-server x11-apps/xhost )" |
9 | # Is a dependency on xorg-server and xhost needed? |
| 10 | IUSE="X" |
10 | # Valid values are "always", "optional", and "manual" |
|
|
11 | # "tests" is treated as a synonym for "optional" |
|
|
12 | : ${VIRTUALX_REQUIRED:=optional} |
|
|
13 | |
|
|
14 | # If VIRTUALX_REQUIRED=optional, what use flag should control |
|
|
15 | # the dependency? Default is "test" |
|
|
16 | : ${VIRTUALX_USE:=test} |
|
|
17 | |
|
|
18 | # Dep string available for use outside of eclass, in case a more |
|
|
19 | # complicated dep is needed |
|
|
20 | VIRTUALX_DEPEND="x11-base/xorg-server |
|
|
21 | x11-apps/xhost" |
|
|
22 | |
|
|
23 | case ${VIRTUALX_REQUIRED} in |
|
|
24 | always) |
|
|
25 | DEPEND="${VIRTUALX_DEPEND}" |
|
|
26 | RDEPEND="" |
|
|
27 | ;; |
|
|
28 | optional|tests) |
|
|
29 | DEPEND="${VIRTUALX_USE}? ( ${VIRTUALX_DEPEND} )" |
|
|
30 | RDEPEND="" |
|
|
31 | IUSE="${VIRTUALX_USE}" |
|
|
32 | ;; |
|
|
33 | manual) |
|
|
34 | ;; |
|
|
35 | *) |
|
|
36 | eerror "Invalid value (${VIRTUALX_REQUIRED}) for VIRTUALX_REQUIRED" |
|
|
37 | eerror "Valid values are:" |
|
|
38 | eerror " always" |
|
|
39 | eerror " optional (default if unset)" |
|
|
40 | eerror " manual" |
|
|
41 | die "Invalid value (${VIRTUALX_REQUIRED}) for VIRTUALX_REQUIRED" |
|
|
42 | ;; |
|
|
43 | esac |
| 11 | |
44 | |
| 12 | DESCRIPTION="Based on the $ECLASS eclass" |
45 | DESCRIPTION="Based on the $ECLASS eclass" |
| 13 | |
46 | |
| 14 | # |
|
|
| 15 | # Brian Harring <ferringb@gentoo.org> 11/04/2004 |
|
|
| 16 | # do not disable the sandbox during the depend phase. |
|
|
| 17 | # ebuilds shouldn't touch the fs during depend phase, nor screw with the sandbox. |
|
|
| 18 | # |
|
|
| 19 | if [[ ${EBUILD_PHASE/depend} == "${EBUILD_PHASE}" ]] ; then |
|
|
| 20 | [[ -z ${SANDBOX_DISABLED} ]] && export SANDBOX_DISABLED="0" || : |
|
|
| 21 | fi |
|
|
| 22 | |
|
|
| 23 | virtualmake() { |
47 | virtualmake() { |
| 24 | local retval=0 |
48 | local retval=0 |
| 25 | local OLD_SANDBOX_DISABLED="${SANDBOX_DISABLED}" |
49 | local OLD_SANDBOX_ON="${SANDBOX_ON}" |
| 26 | local XVFB=$(type -p Xvfb) |
50 | local XVFB=$(type -p Xvfb) |
| 27 | local XHOST=$(type -p xhost) |
51 | local XHOST=$(type -p xhost) |
| 28 | |
52 | |
| 29 | # If $DISPLAY is not set, or xhost cannot connect to an X |
53 | # If $DISPLAY is not set, or xhost cannot connect to an X |
| 30 | # display, then do the Xvfb hack. |
54 | # display, then do the Xvfb hack. |
| … | |
… | |
| 35 | # compiling without the X display |
59 | # compiling without the X display |
| 36 | |
60 | |
| 37 | einfo "Scanning for an open DISPLAY to start Xvfb ..." |
61 | einfo "Scanning for an open DISPLAY to start Xvfb ..." |
| 38 | |
62 | |
| 39 | # We really do not want SANDBOX enabled here |
63 | # We really do not want SANDBOX enabled here |
| 40 | export SANDBOX_DISABLED="1" |
64 | export SANDBOX_ON="0" |
| 41 | |
65 | |
| 42 | local i=0 |
66 | local i=0 |
| 43 | XDISPLAY=$(i=0; while [[ -f /tmp/.X${i}-lock ]] ; do i=$((${i}+1));done; echo ${i}) |
67 | XDISPLAY=$(i=0; while [[ -f /tmp/.X${i}-lock ]] ; do ((i++));done; echo ${i}) |
| 44 | |
68 | |
| 45 | # If we are in a chrooted environment, and there is already a |
69 | # If we are in a chrooted environment, and there is already a |
| 46 | # X server started outside of the chroot, Xvfb will fail to start |
70 | # X server started outside of the chroot, Xvfb will fail to start |
| 47 | # on the same display (most cases this is :0 ), so make sure |
71 | # on the same display (most cases this is :0 ), so make sure |
| 48 | # Xvfb is started, else bump the display number |
72 | # Xvfb is started, else bump the display number |
| … | |
… | |
| 64 | sleep 2 |
88 | sleep 2 |
| 65 | |
89 | |
| 66 | local start=${XDISPLAY} |
90 | local start=${XDISPLAY} |
| 67 | while [[ ! -f /tmp/.X${XDISPLAY}-lock ]] ; do |
91 | while [[ ! -f /tmp/.X${XDISPLAY}-lock ]] ; do |
| 68 | # Stop trying after 15 tries |
92 | # Stop trying after 15 tries |
| 69 | if [[ $((${XDISPLAY} - ${start})) -gt 15 ]] ; then |
93 | if ((XDISPLAY - start > 15)) ; then |
| 70 | |
94 | |
| 71 | eerror "" |
95 | eerror "" |
| 72 | eerror "Unable to start Xvfb." |
96 | eerror "Unable to start Xvfb." |
| 73 | eerror "" |
97 | eerror "" |
| 74 | eerror "'/usr/bin/Xvfb :${XDISPLAY} -fp built-ins -screen 0 800x600x24' returns:" |
98 | eerror "'${XVFB} :${XDISPLAY} -fp built-ins -screen 0 800x600x24' returns:" |
| 75 | eerror "" |
99 | eerror "" |
| 76 | ${XVFB} :${XDISPLAY} -fp built-ins -screen 0 800x600x24 |
100 | ${XVFB} :${XDISPLAY} -fp built-ins -screen 0 800x600x24 |
| 77 | eerror "" |
101 | eerror "" |
| 78 | eerror "If possible, correct the above error and try your emerge again." |
102 | eerror "If possible, correct the above error and try your emerge again." |
| 79 | eerror "" |
103 | eerror "" |
| 80 | die |
104 | die |
| 81 | fi |
105 | fi |
| 82 | |
106 | |
| 83 | XDISPLAY=$((${XDISPLAY}+1)) |
107 | ((XDISPLAY++)) |
| 84 | ${XVFB} :${XDISPLAY} -fp built-ins -screen 0 800x600x24 &>/dev/null & |
108 | ${XVFB} :${XDISPLAY} -fp built-ins -screen 0 800x600x24 &>/dev/null & |
| 85 | sleep 2 |
109 | sleep 2 |
| 86 | done |
110 | done |
| 87 | |
111 | |
| 88 | # Now enable SANDBOX again if needed. |
112 | # Now enable SANDBOX again if needed. |
| 89 | export SANDBOX_DISABLED="${OLD_SANDBOX_DISABLED}" |
113 | export SANDBOX_ON="${OLD_SANDBOX_ON}" |
| 90 | |
114 | |
| 91 | einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..." |
115 | einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..." |
| 92 | |
116 | |
| 93 | export DISPLAY=:${XDISPLAY} |
117 | export DISPLAY=:${XDISPLAY} |
| 94 | #Do not break on error, but setup $retval, as we need |
118 | #Do not break on error, but setup $retval, as we need |
| 95 | #to kill Xvfb |
119 | #to kill Xvfb |
| 96 | ${maketype} $* |
120 | ${maketype} "$@" |
| 97 | retval=$? |
121 | retval=$? |
| 98 | |
122 | |
| 99 | #Now kill Xvfb |
123 | #Now kill Xvfb |
| 100 | kill $(cat /tmp/.X${XDISPLAY}-lock) |
124 | kill $(cat /tmp/.X${XDISPLAY}-lock) |
| 101 | else |
125 | else |
| 102 | #Normal make if we can connect to an X display |
126 | #Normal make if we can connect to an X display |
| 103 | ${maketype} $* |
127 | ${maketype} "$@" |
| 104 | retval=$? |
128 | retval=$? |
| 105 | fi |
129 | fi |
| 106 | |
130 | |
| 107 | return ${retval} |
131 | return ${retval} |
| 108 | } |
132 | } |
| 109 | |
133 | |
| 110 | #Same as "make", but setup the Xvfb hack if needed |
134 | #Same as "make", but setup the Xvfb hack if needed |
| 111 | Xmake() { |
135 | Xmake() { |
| 112 | export maketype="make" |
136 | export maketype="make" |
| 113 | virtualmake "$*" |
137 | virtualmake "$@" |
| 114 | } |
138 | } |
| 115 | |
139 | |
| 116 | #Same as "emake", but setup the Xvfb hack if needed |
140 | #Same as "emake", but setup the Xvfb hack if needed |
| 117 | Xemake() { |
141 | Xemake() { |
| 118 | export maketype="emake" |
142 | export maketype="emake" |
| 119 | virtualmake "$*" |
143 | virtualmake "$@" |
| 120 | } |
144 | } |
| 121 | |
145 | |
| 122 | #Same as "econf", but setup the Xvfb hack if needed |
146 | #Same as "econf", but setup the Xvfb hack if needed |
| 123 | Xeconf() { |
147 | Xeconf() { |
| 124 | export maketype="econf" |
148 | export maketype="econf" |
| 125 | virtualmake "$*" |
149 | virtualmake "$@" |
| 126 | } |
150 | } |