]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
don't reimpkemtn run() ross/split/patch
authorRoss Burton <ross.burton@arm.com>
Mon, 24 Jun 2024 14:06:56 +0000 (15:06 +0100)
committerRoss Burton <ross.burton@arm.com>
Thu, 12 Feb 2026 18:20:09 +0000 (18:20 +0000)
meta/lib/oe/patch.py

index 1372da6698b0c5ee3af0df14792736ecf7aa1b1b..cb4f0e17af948df7e906b6dbac392a36871d79f9 100644 (file)
@@ -17,47 +17,15 @@ class NotFoundError(bb.BBHandledException):
     def __str__(self):
         return "Error: %s not found." % self.path
 
-class CmdError(bb.BBHandledException):
-    def __init__(self, command, exitstatus, output):
-        self.command = command
-        self.status = exitstatus
-        self.output = output
+def runcmd(cmd, dir=None):
+    proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=dir, check=True, universal_newlines=True)
 
-    def __str__(self):
-        return "Command Error: '%s' exited with %d  Output:\n%s" % \
-                (self.command, self.status, self.output)
-
-
-def runcmd(args, dir = None):
-    if dir:
-        olddir = os.path.abspath(os.curdir)
-        if not os.path.exists(dir):
-            raise NotFoundError(dir)
-        os.chdir(dir)
-        # print("cwd: %s -> %s" % (olddir, dir))
-
-    try:
-        args = [ shlex.quote(str(arg)) for arg in args ]
-        cmd = " ".join(args)
-        # print("cmd: %s" % cmd)
-        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
-        stdout, stderr = proc.communicate()
-        stdout = stdout.decode('utf-8')
-        stderr = stderr.decode('utf-8')
-        exitstatus = proc.returncode
-        if exitstatus != 0:
-            raise CmdError(cmd, exitstatus >> 8, "stdout: %s\nstderr: %s" % (stdout, stderr))
-        if " fuzz " in stdout and "Hunk " in stdout:
-            # Drop patch fuzz info with header and footer to log file so
-            # insane.bbclass can handle to throw error/warning
-            bb.note("--- Patch fuzz start ---\n%s\n--- Patch fuzz end ---" % format(stdout))
-
-        return stdout
-
-    finally:
-        if dir:
-            os.chdir(olddir)
+    if " fuzz " in proc.stdout and "Hunk " in proc.stdout:
+        # Drop patch fuzz info with header and footer to log file so
+        # insane.bbclass can handle to throw error/warning
+        bb.note("--- Patch fuzz start ---\n%s\n--- Patch fuzz end ---" % format(stdout))
 
+    return proc.stdout
 
 class PatchError(Exception):
     def __init__(self, msg):
@@ -247,7 +215,7 @@ class PatchTree(PatchSet):
 
             shellcmd.pop(len(shellcmd) - 1)
             output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
-        except CmdError as err:
+        except subprocess.CalledProcessError as err:
             raise bb.BBHandledException("Applying '%s' failed:\n%s" %
                                         (os.path.basename(patch['file']), err.output))
 
@@ -308,7 +276,7 @@ class GitApplyTree(PatchTree):
     def _isInitialized(self, d):
         try:
             output = runcmd(["git", "rev-parse", "--show-toplevel"], self.dir).strip()
-        except CmdError:
+        except subprocess.CalledProcessError:
             ## runcmd returned non-zero which most likely means 128
             ## Not a git directory
             return False
@@ -428,7 +396,7 @@ class GitApplyTree(PatchTree):
             try:
                 cmd = ["git", "log", "--format=email", "--follow", "--diff-filter=A", "--", patchfile]
                 out = runcmd(cmd, dir=os.path.dirname(patchfile))
-            except CmdError:
+            except subprocess.CalledProcessError:
                 out = None
             if out:
                 _, newauthor, newdate, newsubject = GitApplyTree.interpretPatchHeader(out.splitlines())
@@ -487,7 +455,7 @@ class GitApplyTree(PatchTree):
         try:
             note = runcmd(["git", "notes", "--ref", GitApplyTree.notes_ref, "show", ref], repo)
             prefix = ""
-        except CmdError:
+        except subprocess.CalledProcessError:
             note = runcmd(['git', 'show', '-s', '--format=%B', ref], repo)
             prefix = "%% "
 
@@ -609,7 +577,7 @@ class GitApplyTree(PatchTree):
                 # Check dirtyness of the tree
                 try:
                     output = runcmd(["git", "--work-tree=%s" % reporoot, "status", "--short"])
-                except CmdError:
+                except subprocess.CalledProcessError:
                     pass
                 else:
                     if output:
@@ -624,11 +592,11 @@ class GitApplyTree(PatchTree):
                 shellcmd += ["am", "--committer-date-is-author-date",
                              "-3", "--keep-cr", "--no-scissors", "-p%s" % patch['strippath']]
                 return _applypatchhelper(shellcmd, patch, force, reverse, run)
-            except CmdError:
+            except subprocess.CalledProcessError:
                 # Need to abort the git am, or we'll still be within it at the end
                 try:
                     runcmd(["git", "--work-tree=%s" % reporoot, "am", "--abort"], self.dir)
-                except CmdError:
+                except subprocess.CalledProcessError:
                     pass
                 # git am won't always clean up after itself, sadly, so...
                 runcmd(["git", "--work-tree=%s" % reporoot, "reset", "--hard", "HEAD"], self.dir)
@@ -639,7 +607,7 @@ class GitApplyTree(PatchTree):
                 shellcmd = ["git", "--git-dir=%s" % reporoot, "apply", "-p%s" % patch['strippath']]
                 try:
                     output = _applypatchhelper(shellcmd, patch, force, reverse, run)
-                except CmdError:
+                except subprocess.CalledProcessError:
                     # Fall back to patch
                     output = PatchTree._applypatch(self, patch, force, reverse, run)
                 output += self._commitpatch(patch)
@@ -701,7 +669,7 @@ class QuiltTree(PatchSet):
             # determine which patches are applied -> self._current
             try:
                 output = self.run_quilt(["applied"])
-            except CmdError:
+            except subprocess.CalledProcessError:
                 import sys
                 if sys.exc_value.output.strip() == "No patches applied":
                     return
@@ -831,7 +799,7 @@ class UserResolver(Resolver):
         os.chdir(self.patchset.dir)
         try:
             self.patchset.Push(False)
-        except CmdError:
+        except subprocess.CalledProcessError:
             # Patch application failed
             patchcmd = self.patchset.Push(True, False, False)