mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-15 08:56:58 +02:00
eclass/virtualx: Sync with Gentoo
It's from Gentoo commit aa7fdc965621b413d85624ea30e9452a4130aced.
This commit is contained in:
parent
b58940ccf3
commit
e855d3dfc7
@ -1,24 +1,23 @@
|
|||||||
# Copyright 1999-2021 Gentoo Authors
|
# Copyright 1999-2021 Gentoo Authors
|
||||||
# Distributed under the terms of the GNU General Public License v2
|
# Distributed under the terms of the GNU General Public License v2
|
||||||
|
|
||||||
# Flatcar: Support EAPI 4 and 5.
|
|
||||||
|
|
||||||
# @ECLASS: virtualx.eclass
|
# @ECLASS: virtualx.eclass
|
||||||
# @MAINTAINER:
|
# @MAINTAINER:
|
||||||
# x11@gentoo.org
|
# x11@gentoo.org
|
||||||
# @AUTHOR:
|
# @AUTHOR:
|
||||||
# Original author: Martin Schlemmer <azarah@gentoo.org>
|
# Original author: Martin Schlemmer <azarah@gentoo.org>
|
||||||
# @SUPPORTED_EAPIS: 4 5 6 7 8
|
# @SUPPORTED_EAPIS: 6 7 8
|
||||||
# @BLURB: This eclass can be used for packages that need a working X environment to build.
|
# @BLURB: This eclass can be used for packages that need a working X environment to build.
|
||||||
|
|
||||||
case ${EAPI} in
|
case ${EAPI} in
|
||||||
4|5|6|7|8) ;;
|
6|7|8) ;;
|
||||||
*) die "${ECLASS}: EAPI ${EAPI:-0} is not supported." ;;
|
*) die "${ECLASS}: EAPI ${EAPI:-0} is not supported." ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ ! ${_VIRTUALX_ECLASS} ]]; then
|
if [[ ! ${_VIRTUALX_ECLASS} ]]; then
|
||||||
_VIRTUALX_ECLASS=1
|
_VIRTUALX_ECLASS=1
|
||||||
|
|
||||||
# @ECLASS-VARIABLE: VIRTUALX_REQUIRED
|
# @ECLASS_VARIABLE: VIRTUALX_REQUIRED
|
||||||
# @PRE_INHERIT
|
# @PRE_INHERIT
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Variable specifying the dependency on xorg-server and xhost.
|
# Variable specifying the dependency on xorg-server and xhost.
|
||||||
@ -29,19 +28,19 @@ _VIRTUALX_ECLASS=1
|
|||||||
# into "kde? ( )" and add kde into IUSE.
|
# into "kde? ( )" and add kde into IUSE.
|
||||||
: ${VIRTUALX_REQUIRED:=test}
|
: ${VIRTUALX_REQUIRED:=test}
|
||||||
|
|
||||||
# @ECLASS-VARIABLE: VIRTUALX_DEPEND
|
# @ECLASS_VARIABLE: VIRTUALX_DEPEND
|
||||||
# @OUTPUT_VARIABLE
|
# @OUTPUT_VARIABLE
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Standard dependencies string that is automatically added to BDEPEND
|
# Standard dependencies string that is automatically added to BDEPEND
|
||||||
# (in EAPI-6: DEPEND) unless VIRTUALX_REQUIRED is set to "manual".
|
# (in EAPI-6: DEPEND) unless VIRTUALX_REQUIRED is set to "manual".
|
||||||
# DEPRECATED: Pre-EAPI-8 you can specify the variable BEFORE inherit
|
# DEPRECATED: Pre-EAPI-8 you can specify the variable BEFORE inherit
|
||||||
# to add more dependencies.
|
# to add more dependencies.
|
||||||
[[ ${EAPI} != [4567] ]] && VIRTUALX_DEPEND=""
|
[[ ${EAPI} != [67] ]] && VIRTUALX_DEPEND=""
|
||||||
VIRTUALX_DEPEND+="
|
VIRTUALX_DEPEND+="
|
||||||
x11-base/xorg-server[xvfb]
|
x11-base/xorg-server[xvfb]
|
||||||
x11-apps/xhost
|
x11-apps/xhost
|
||||||
"
|
"
|
||||||
[[ ${EAPI} != [4567] ]] && readonly VIRTUALX_DEPEND
|
[[ ${EAPI} != [67] ]] && readonly VIRTUALX_DEPEND
|
||||||
|
|
||||||
[[ ${VIRTUALX_COMMAND} ]] && die "VIRTUALX_COMMAND has been removed and is a no-op"
|
[[ ${VIRTUALX_COMMAND} ]] && die "VIRTUALX_COMMAND has been removed and is a no-op"
|
||||||
|
|
||||||
@ -54,12 +53,12 @@ case ${VIRTUALX_REQUIRED} in
|
|||||||
*)
|
*)
|
||||||
BDEPEND="${VIRTUALX_REQUIRED}? ( ${VIRTUALX_DEPEND} )"
|
BDEPEND="${VIRTUALX_REQUIRED}? ( ${VIRTUALX_DEPEND} )"
|
||||||
IUSE="${VIRTUALX_REQUIRED}"
|
IUSE="${VIRTUALX_REQUIRED}"
|
||||||
[[ ${VIRTUALX_REQUIRED} == test ]] &&
|
[[ ${VIRTUALX_REQUIRED} == "test" ]] &&
|
||||||
RESTRICT+=" !test? ( test )"
|
RESTRICT+=" !test? ( test )"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[[ ${EAPI} == [456] ]] && DEPEND="${BDEPEND}"
|
[[ ${EAPI} == 6 ]] && DEPEND="${BDEPEND}"
|
||||||
|
|
||||||
|
|
||||||
# @FUNCTION: virtx
|
# @FUNCTION: virtx
|
||||||
@ -108,68 +107,37 @@ virtx() {
|
|||||||
|
|
||||||
local i=0
|
local i=0
|
||||||
local retval=0
|
local retval=0
|
||||||
local OLD_SANDBOX_ON="${SANDBOX_ON}"
|
local xvfbargs=( -screen 0 1280x1024x24 +extension RANDR )
|
||||||
local XVFB XHOST XDISPLAY
|
|
||||||
local xvfbargs="-screen 0 1280x1024x24 +extension RANDR"
|
|
||||||
XVFB=$(type -p Xvfb) || die
|
|
||||||
XHOST=$(type -p xhost) || die
|
|
||||||
|
|
||||||
debug-print "${FUNCNAME}: running Xvfb hack"
|
debug-print "${FUNCNAME}: running Xvfb hack"
|
||||||
export XAUTHORITY=
|
export XAUTHORITY=
|
||||||
# The following is derived from Mandrake's hack to allow
|
|
||||||
# compiling without the X display
|
|
||||||
|
|
||||||
einfo "Scanning for an open DISPLAY to start Xvfb ..."
|
einfo "Starting Xvfb ..."
|
||||||
# If we are in a chrooted environment, and there is already a
|
|
||||||
# X server started outside of the chroot, Xvfb will fail to start
|
|
||||||
# on the same display (most cases this is :0 ), so make sure
|
|
||||||
# Xvfb is started, else bump the display number
|
|
||||||
#
|
|
||||||
# Azarah - 5 May 2002
|
|
||||||
# GNOME GDM may have started X on DISPLAY :0 with a
|
|
||||||
# lock file /tmp/.X1024-lock, therefore start the search at 1.
|
|
||||||
# Else a leftover /tmp/.X1-lock will prevent finding an available display.
|
|
||||||
XDISPLAY=$(i=1; while [[ -f /tmp/.X${i}-lock ]] ; do ((i++));done; echo ${i})
|
|
||||||
debug-print "${FUNCNAME}: XDISPLAY=${XDISPLAY}"
|
|
||||||
|
|
||||||
# We really do not want SANDBOX enabled here
|
debug-print "${FUNCNAME}: Xvfb -displayfd 1 ${xvfbargs[*]}"
|
||||||
export SANDBOX_ON="0"
|
local logfile=${T}/Xvfb.log
|
||||||
|
local pidfile=${T}/Xvfb.pid
|
||||||
|
# NB: bash command substitution blocks until Xvfb prints fd to stdout
|
||||||
|
# and then closes the fd; only then it backgrounds properly
|
||||||
|
export DISPLAY=:$(
|
||||||
|
Xvfb -displayfd 1 "${xvfbargs[@]}" 2>"${logfile}" &
|
||||||
|
echo "$!" > "${pidfile}"
|
||||||
|
)
|
||||||
|
|
||||||
debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}"
|
if [[ ${DISPLAY} == : ]]; then
|
||||||
${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null &
|
eerror "Xvfb failed to start, reprinting error log"
|
||||||
sleep 2
|
cat "${logfile}"
|
||||||
|
die "Xvfb failed to start"
|
||||||
local start=${XDISPLAY}
|
|
||||||
while [[ ! -f /tmp/.X${XDISPLAY}-lock ]]; do
|
|
||||||
# Stop trying after 15 tries
|
|
||||||
if ((XDISPLAY - start > 15)) ; then
|
|
||||||
eerror "'${XVFB} :${XDISPLAY} ${xvfbargs}' returns:"
|
|
||||||
echo
|
|
||||||
${XVFB} :${XDISPLAY} ${xvfbargs}
|
|
||||||
echo
|
|
||||||
eerror "If possible, correct the above error and try your emerge again."
|
|
||||||
die "Unable to start Xvfb"
|
|
||||||
fi
|
fi
|
||||||
((XDISPLAY++))
|
|
||||||
debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}"
|
|
||||||
${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null &
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
|
|
||||||
# Now enable SANDBOX again if needed.
|
# Do not break on error, but setup $retval, as we need to kill Xvfb
|
||||||
export SANDBOX_ON="${OLD_SANDBOX_ON}"
|
einfo "Xvfb started on DISPLAY=${DISPLAY}"
|
||||||
|
|
||||||
einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..."
|
|
||||||
|
|
||||||
export DISPLAY=:${XDISPLAY}
|
|
||||||
# Do not break on error, but setup $retval, as we need
|
|
||||||
# to kill Xvfb
|
|
||||||
debug-print "${FUNCNAME}: $@"
|
debug-print "${FUNCNAME}: $@"
|
||||||
nonfatal "$@"
|
nonfatal "$@"
|
||||||
retval=$?
|
retval=$?
|
||||||
|
|
||||||
# Now kill Xvfb
|
# Now kill Xvfb
|
||||||
kill $(cat /tmp/.X${XDISPLAY}-lock)
|
kill "$(<"${pidfile}")"
|
||||||
|
|
||||||
# die if our command failed
|
# die if our command failed
|
||||||
[[ ${retval} -ne 0 ]] && die "Failed to run '$@'"
|
[[ ${retval} -ne 0 ]] && die "Failed to run '$@'"
|
||||||
|
Loading…
Reference in New Issue
Block a user