aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2011-03-29 12:53:19 -0700
committerChris Larson <chris_larson@mentor.com>2011-05-18 09:55:58 -0700
commit96e4df5d0b4e27e40a2a6b5d7db2631b9c203010 (patch)
tree682d112618a738f29885a73038abac9d4968083b
parent95c1c690d14f493b615eafeb349d57aa67366b5d (diff)
downloadopenembedded-core-contrib-96e4df5d0b4e27e40a2a6b5d7db2631b9c203010.tar.gz
openembedded-core-contrib-96e4df5d0b4e27e40a2a6b5d7db2631b9c203010.tar.bz2
openembedded-core-contrib-96e4df5d0b4e27e40a2a6b5d7db2631b9c203010.zip
Rework how the devshell functions
In the new implementation, each known terminal is defined as a class in oe.terminal, as a subclass of bb.process.Popen. It obeys the OE_TERMINAL variable, which is a 'choice' typed variable. This variable may be 'auto', 'none', or any of the names of the defined terminals. When using 'auto', or requesting an unsupported terminal, we attempt to spawn them in priority order until we get one that's available on this system (and in the case of the X terminals, has DISPLAY defined). The 'none' value is used when we're doing things like automated builds, and want to ensure that no terminal is *ever* spawned, under any circumstances. Current available terminals: gnome konsole xterm rxvt screen Signed-off-by: Chris Larson <chris_larson@mentor.com>
-rw-r--r--meta/classes/devshell.bbclass25
-rw-r--r--meta/conf/bitbake.conf9
-rw-r--r--meta/lib/oe/classutils.py2
-rw-r--r--meta/lib/oe/terminal.py126
4 files changed, 143 insertions, 19 deletions
diff --git a/meta/classes/devshell.bbclass b/meta/classes/devshell.bbclass
index 5f262f426e..216a9dc96a 100644
--- a/meta/classes/devshell.bbclass
+++ b/meta/classes/devshell.bbclass
@@ -1,22 +1,9 @@
-do_devshell[dirs] = "${S}"
-do_devshell[nostamp] = "1"
-
-XAUTHORITY ?= "${HOME}/.Xauthority"
-
-devshell_do_devshell() {
- export DISPLAY='${DISPLAY}'
- export DBUS_SESSION_BUS_ADDRESS='${DBUS_SESSION_BUS_ADDRESS}'
- export XAUTHORITY='${XAUTHORITY}'
- export TERMWINDOWTITLE="Bitbake Developer Shell"
- export EXTRA_OEMAKE='${EXTRA_OEMAKE}'
- export SHELLCMDS="bash"
- ${TERMCMDRUN}
- if [ $? -ne 0 ]; then
- echo "Fatal: '${TERMCMD}' not found. Check TERMCMD variable."
- exit 1
- fi
+python do_devshell () {
+ import oe.terminal
+ oe.terminal.run(d.getVar('SHELL', True), 'OpenEmbedded Developer Shell', d)
}
-addtask devshell after do_patch
-EXPORT_FUNCTIONS do_devshell
+addtask devshell after do_patch
+do_devshell[dirs] = "${S}"
+do_devshell[nostamp] = "1"
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index a0af672ae2..45a426d771 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -539,6 +539,15 @@ PREFERRED_PROVIDER_virtual/fakeroot-native ?= "pseudo-native"
# UI/Interaction Configuration
##################################################################
+
+OE_TERMINAL ?= 'auto'
+OE_TERMINAL[type] = 'choice'
+OE_TERMINAL[choices] = 'auto none \
+ ${@" ".join(o.name \
+ for o in oe.terminal.prioritized())}'
+
+export XAUTHORITY ?= "${HOME}/.Xauthority"
+export SHELL ?= "bash"
export SHELLCMDS = "bash"
# Some common terminal programs to choose from
GNOME_TERMCMD = 'gnome-terminal --disable-factory -t "$TERMWINDOWTITLE"'
diff --git a/meta/lib/oe/classutils.py b/meta/lib/oe/classutils.py
index 58188fdd6e..42b0f49bc3 100644
--- a/meta/lib/oe/classutils.py
+++ b/meta/lib/oe/classutils.py
@@ -1,3 +1,5 @@
+__author__ = 'kergoth'
+
class ClassRegistry(type):
"""Maintain a registry of classes, indexed by name.
diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
new file mode 100644
index 0000000000..e14fc5dbc4
--- /dev/null
+++ b/meta/lib/oe/terminal.py
@@ -0,0 +1,126 @@
+import logging
+import os
+import oe.classutils
+import oe.data
+import shlex
+import bb
+from bb.process import Popen, ExecutionError
+
+
+logger = logging.getLogger('BitBake.OE.Terminal')
+
+
+class UnsupportedTerminal(StandardError):
+ pass
+
+class NoSupportedTerminals(StandardError):
+ pass
+
+
+class Registry(oe.classutils.ClassRegistry):
+ command = None
+
+ def __init__(cls, name, bases, attrs):
+ super(Registry, cls).__init__(name.lower(), bases, attrs)
+
+ @property
+ def implemented(cls):
+ return bool(cls.command)
+
+
+class Terminal(Popen):
+ __metaclass__ = Registry
+
+ def __init__(self, command, title=None):
+ self.format_command(command, title)
+ logger.debug(1, "%s: running %s", self.name, self.command)
+
+ try:
+ Popen.__init__(self, self.command, shell=False)
+ except OSError as exc:
+ import errno
+ if exc.errno == errno.ENOENT:
+ raise UnsupportedTerminal(self.name)
+ else:
+ raise
+
+ def format_command(self, command, title):
+ fmt = {'title': title or 'Terminal', 'command': command}
+ if isinstance(self.command, basestring):
+ self.command = shlex.split(self.command.format(**fmt))
+ else:
+ self.command = [element.format(**fmt) for element in self.command]
+
+class XTerminal(Terminal):
+ def __init__(self, command, title=None):
+ Terminal.__init__(self, command, title)
+ if not os.environ.get('DISPLAY'):
+ raise UnsupportedTerminal(self.name)
+
+class Gnome(XTerminal):
+ command = 'gnome-terminal --disable-factory -t "{title}" -x {command}'
+ priority = 2
+
+class Konsole(XTerminal):
+ command = 'konsole -T "{title}" -e {command}'
+ priority = 2
+
+class XTerm(XTerminal):
+ command = 'xterm -T "{title}" -e {command}'
+ priority = 1
+
+class Rxvt(XTerminal):
+ command = 'rxvt -T "{title}" -e {command}'
+ priority = 1
+
+class Screen(Terminal):
+ command = 'screen -D -m -t "{title}" {command}'
+
+
+def prioritized():
+ return Registry.prioritized()
+
+def run(command, title, d):
+ terminal = oe.data.typed_value('OE_TERMINAL', d).lower()
+ if terminal == 'none':
+ bb.fatal('Devshell usage disabled with OE_TERMINAL')
+ elif terminal != 'auto':
+ try:
+ spawn(terminal, command, title)
+ return
+ except UnsupportedTerminal:
+ bb.warn('Unsupported terminal "%s", defaulting to "auto"' %
+ terminal)
+ except ExecutionError as exc:
+ bb.fatal('Unable to spawn terminal %s: %s' % (terminal, exc))
+
+ try:
+ spawn_preferred(command, title)
+ except NoSupportedTerminals:
+ bb.fatal('No valid terminal found, unable to open devshell')
+ except ExecutionError as exc:
+ bb.fatal('Unable to spawn terminal %s: %s' % (terminal, exc))
+
+def spawn_preferred(command, title=None):
+ """Spawn the first supported terminal, by priority"""
+ for terminal in prioritized():
+ try:
+ spawn(terminal.name, command, title)
+ break
+ except UnsupportedTerminal:
+ continue
+ else:
+ raise NoSupportedTerminals()
+
+def spawn(name, command, title=None):
+ """Spawn the specified terminal, by name"""
+ logger.debug(1, 'Attempting to spawn terminal "%s"', name)
+ try:
+ terminal = Registry.registry[name]
+ except KeyError:
+ raise UnsupportedTerminal(name)
+
+ pipe = terminal(command, title)
+ output = pipe.communicate()[0]
+ if pipe.returncode != 0:
+ raise ExecutionError(pipe.command, pipe.returncode, output)