diff options
Diffstat (limited to 'meta/classes/terminal.bbclass')
-rw-r--r-- | meta/classes/terminal.bbclass | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/meta/classes/terminal.bbclass b/meta/classes/terminal.bbclass new file mode 100644 index 0000000000..efbc4eb9ae --- /dev/null +++ b/meta/classes/terminal.bbclass | |||
@@ -0,0 +1,88 @@ | |||
1 | OE_TERMINAL ?= 'auto' | ||
2 | OE_TERMINAL[type] = 'choice' | ||
3 | OE_TERMINAL[choices] = 'auto none \ | ||
4 | ${@" ".join(o.name \ | ||
5 | for o in oe.terminal.prioritized())}' | ||
6 | |||
7 | OE_TERMINAL_EXPORTS += 'EXTRA_OEMAKE' | ||
8 | OE_TERMINAL_EXPORTS[type] = 'list' | ||
9 | |||
10 | XAUTHORITY ?= "${HOME}/.Xauthority" | ||
11 | SHELL ?= "bash" | ||
12 | |||
13 | |||
14 | def 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 | |||
34 | def 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 | # Replace command with an executable wrapper script | ||
68 | command = emit_terminal_func(command, envdata, d) | ||
69 | |||
70 | terminal = oe.data.typed_value('OE_TERMINAL', d).lower() | ||
71 | if terminal == 'none': | ||
72 | bb.fatal('Devshell usage disabled with OE_TERMINAL') | ||
73 | elif terminal != 'auto': | ||
74 | try: | ||
75 | oe.terminal.spawn(terminal, command, title, None, d) | ||
76 | return | ||
77 | except oe.terminal.UnsupportedTerminal: | ||
78 | bb.warn('Unsupported terminal "%s", defaulting to "auto"' % | ||
79 | terminal) | ||
80 | except oe.terminal.ExecutionError as exc: | ||
81 | bb.fatal('Unable to spawn terminal %s: %s' % (terminal, exc)) | ||
82 | |||
83 | try: | ||
84 | oe.terminal.spawn_preferred(command, title, None, d) | ||
85 | except oe.terminal.NoSupportedTerminals: | ||
86 | bb.fatal('No valid terminal found, unable to open devshell') | ||
87 | except oe.terminal.ExecutionError as exc: | ||
88 | bb.fatal('Unable to spawn terminal %s: %s' % (terminal, exc)) | ||