blob: e577c6d5943e3421d771a6709d737b1618032515 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001OE_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"