From: Anders Heimer <anders.heimer@est.tech>
To: openembedded-core@lists.openembedded.org
Cc: Anders Heimer <anders.heimer@est.tech>,
Daniel Turull <daniel.turull@ericsson.com>
Subject: [PATCH 3/9] oe/patch: convert simple runcmd shell callers
Date: Tue, 23 Jun 2026 15:35:15 +0200 [thread overview]
Message-ID: <20260623133521.17053-4-anders.heimer@est.tech> (raw)
In-Reply-To: <20260623133521.17053-1-anders.heimer@est.tech>
Replace simple sh -c runcmd() users with direct argv calls where the
commands do not need shell syntax.
Also replace the cat-to-file redirection used when appending patch files
with shutil.copyfile().
Reviewed-by: Daniel Turull <daniel.turull@ericsson.com>
Signed-off-by: Anders Heimer <anders.heimer@est.tech>
---
meta/lib/oe/patch.py | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index b152a2d784..290eb990f1 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -195,10 +195,12 @@ class PatchTree(PatchSet):
bb.utils.mkdirhier(self.patchdir)
def _appendPatchFile(self, patch, strippath):
+ import shutil
+
with open(self.seriespath, 'a') as f:
f.write(os.path.basename(patch) + "," + strippath + "\n")
- shellcmd = ["cat", patch, ">" , self.patchdir + "/" + os.path.basename(patch)]
- runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+ dest = os.path.join(self.patchdir, os.path.basename(patch))
+ shutil.copyfile(patch, dest)
def _removePatch(self, p):
patch = {}
@@ -433,8 +435,8 @@ class GitApplyTree(PatchTree):
outlines, author, date, subject = GitApplyTree.interpretPatchHeader(lines)
if not author or not subject or not date:
try:
- shellcmd = ["git", "log", "--format=email", "--follow", "--diff-filter=A", "--", patchfile]
- out = runcmd(["sh", "-c", " ".join(shellcmd)], os.path.dirname(patchfile))
+ cmd = ["git", "log", "--format=email", "--follow", "--diff-filter=A", "--", patchfile]
+ out = runcmd(cmd, os.path.dirname(patchfile))
except CmdError:
out = None
if out:
@@ -525,11 +527,11 @@ class GitApplyTree(PatchTree):
patches = []
try:
for name, rev in startcommits.items():
- shellcmd = ["git", "format-patch", "--no-signature", "--no-numbered", rev, "-o", tempdir]
+ cmd = ["git", "format-patch", "--no-signature", "--no-numbered", rev, "-o", tempdir]
if paths:
- shellcmd.append('--')
- shellcmd.extend(paths)
- out = runcmd(["sh", "-c", " ".join(shellcmd)], os.path.join(tree, name))
+ cmd.append('--')
+ cmd.extend(paths)
+ out = runcmd(cmd, os.path.join(tree, name))
if out:
for srcfile in out.split():
# This loop, which is used to remove any line that
@@ -585,11 +587,11 @@ class GitApplyTree(PatchTree):
def _commitpatch(self, patch, patchfilevar):
output = ""
# Add all files
- shellcmd = ["git", "add", "-f", "-A", "."]
- output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+ cmd = ["git", "add", "-f", "-A", "."]
+ output += runcmd(cmd, self.dir)
# Exclude the patches directory
- shellcmd = ["git", "reset", "HEAD", self.patchdir]
- output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+ cmd = ["git", "reset", "HEAD", self.patchdir]
+ output += runcmd(cmd, self.dir)
# Commit the result
(tmpfile, shellcmd) = self.prepareCommit(patch['file'], self.commituser, self.commitemail)
try:
@@ -642,21 +644,21 @@ class GitApplyTree(PatchTree):
except CmdError:
# Need to abort the git am, or we'll still be within it at the end
try:
- shellcmd = ["git", "--work-tree=%s" % reporoot, "am", "--abort"]
- runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+ cmd = ["git", "--work-tree=%s" % reporoot, "am", "--abort"]
+ runcmd(cmd, self.dir)
except CmdError:
pass
# git am won't always clean up after itself, sadly, so...
- shellcmd = ["git", "--work-tree=%s" % reporoot, "reset", "--hard", "HEAD"]
- runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+ cmd = ["git", "--work-tree=%s" % reporoot, "reset", "--hard", "HEAD"]
+ runcmd(cmd, self.dir)
# Also need to take care of any stray untracked files
- shellcmd = ["git", "--work-tree=%s" % reporoot, "clean", "-f"]
- runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+ cmd = ["git", "--work-tree=%s" % reporoot, "clean", "-f"]
+ runcmd(cmd, self.dir)
# Fall back to git apply
- shellcmd = ["git", "--git-dir=%s" % reporoot, "apply", "-p%s" % patch['strippath']]
+ cmd = ["git", "--git-dir=%s" % reporoot, "apply", "-p%s" % patch['strippath']]
try:
- output = _applypatchhelper(shellcmd, patch, force, reverse, run)
+ output = _applypatchhelper(cmd, patch, force, reverse, run)
except CmdError:
# Fall back to patch
output = PatchTree._applypatch(self, patch, force, reverse, run)
next prev parent reply other threads:[~2026-06-23 13:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 13:35 [PATCH 0/9] oe/patch: execute patch commands without an implicit shell Anders Heimer
2026-06-23 13:35 ` [PATCH 1/9] oe/patch: drop shell=True from runcmd Anders Heimer
2026-06-23 13:35 ` [PATCH 2/9] oeqa/oelib: add runcmd tests Anders Heimer
2026-06-23 13:35 ` Anders Heimer [this message]
2026-06-23 13:35 ` [PATCH 4/9] oe/patch: avoid shell pipeline in _applypatch Anders Heimer
2026-06-23 13:35 ` [PATCH 5/9] oe/patch: remove obsolete PATCHFILE assignment Anders Heimer
2026-06-23 13:35 ` [PATCH 6/9] oeqa/oelib: test GitApplyTree patch names Anders Heimer
2026-06-23 13:35 ` [PATCH 7/9] oe/patch: pass GitApplyTree commands as argv lists Anders Heimer
2026-06-23 13:35 ` [PATCH 8/9] oe/patch: return manual-resolution " Anders Heimer
2026-06-23 13:35 ` [PATCH 9/9] oeqa/oelib: test patch command argv handling Anders Heimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260623133521.17053-4-anders.heimer@est.tech \
--to=anders.heimer@est.tech \
--cc=daniel.turull@ericsson.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox