From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1029238-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 880C0138334
	for <garchives@archives.gentoo.org>; Sun, 10 Jun 2018 14:43:33 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 89F3CE0825;
	Sun, 10 Jun 2018 14:43:32 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 4A318E0825
	for <gentoo-commits@lists.gentoo.org>; Sun, 10 Jun 2018 14:43:32 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 0DCE4335C90
	for <gentoo-commits@lists.gentoo.org>; Sun, 10 Jun 2018 14:43:31 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 5BF5D29E
	for <gentoo-commits@lists.gentoo.org>; Sun, 10 Jun 2018 14:43:29 +0000 (UTC)
From: "Johannes Huber" <johu@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Johannes Huber" <johu@gentoo.org>
Message-ID: <1528641720.251c1c036407953a719149c40d958f269e8937e5.johu@gentoo>
Subject: [gentoo-commits] proj/kde:master commit in: eclass/
X-VCS-Repository: proj/kde
X-VCS-Files: eclass/virtualx.eclass
X-VCS-Directories: eclass/
X-VCS-Committer: johu
X-VCS-Committer-Name: Johannes Huber
X-VCS-Revision: 251c1c036407953a719149c40d958f269e8937e5
X-VCS-Branch: master
Date: Sun, 10 Jun 2018 14:43:29 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: f3dbdf30-9952-4846-b29b-35a940a8584f
X-Archives-Hash: 7e7a5636fe05595c2f649651f1346534

commit:     251c1c036407953a719149c40d958f269e8937e5
Author:     Johannes Huber <johu <AT> gentoo <DOT> org>
AuthorDate: Sun Jun 10 14:42:00 2018 +0000
Commit:     Johannes Huber <johu <AT> gentoo <DOT> org>
CommitDate: Sun Jun 10 14:42:00 2018 +0000
URL:        https://gitweb.gentoo.org/proj/kde.git/commit/?id=251c1c03

virtualx.eclass: Drop prefix access w/o define

 eclass/virtualx.eclass | 260 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 260 insertions(+)

diff --git a/eclass/virtualx.eclass b/eclass/virtualx.eclass
new file mode 100644
index 0000000000..749c051bf1
--- /dev/null
+++ b/eclass/virtualx.eclass
@@ -0,0 +1,260 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: virtualx.eclass
+# @MAINTAINER:
+# x11@gentoo.org
+# @AUTHOR:
+# Original author: Martin Schlemmer <azarah@gentoo.org>
+# @BLURB: This eclass can be used for packages that needs a working X environment to build.
+
+if [[ ! ${_VIRTUAL_X} ]]; then
+
+case "${EAPI:-0}" in
+	0|1|2|3)
+		die "virtualx.eclass: EAPI ${EAPI} is too old."
+		;;
+	4|5|6)
+		;;
+	*)
+		die "virtualx.eclass: EAPI ${EAPI} is not supported yet."
+		;;
+esac
+
+[[ ${EAPI} == [45] ]] && inherit eutils
+
+# @ECLASS-VARIABLE: VIRTUALX_REQUIRED
+# @DESCRIPTION:
+# Variable specifying the dependency on xorg-server and xhost.
+# Possible special values are "always" and "manual", which specify
+# the dependency to be set unconditionaly or not at all.
+# Any other value is taken as useflag desired to be in control of
+# the dependency (eg. VIRTUALX_REQUIRED="kde" will add the dependency
+# into "kde? ( )" and add kde into IUSE.
+: ${VIRTUALX_REQUIRED:=test}
+
+# @ECLASS-VARIABLE: VIRTUALX_DEPEND
+# @DESCRIPTION:
+# Dep string available for use outside of eclass, in case a more
+# complicated dep is needed.
+# You can specify the variable BEFORE inherit to add more dependencies.
+VIRTUALX_DEPEND="${VIRTUALX_DEPEND}
+	x11-apps/xhost
+	x11-base/xorg-server[xvfb]
+"
+
+# @ECLASS-VARIABLE: VIRTUALX_COMMAND
+# @DESCRIPTION:
+# Command (or eclass function call) to be run in the X11 environment
+# (within virtualmake function).
+: ${VIRTUALX_COMMAND:="emake"}
+
+case ${VIRTUALX_REQUIRED} in
+	manual)
+		;;
+	always)
+		DEPEND="${VIRTUALX_DEPEND}"
+		RDEPEND=""
+		;;
+	optional|tests)
+		[[ ${EAPI} == [45] ]] \
+			|| die 'Values "optional" and "tests" for VIRTUALX_REQUIRED are banned in EAPI > 5'
+		# deprecated section YAY.
+		eqawarn "VIRTUALX_REQUIRED=optional and VIRTUALX_REQUIRED=tests are deprecated."
+		eqawarn "You can drop the variable definition completely from ebuild,"
+		eqawarn "because it is default behaviour."
+
+		if [[ -n ${VIRTUALX_USE} ]]; then
+			# so they like to specify the useflag
+			eqawarn "VIRTUALX_USE variable is deprecated."
+			eqawarn "Please read eclass manpage to find out how to use VIRTUALX_REQUIRED"
+			eqawarn "to achieve the same behaviour."
+		fi
+
+		[[ -z ${VIRTUALX_USE} ]] && VIRTUALX_USE="test"
+		DEPEND="${VIRTUALX_USE}? ( ${VIRTUALX_DEPEND} )"
+		RDEPEND=""
+		IUSE="${VIRTUALX_USE}"
+		;;
+	*)
+		DEPEND="${VIRTUALX_REQUIRED}? ( ${VIRTUALX_DEPEND} )"
+		RDEPEND=""
+		IUSE="${VIRTUALX_REQUIRED}"
+		;;
+esac
+
+# @FUNCTION: virtualmake
+# @DESCRIPTION:
+# Function which start new Xvfb session
+# where the VIRTUALX_COMMAND variable content gets executed.
+virtualmake() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	[[ ${EAPI} == [45] ]] \
+		|| die "${FUNCNAME} is unsupported in EAPI > 5, please use virtx"
+
+	# backcompat for maketype
+	if [[ -n ${maketype} ]]; then
+		[[ ${EAPI} == [45] ]] || die "maketype is banned in EAPI > 5"
+		eqawarn "ebuild is exporting \$maketype=${maketype}"
+		eqawarn "Ebuild should be migrated to use 'virtx command' instead."
+		VIRTUALX_COMMAND=${maketype}
+	fi
+
+	virtx "${VIRTUALX_COMMAND}" "${@}"
+}
+
+
+# @FUNCTION: virtx
+# @USAGE: <command> [command arguments]
+# @DESCRIPTION:
+# Start new Xvfb session and run commands in it.
+#
+# IMPORTANT: The command is run nonfatal !!!
+#
+# This means we are checking for the return code and raise an exception if it
+# isn't 0. So you need to make sure that all commands return a proper
+# code and not just die. All eclass function used should support nonfatal
+# calls properly.
+#
+# The rational behind this is the tear down of the started Xfvb session. A
+# straight die would leave a running session behind.
+#
+# Example:
+#
+# @CODE
+# src_test() {
+# 	virtx default
+# }
+# @CODE
+#
+# @CODE
+# python_test() {
+# 	virtx py.test --verbose
+# }
+# @CODE
+#
+# @CODE
+# my_test() {
+#   some_command
+#   return $?
+# }
+#
+# src_test() {
+#   virtx my_test
+# }
+# @CODE
+virtx() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	[[ $# -lt 1 ]] && die "${FUNCNAME} needs at least one argument"
+
+	local i=0
+	local retval=0
+	local OLD_SANDBOX_ON="${SANDBOX_ON}"
+	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"
+	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 ..."
+	# 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
+	XDISPLAY=$(i=0; while [[ -f /tmp/.X${i}-lock ]] ; do ((i++));done; echo ${i})
+	debug-print "${FUNCNAME}: XDISPLAY=${XDISPLAY}"
+
+	# We really do not want SANDBOX enabled here
+	export SANDBOX_ON="0"
+
+	debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}"
+	${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null &
+	sleep 2
+
+	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
+			((XDISPLAY++))
+		debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}"
+		${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null &
+		sleep 2
+	done
+
+	# Now enable SANDBOX again if needed.
+	export SANDBOX_ON="${OLD_SANDBOX_ON}"
+
+	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}: $@"
+	nonfatal "$@"
+	retval=$?
+
+	# Now kill Xvfb
+	kill $(cat /tmp/.X${XDISPLAY}-lock)
+
+	# die if our command failed
+	[[ ${retval} -ne 0 ]] && die "Failed to run '$@'"
+
+	return 0 # always return 0, it can be altered by failed kill for Xvfb
+}
+
+# @FUNCTION: Xmake
+# @DESCRIPTION:
+# Same as "make", but set up the Xvfb hack if needed.
+# Deprecated call.
+Xmake() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	[[ ${EAPI} == [45] ]] \
+		|| die "${FUNCNAME} is unsupported in EAPI > 5, please use 'virtx emake -j1 ....'"
+
+	eqawarn "you should not execute make directly"
+	eqawarn "rather execute Xemake -j1 if you have issues with parallel make"
+	VIRTUALX_COMMAND="emake -j1" virtualmake "$@"
+}
+
+# @FUNCTION: Xemake
+# @DESCRIPTION:
+# Same as "emake", but set up the Xvfb hack if needed.
+Xemake() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	[[ ${EAPI} == [45] ]] \
+		|| die "${FUNCNAME} is unsupported in EAPI > 5, please use 'virtx emake ....'"
+
+	VIRTUALX_COMMAND="emake" virtualmake "$@"
+}
+
+# @FUNCTION: Xeconf
+# @DESCRIPTION:
+# Same as "econf", but set up the Xvfb hack if needed.
+Xeconf() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	[[ ${EAPI} == [45] ]] \
+		|| die "${FUNCNAME} is unsupported in EAPI > 5, please use 'virtx econf ....'"
+
+	VIRTUALX_COMMAND="econf" virtualmake "$@"
+}
+
+_VIRTUAL_X=1
+fi