summaryrefslogtreecommitdiffstats
path: root/meta/classes/terminal.bbclass
diff options
context:
space:
mode:
authorTudor Florea <tudor.florea@enea.com>2014-10-16 03:05:19 +0200
committerTudor Florea <tudor.florea@enea.com>2014-10-16 03:05:19 +0200
commitc527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch)
treebb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /meta/classes/terminal.bbclass
downloadpoky-daisy-140929.tar.gz
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/classes/terminal.bbclass')
-rw-r--r--meta/classes/terminal.bbclass94
1 files changed, 94 insertions, 0 deletions
diff --git a/meta/classes/terminal.bbclass b/meta/classes/terminal.bbclass
new file mode 100644
index 0000000000..e577c6d594
--- /dev/null
+++ b/meta/classes/terminal.bbclass
@@ -0,0 +1,94 @@
1OE_TERMINAL ?= 'auto'
2OE_TERMINAL[type] = 'choice'
3OE_TERMINAL[choices] = 'auto none \
4 ${@" ".join(o.name \
5 for o in oe.terminal.prioritized())}'
6
7OE_TERMINAL_EXPORTS += 'EXTRA_OEMAKE'
8OE_TERMINAL_EXPORTS[type] = 'list'
9
10XAUTHORITY ?= "${HOME}/.Xauthority"
11SHELL ?= "bash"
12
13
14def emit_terminal_func(command, envdata, d):
15 cmd_func = 'do_terminal'
16
17 envdata.setVar(cmd_func, 'exec ' + command)
18 envdata.setVarFlag(cmd_func, 'func', 1)
19
20 runfmt = d.getVar('BB_RUNFMT', True) or "run.{func}.{pid}"
21 runfile = runfmt.format(func=cmd_func, task=cmd_func, taskfunc=cmd_func, pid=os.getpid())
22 runfile = os.path.join(d.getVar('T', True), runfile)
23 bb.utils.mkdirhier(os.path.dirname(runfile))
24
25 with open(runfile, 'w') as script:
26 script.write('#!/bin/sh -e\n')
27 bb.data.emit_func(cmd_func, script, envdata)
28 script.write(cmd_func)
29 script.write("\n")
30 os.chmod(runfile, 0755)
31
32 return runfile
33
34def oe_terminal(command, title, d):
35 import oe.data
36 import oe.terminal
37
38 envdata = bb.data.init()
39
40 for v in os.environ:
41 envdata.setVar(v, os.environ[v])
42 envdata.setVarFlag(v, 'export', 1)
43
44 for export in oe.data.typed_value('OE_TERMINAL_EXPORTS', d):
45 value = d.getVar(export, True)
46 if value is not None:
47 os.environ[export] = str(value)
48 envdata.setVar(export, str(value))
49 envdata.setVarFlag(export, 'export', 1)
50 if export == "PSEUDO_DISABLED":
51 if "PSEUDO_UNLOAD" in os.environ:
52 del os.environ["PSEUDO_UNLOAD"]
53 envdata.delVar("PSEUDO_UNLOAD")
54
55 # Add in all variables from the user's original environment which
56 # haven't subsequntly been set/changed
57 origbbenv = d.getVar("BB_ORIGENV", False) or {}
58 for key in origbbenv:
59 if key in envdata:
60 continue
61 value = origbbenv.getVar(key, True)
62 if value is not None:
63 os.environ[key] = str(value)
64 envdata.setVar(key, str(value))
65 envdata.setVarFlag(key, 'export', 1)
66
67 # A complex PS1 might need more escaping of chars.
68 # Lets not export PS1 instead.
69 envdata.delVar("PS1")
70
71 # Replace command with an executable wrapper script
72 command = emit_terminal_func(command, envdata, d)
73
74 terminal = oe.data.typed_value('OE_TERMINAL', d).lower()
75 if terminal == 'none':
76 bb.fatal('Devshell usage disabled with OE_TERMINAL')
77 elif terminal != 'auto':
78 try:
79 oe.terminal.spawn(terminal, command, title, None, d)
80 return
81 except oe.terminal.UnsupportedTerminal:
82 bb.warn('Unsupported terminal "%s", defaulting to "auto"' %
83 terminal)
84 except oe.terminal.ExecutionError as exc:
85 bb.fatal('Unable to spawn terminal %s: %s' % (terminal, exc))
86
87 try:
88 oe.terminal.spawn_preferred(command, title, None, d)
89 except oe.terminal.NoSupportedTerminals:
90 bb.fatal('No valid terminal found, unable to open devshell')
91 except oe.terminal.ExecutionError as exc:
92 bb.fatal('Unable to spawn terminal %s: %s' % (terminal, exc))
93
94oe_terminal[vardepsexclude] = "BB_ORIGENV"