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. terminal.bbclass wraps this
functionality, providing the metadata pieces. 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
(From OE-Core rev: 69f77f80965fa06a057837f8f49eda06855c4086)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2011-03-29 19:53:19 +00:00
|
|
|
inherit terminal
|
2007-09-17 08:14:16 +00:00
|
|
|
|
2013-02-18 13:19:50 +00:00
|
|
|
DEVSHELL = "${SHELL}"
|
|
|
|
|
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. terminal.bbclass wraps this
functionality, providing the metadata pieces. 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
(From OE-Core rev: 69f77f80965fa06a057837f8f49eda06855c4086)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2011-03-29 19:53:19 +00:00
|
|
|
python do_devshell () {
|
2016-12-14 21:13:06 +00:00
|
|
|
if d.getVarFlag("do_devshell", "manualfakeroot"):
|
2013-09-05 15:17:27 +00:00
|
|
|
d.prependVar("DEVSHELL", "pseudo ")
|
2016-12-14 21:13:04 +00:00
|
|
|
fakeenv = d.getVar("FAKEROOTENV").split()
|
2013-09-05 15:17:27 +00:00
|
|
|
for f in fakeenv:
|
|
|
|
k = f.split("=")
|
|
|
|
d.setVar(k[0], k[1])
|
|
|
|
d.appendVar("OE_TERMINAL_EXPORTS", " " + k[0])
|
|
|
|
d.delVarFlag("do_devshell", "fakeroot")
|
|
|
|
|
2016-12-14 21:13:04 +00:00
|
|
|
oe_terminal(d.getVar('DEVSHELL'), 'OpenEmbedded Developer Shell', d)
|
2006-08-30 22:11:12 +00:00
|
|
|
}
|
|
|
|
|
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. terminal.bbclass wraps this
functionality, providing the metadata pieces. 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
(From OE-Core rev: 69f77f80965fa06a057837f8f49eda06855c4086)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2011-03-29 19:53:19 +00:00
|
|
|
addtask devshell after do_patch
|
2006-08-30 22:11:12 +00:00
|
|
|
|
2015-03-11 10:00:41 +00:00
|
|
|
# The directory that the terminal starts in
|
|
|
|
DEVSHELL_STARTDIR ?= "${S}"
|
|
|
|
do_devshell[dirs] = "${DEVSHELL_STARTDIR}"
|
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. terminal.bbclass wraps this
functionality, providing the metadata pieces. 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
(From OE-Core rev: 69f77f80965fa06a057837f8f49eda06855c4086)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2011-03-29 19:53:19 +00:00
|
|
|
do_devshell[nostamp] = "1"
|
2013-02-18 13:19:50 +00:00
|
|
|
|
|
|
|
# devshell and fakeroot/pseudo need careful handling since only the final
|
|
|
|
# command should run under fakeroot emulation, any X connection should
|
|
|
|
# be done as the normal user. We therfore carefully construct the envionment
|
|
|
|
# manually
|
|
|
|
python () {
|
2016-12-14 21:13:06 +00:00
|
|
|
if d.getVarFlag("do_devshell", "fakeroot"):
|
2013-09-05 15:17:27 +00:00
|
|
|
# We need to signal our code that we want fakeroot however we
|
|
|
|
# can't manipulate the environment and variables here yet (see YOCTO #4795)
|
|
|
|
d.setVarFlag("do_devshell", "manualfakeroot", "1")
|
2013-02-18 13:19:50 +00:00
|
|
|
d.delVarFlag("do_devshell", "fakeroot")
|
|
|
|
}
|
2014-05-27 15:09:16 +00:00
|
|
|
|
|
|
|
def devpyshell(d):
|
|
|
|
|
|
|
|
import code
|
|
|
|
import select
|
|
|
|
import signal
|
|
|
|
import termios
|
|
|
|
|
|
|
|
m, s = os.openpty()
|
|
|
|
sname = os.ttyname(s)
|
|
|
|
|
|
|
|
def noechoicanon(fd):
|
|
|
|
old = termios.tcgetattr(fd)
|
|
|
|
old[3] = old[3] &~ termios.ECHO &~ termios.ICANON
|
|
|
|
# &~ termios.ISIG
|
|
|
|
termios.tcsetattr(fd, termios.TCSADRAIN, old)
|
|
|
|
|
|
|
|
# No echo or buffering over the pty
|
|
|
|
noechoicanon(s)
|
|
|
|
|
|
|
|
pid = os.fork()
|
|
|
|
if pid:
|
|
|
|
os.close(m)
|
|
|
|
oe_terminal("oepydevshell-internal.py %s %d" % (sname, pid), 'OpenEmbedded Developer PyShell', d)
|
|
|
|
os._exit(0)
|
|
|
|
else:
|
|
|
|
os.close(s)
|
|
|
|
|
|
|
|
os.dup2(m, sys.stdin.fileno())
|
|
|
|
os.dup2(m, sys.stdout.fileno())
|
|
|
|
os.dup2(m, sys.stderr.fileno())
|
|
|
|
|
|
|
|
bb.utils.nonblockingfd(sys.stdout)
|
|
|
|
bb.utils.nonblockingfd(sys.stderr)
|
|
|
|
bb.utils.nonblockingfd(sys.stdin)
|
|
|
|
|
|
|
|
_context = {
|
|
|
|
"os": os,
|
|
|
|
"bb": bb,
|
|
|
|
"time": time,
|
|
|
|
"d": d,
|
|
|
|
}
|
|
|
|
|
|
|
|
ps1 = "pydevshell> "
|
|
|
|
ps2 = "... "
|
|
|
|
buf = []
|
|
|
|
more = False
|
|
|
|
|
|
|
|
i = code.InteractiveInterpreter(locals=_context)
|
2016-12-14 21:13:04 +00:00
|
|
|
print("OE PyShell (PN = %s)\n" % d.getVar("PN"))
|
2014-05-27 15:09:16 +00:00
|
|
|
|
|
|
|
def prompt(more):
|
|
|
|
if more:
|
|
|
|
prompt = ps2
|
|
|
|
else:
|
|
|
|
prompt = ps1
|
|
|
|
sys.stdout.write(prompt)
|
2016-07-04 22:08:14 +00:00
|
|
|
sys.stdout.flush()
|
2014-05-27 15:09:16 +00:00
|
|
|
|
|
|
|
# Restore Ctrl+C since bitbake masks this
|
|
|
|
def signal_handler(signal, frame):
|
|
|
|
raise KeyboardInterrupt
|
|
|
|
signal.signal(signal.SIGINT, signal_handler)
|
|
|
|
|
|
|
|
child = None
|
|
|
|
|
|
|
|
prompt(more)
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
(r, _, _) = select.select([sys.stdin], [], [], 1)
|
|
|
|
if not r:
|
|
|
|
continue
|
|
|
|
line = sys.stdin.readline().strip()
|
|
|
|
if not line:
|
|
|
|
prompt(more)
|
|
|
|
continue
|
|
|
|
except EOFError as e:
|
|
|
|
sys.stdout.write("\n")
|
2016-07-04 22:08:14 +00:00
|
|
|
sys.stdout.flush()
|
2014-05-27 15:09:16 +00:00
|
|
|
except (OSError, IOError) as e:
|
|
|
|
if e.errno == 11:
|
|
|
|
continue
|
|
|
|
if e.errno == 5:
|
|
|
|
return
|
|
|
|
raise
|
|
|
|
else:
|
|
|
|
if not child:
|
|
|
|
child = int(line)
|
|
|
|
continue
|
|
|
|
buf.append(line)
|
|
|
|
source = "\n".join(buf)
|
|
|
|
more = i.runsource(source, "<pyshell>")
|
|
|
|
if not more:
|
|
|
|
buf = []
|
|
|
|
prompt(more)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
i.write("\nKeyboardInterrupt\n")
|
|
|
|
buf = []
|
|
|
|
more = False
|
|
|
|
prompt(more)
|
|
|
|
except SystemExit:
|
|
|
|
# Easiest way to ensure everything exits
|
|
|
|
os.kill(child, signal.SIGTERM)
|
|
|
|
break
|
|
|
|
|
|
|
|
python do_devpyshell() {
|
|
|
|
import signal
|
|
|
|
|
|
|
|
try:
|
|
|
|
devpyshell(d)
|
|
|
|
except SystemExit:
|
|
|
|
# Stop the SIGTERM above causing an error exit code
|
|
|
|
return
|
|
|
|
finally:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
addtask devpyshell after do_patch
|
|
|
|
|
|
|
|
do_devpyshell[nostamp] = "1"
|