| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | OE_TERMINAL ?= 'auto' | 
|  | 2 | OE_TERMINAL[type] = 'choice' | 
|  | 3 | OE_TERMINAL[choices] = 'auto none \ | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4 | ${@oe_terminal_prioritized()}' | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 |  | 
|  | 6 | OE_TERMINAL_EXPORTS += 'EXTRA_OEMAKE' | 
|  | 7 | OE_TERMINAL_EXPORTS[type] = 'list' | 
|  | 8 |  | 
|  | 9 | XAUTHORITY ?= "${HOME}/.Xauthority" | 
|  | 10 | SHELL ?= "bash" | 
|  | 11 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 12 | def oe_terminal_prioritized(): | 
|  | 13 | import oe.terminal | 
|  | 14 | return " ".join(o.name for o in oe.terminal.prioritized()) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 |  | 
|  | 16 | def emit_terminal_func(command, envdata, d): | 
|  | 17 | cmd_func = 'do_terminal' | 
|  | 18 |  | 
|  | 19 | envdata.setVar(cmd_func, 'exec ' + command) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 20 | envdata.setVarFlag(cmd_func, 'func', '1') | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 |  | 
|  | 22 | runfmt = d.getVar('BB_RUNFMT', True) or "run.{func}.{pid}" | 
|  | 23 | runfile = runfmt.format(func=cmd_func, task=cmd_func, taskfunc=cmd_func, pid=os.getpid()) | 
|  | 24 | runfile = os.path.join(d.getVar('T', True), runfile) | 
|  | 25 | bb.utils.mkdirhier(os.path.dirname(runfile)) | 
|  | 26 |  | 
|  | 27 | with open(runfile, 'w') as script: | 
|  | 28 | script.write('#!/bin/sh -e\n') | 
|  | 29 | bb.data.emit_func(cmd_func, script, envdata) | 
|  | 30 | script.write(cmd_func) | 
|  | 31 | script.write("\n") | 
|  | 32 | os.chmod(runfile, 0755) | 
|  | 33 |  | 
|  | 34 | return runfile | 
|  | 35 |  | 
|  | 36 | def oe_terminal(command, title, d): | 
|  | 37 | import oe.data | 
|  | 38 | import oe.terminal | 
|  | 39 |  | 
|  | 40 | envdata = bb.data.init() | 
|  | 41 |  | 
|  | 42 | for v in os.environ: | 
|  | 43 | envdata.setVar(v, os.environ[v]) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 44 | envdata.setVarFlag(v, 'export', '1') | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 |  | 
|  | 46 | for export in oe.data.typed_value('OE_TERMINAL_EXPORTS', d): | 
|  | 47 | value = d.getVar(export, True) | 
|  | 48 | if value is not None: | 
|  | 49 | os.environ[export] = str(value) | 
|  | 50 | envdata.setVar(export, str(value)) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 51 | envdata.setVarFlag(export, 'export', '1') | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | if export == "PSEUDO_DISABLED": | 
|  | 53 | if "PSEUDO_UNLOAD" in os.environ: | 
|  | 54 | del os.environ["PSEUDO_UNLOAD"] | 
|  | 55 | envdata.delVar("PSEUDO_UNLOAD") | 
|  | 56 |  | 
|  | 57 | # Add in all variables from the user's original environment which | 
|  | 58 | # haven't subsequntly been set/changed | 
|  | 59 | origbbenv = d.getVar("BB_ORIGENV", False) or {} | 
|  | 60 | for key in origbbenv: | 
|  | 61 | if key in envdata: | 
|  | 62 | continue | 
|  | 63 | value = origbbenv.getVar(key, True) | 
|  | 64 | if value is not None: | 
|  | 65 | os.environ[key] = str(value) | 
|  | 66 | envdata.setVar(key, str(value)) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 67 | envdata.setVarFlag(key, 'export', '1') | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 68 |  | 
|  | 69 | # A complex PS1 might need more escaping of chars. | 
|  | 70 | # Lets not export PS1 instead. | 
|  | 71 | envdata.delVar("PS1") | 
|  | 72 |  | 
|  | 73 | # Replace command with an executable wrapper script | 
|  | 74 | command = emit_terminal_func(command, envdata, d) | 
|  | 75 |  | 
|  | 76 | terminal = oe.data.typed_value('OE_TERMINAL', d).lower() | 
|  | 77 | if terminal == 'none': | 
|  | 78 | bb.fatal('Devshell usage disabled with OE_TERMINAL') | 
|  | 79 | elif terminal != 'auto': | 
|  | 80 | try: | 
|  | 81 | oe.terminal.spawn(terminal, command, title, None, d) | 
|  | 82 | return | 
|  | 83 | except oe.terminal.UnsupportedTerminal: | 
|  | 84 | bb.warn('Unsupported terminal "%s", defaulting to "auto"' % | 
|  | 85 | terminal) | 
|  | 86 | except oe.terminal.ExecutionError as exc: | 
|  | 87 | bb.fatal('Unable to spawn terminal %s: %s' % (terminal, exc)) | 
|  | 88 |  | 
|  | 89 | try: | 
|  | 90 | oe.terminal.spawn_preferred(command, title, None, d) | 
|  | 91 | except oe.terminal.NoSupportedTerminals: | 
|  | 92 | bb.fatal('No valid terminal found, unable to open devshell') | 
|  | 93 | except oe.terminal.ExecutionError as exc: | 
|  | 94 | bb.fatal('Unable to spawn terminal %s: %s' % (terminal, exc)) | 
|  | 95 |  | 
|  | 96 | oe_terminal[vardepsexclude] = "BB_ORIGENV" |