patch.bbclass/devshell.bbclass: Switch to new form of interactive task handling as...
authorRichard Purdie <rpurdie@rpsys.net>
Mon, 9 Apr 2007 21:50:12 +0000 (21:50 +0000)
committerRichard Purdie <rpurdie@rpsys.net>
Mon, 9 Apr 2007 21:50:12 +0000 (21:50 +0000)
classes/devshell.bbclass
classes/patch.bbclass
conf/bitbake.conf

index 14f957e..06152ef 100644 (file)
@@ -2,9 +2,10 @@ EXTRA_OEMAKE[export] = "1"
 
 do_devshell[dirs] = "${S}"
 do_devshell[nostamp] = "1"
-do_devshell[interactive] = "1"
+
 devshell_do_devshell() {
-       bash -i
+       export TERMWINDOWTITLE="Bitbake Developer Shell"
+       ${TERMCMD}
 }
 addtask devshell after do_patch
 
index 07d1847..a28f889 100644 (file)
@@ -128,11 +128,14 @@ def patch_init(d):
                                i = 0
                        self.patches.insert(i, patch)
 
-               def _applypatch(self, patch, force = None, reverse = None):
+               def _applypatch(self, patch, force = False, reverse = False, run = True):
                        shellcmd = ["cat", patch['file'], "|", "patch", "-p", patch['strippath']]
                        if reverse:
                                shellcmd.append('-R')
 
+                       if not run:
+                               return "sh" + "-c" + " ".join(shellcmd)
+
                        if not force:
                                shellcmd.append('--dry-run')
 
@@ -145,7 +148,7 @@ def patch_init(d):
                        output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
                        return output
 
-               def Push(self, force = None, all = None):
+               def Push(self, force = False, all = False, run = True):
                        bb.note("self._current is %s" % self._current)
                        bb.note("patches is %s" % self.patches)
                        if all:
@@ -162,7 +165,7 @@ def patch_init(d):
                                else:
                                        self._current = 0
                                bb.note("applying patch %s" % self.patches[self._current])
-                               self._applypatch(self.patches[self._current], force)
+                               return self._applypatch(self.patches[self._current], force)
 
 
                def Pop(self, force = None, all = None):
@@ -176,7 +179,9 @@ def patch_init(d):
                        """"""
 
        class QuiltTree(PatchSet):
-               def _runcmd(self, args):
+               def _runcmd(self, args, run = True):
+                       if not run:
+                               return ["quilt"] + args
                        runcmd(["quilt"] + args, self.dir)
 
                def _quiltpatchpath(self, file):
@@ -251,7 +256,7 @@ def patch_init(d):
                        self.patches.insert(self._current or 0, patch)
 
 
-               def Push(self, force = None, all = None):
+               def Push(self, force = False, all = False, run = True):
                        # quilt push [-f]
 
                        args = ["push"]
@@ -259,6 +264,8 @@ def patch_init(d):
                                args.append("-f")
                        if all:
                                args.append("-a")
+                       if not run:
+                               return self._runcmd(args, run)
 
                        self._runcmd(args)
 
@@ -345,16 +352,31 @@ def patch_init(d):
 
                        olddir = os.path.abspath(os.curdir)
                        os.chdir(self.patchset.dir)
-                       try:
-                               self.patchset.Push(True)
-                       except CmdError, v:
-                               # Patch application failed
-                               if sys.exc_value.output.strip() == "No patches applied":
-                                       return
-                               print(sys.exc_value)
-                               print('NOTE: dropping user into a shell, so that patch rejects can be fixed manually.')
-
-                               os.system('/bin/sh')
+                       try:
+                               self.patchset.Push(False)
+                       except CmdError, v:
+                               # Patch application failed
+                               patchcmd = self.patchset.Push(True, False, False)
+                               t = bb.data.getVar('T', d, 1)
+                               if not t:
+                                       bb.msg.fatal(bb.msg.domain.Build, "T not set")
+                               bb.mkdirhier(t)
+                               import random
+                               rcfile = "%s/bashrc.%s.%s" % (t, str(os.getpid()), random.random())
+                               f = open(rcfile, "w")
+                               f.write("echo '*** Manual patch resolution mode ***'\n")
+                               f.write("echo 'Dropping to a shell, so patch rejects can be fixed manually.'\n")
+                               f.write("echo 'Run \"quilt refresh\" when patch is corrected, press CTRL+D to exit.'\n")
+                               f.write("echo ''\n")
+                               f.write(" ".join(patchcmd) + "\n")
+                               f.write("#" + bb.data.getVar('TERMCMDRUN', d, 1))
+                               f.close()
+                               os.chmod(rcfile, 0775)
+                               os.environ['TERMWINDOWTITLE'] = "Bitbake: Please fix patch rejects manually"
+                               os.environ['TERMRCFILE'] = rcfile
+                               os.system(bb.data.getVar('TERMCMDRUN', d, 1))
 
                                # Construct a new PatchSet after the user's changes, compare the
                                # sets, checking patches for modifications, and doing a remote
index e3608c3..ae26d99 100644 (file)
@@ -364,6 +364,25 @@ SRCDATE = "${DATE}"
 
 SRC_URI = "file://${FILE}"
 
+##################################################################
+# UI/Interaction Configuration
+##################################################################
+
+SHELLRCCMD = "bash --rcfile $TERMRCFILE"
+# Some common terminal programs to choose from
+GNOME_TERMCMD = 'gnome-terminal --disable-factory -t "$TERMWINDOWTITLE"'
+GNOME_TERMCMDRUN = '${GNOME_TERMCMD} -x ${SHELLRCCMD}'
+SCREEN_TERMCMD = 'screen -D -m -t "$TERMWINDOWTITLE"'
+SCREEN_TERMCMDRUN = '${SCREEN_TERMCMD} ${SHELLRCCMD}'
+XTERM_TERMCMD = 'xterm -T "$TERMWINDOWTITLE"'
+XTERM_TERMCMDRUN = '${XTERM_TERMCMD} -e ${SHELLRCCMD}'
+KONSOLE_TERMCMD = 'konsole -T "$TERMWINDOWTITLE"'
+KONSOLE_TERMCMDRUN = '${KCONSOLE_TERMCMD} -e ${SHELLRCCMD}'
+
+# Set a default
+TERMCMD ?= "${GNOME_TERMCMD}"
+TERMCMDRUN ?= "${GNOME_TERMCMDRUN}"
+
 ##################################################################
 # Miscellaneous utilities.
 ##################################################################