From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: adrian.freihofer@siemens.com, openembedded-core@lists.openembedded.org
Subject: Re: [OE-core] [PATCH v2 15/25] runqemu-extract-sdk: refactor in Python
Date: Thu, 03 Sep 2026 12:36:39 +0100 [thread overview]
Message-ID: <a4725550357587748e1c4ae6cd76690886c6f596.camel@linuxfoundation.org> (raw)
In-Reply-To: <20260830214912.1346063-16-adrian.freihofer@siemens.com>
On Sun, 2026-08-30 at 23:48 +0200, Adrian Freihofer via lists.openembedded.org wrote:
> From: Adrian Freihofer <adrian.freihofer@siemens.com>
>
> Move the pseudo-backed rootfs extraction logic into a reusable Python
> module while preserving the existing command interface.
> Install the module with qemu-helper so the wrapper also works from an SDK.
>
> AI-Generated: Uses GitHub Copilot
>
> Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
> ---
> .../qemu/nativesdk-qemu-helper_1.0.bb | 3 +
> scripts/lib/runqemu_utils.py | 124 ++++++++++++++++++
> scripts/runqemu-extract-sdk | 103 +--------------
> 3 files changed, 133 insertions(+), 97 deletions(-)
> create mode 100644 scripts/lib/runqemu_utils.py
>
> diff --git a/meta/recipes-devtools/qemu/nativesdk-qemu-helper_1.0.bb b/meta/recipes-devtools/qemu/nativesdk-qemu-helper_1.0.bb
> index e1f343989a..16fc07fadf 100644
> --- a/meta/recipes-devtools/qemu/nativesdk-qemu-helper_1.0.bb
> +++ b/meta/recipes-devtools/qemu/nativesdk-qemu-helper_1.0.bb
> @@ -9,6 +9,7 @@ RDEPENDS:${PN} = "nativesdk-qemu nativesdk-unfs3 nativesdk-pseudo \
> LIC_FILES_CHKSUM = "file://${COREBASE}/scripts/runqemu;beginline=5;endline=10;md5=ac2b489a58739c7628a2604698db5e7f"
>
> SRC_URI = "file://${COREBASE}/scripts/runqemu \
> + file://${COREBASE}/scripts/lib/runqemu_utils.py \
> file://${COREBASE}/scripts/runqemu-addptable2image \
> file://${COREBASE}/scripts/runqemu-gen-tapdevs \
> file://${COREBASE}/scripts/runqemu-ifup \
> @@ -30,4 +31,6 @@ do_install() {
> install -d ${D}${bindir}
> install -m 0755 ${S}${COREBASE}/scripts/oe-* ${D}${bindir}/
> install -m 0755 ${S}${COREBASE}/scripts/runqemu* ${D}${bindir}/
> + # The runqemu-* wrappers import this module from their own directory.
> + install -m 0644 ${S}${COREBASE}/scripts/lib/runqemu_utils.py ${D}${bindir}/
> }
> diff --git a/scripts/lib/runqemu_utils.py b/scripts/lib/runqemu_utils.py
> new file mode 100644
> index 0000000000..dff0ca8d3a
> --- /dev/null
> +++ b/scripts/lib/runqemu_utils.py
> @@ -0,0 +1,124 @@
> +#!/usr/bin/env python3
> +#
> +# Helpers shared by runqemu and NFS-rootfs preparation tools.
> +#
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +"""Extract and export rootfs tarballs for NFS booting."""
> +
> +import os
> +import subprocess
> +import sys
> +
> +
> +class RunQemuRootfsError(Exception):
> + """Raised when an NFS rootfs cannot be prepared or exported."""
> +
> +
> +def native_environment():
> + """Return the qemu-helper-native environment set by oe-find-native-sysroot."""
> + command = '''
> + helper=$(command -v oe-find-native-sysroot) || exit 127
> + . "$helper" qemu-helper-native >/dev/null
> + env -0
> + printf 'PSEUDO=%s\\0OECORE_NATIVE_SYSROOT=%s\\0' "$PSEUDO" "$OECORE_NATIVE_SYSROOT"
> + '''
> + result = subprocess.run(['bash', '-c', command], capture_output=True)
> + if result.returncode:
> + if result.returncode == 127:
> + raise RunQemuRootfsError(
> + 'Unable to find the oe-find-native-sysroot script.\n'
> + 'Did you forget to source your build system environment setup script?')
> + raise RunQemuRootfsError(
> + result.stderr.decode(errors='replace').strip() or
> + 'Unable to set up the qemu-helper-native sysroot')
> +
> + environment = {}
> + for entry in result.stdout.split(b'\0'):
> + if b'=' in entry:
> + key, value = entry.split(b'=', 1)
> + environment[key.decode()] = value.decode()
> + return environment
This takes a relatively simple shell script and turns it into python
but the python is very machine generated and probably not great for
readability or maintainability in the future.
For example, in the above we're using the shell to find oe-find-native-
sysroot. Instead we could use shutil.which(). That would make the code
a lot more pythonic and readable. It also special cases some variables
specifically so it isn't quite a generic function but it is named
generically.
> +def _tar_options(rootfs_tarball):
> + if rootfs_tarball.endswith('.tar.xz'):
> + return ['--numeric-owner', '-xJf']
> + if rootfs_tarball.endswith('.tar.bz2'):
> + return ['--numeric-owner', '-xjf']
> + if rootfs_tarball.endswith('.tar.gz'):
> + return ['--numeric-owner', '-xzf']
> + if rootfs_tarball.endswith('.tar.zst'):
> + return ['--numeric-owner', '--zstd', '-xf']
> + if rootfs_tarball.endswith('.tar'):
> + return ['--numeric-owner', '-xf']
> + raise RunQemuRootfsError(
> + 'Unable to determine sdk tarball format\n'
> + 'Accepted types: .tar / .tar.gz / .tar.bz2 / .tar.xz / .tar.zst')
A human doing this would create a table and not duplicate the data. Its
a pain to maintain in future. I appreciate it matches the shell code
but if we're going to do it, we may as well do it well.
> +def pseudo_state_dir(rootfs_dir):
> + """Return the pseudo database location associated with an extracted rootfs."""
> + rootfs_dir = os.path.realpath(rootfs_dir)
> + return os.path.join(os.path.dirname(rootfs_dir),
> + os.path.basename(rootfs_dir) + '.pseudo_state')
os.path.join(os.path.dirname(rootfs_dir), os.path.basename(rootfs_dir)) ?
really? :)
I think this needs a bit more human TLC before it could be merged...
Cheers,
Richard
next prev parent reply other threads:[~2026-09-03 11:36 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 21:48 [PATCH v2 00/25] devtool: ide-sdk: NFS/slirp support, deploy filtering, and robustness fixes AdrianF
2026-08-30 21:48 ` [PATCH v2 01/25] runqemu-extract-sdk: set PSEUDO_INCLUDE_PATHS for the extraction AdrianF
2026-08-30 21:48 ` [PATCH v2 02/25] devtool: ide-sdk: dedupe solib_search_path entries AdrianF
2026-09-03 11:18 ` [OE-core] " Richard Purdie
2026-09-03 16:06 ` Freihofer, Adrian
2026-09-03 20:21 ` Richard Purdie
2026-08-30 21:48 ` [PATCH v2 03/25] devtool: ide-sdk: VSCode IntelliSense for rootfs-dbg sources AdrianF
2026-08-30 21:48 ` [PATCH v2 04/25] cpp-example: fix stuck breakpoints when attaching and daemonize properly AdrianF
2026-08-30 21:48 ` [PATCH v2 05/25] devtool: ide-sdk: auto-write image debug settings to bbappend AdrianF
2026-08-30 21:48 ` [PATCH v2 06/25] oe-selftest: devtool ide-sdk: adapt tests for auto-written image debug settings AdrianF
2026-08-30 21:48 ` [PATCH v2 07/25] oeqa: QemuTarget: set use_slirp when slirp is in runqemuparams AdrianF
2026-08-30 21:48 ` [PATCH v2 08/25] devtool: ide-sdk: support runqemu slirp AdrianF
2026-08-30 21:48 ` [PATCH v2 09/25] devtool: ide-sdk: auto-disable ssh host key checking for loopback targets AdrianF
2026-08-30 21:48 ` [PATCH v2 10/25] oe-selftest: devtool ide-sdk: add slirp networking test AdrianF
2026-08-30 21:48 ` [PATCH v2 11/25] devtool: deploy-target: add --package/--file-glob filters AdrianF
2026-08-30 22:11 ` Patchtest results for " patchtest
2026-08-30 21:48 ` [PATCH v2 12/25] oe-selftest: devtool deploy-target: test " AdrianF
2026-08-30 21:48 ` [PATCH v2 13/25] devtool: ide-sdk: forward --package/--file-glob deploy filters AdrianF
2026-08-30 21:48 ` [PATCH v2 14/25] oe-selftest: devtool ide-sdk: cover --package filters AdrianF
2026-08-30 21:48 ` [PATCH v2 15/25] runqemu-extract-sdk: refactor in Python AdrianF
2026-09-03 11:36 ` Richard Purdie [this message]
2026-08-30 21:48 ` [PATCH v2 16/25] runqemu-export-rootfs: " AdrianF
2026-08-30 21:48 ` [PATCH v2 17/25] devtool: deploy: split ssh deployment into a separate function AdrianF
2026-08-30 21:48 ` [PATCH v2 18/25] devtool: deploy-target: allow deploying directly into a local rootfs AdrianF
2026-08-30 21:48 ` [PATCH v2 19/25] oe-selftest: devtool deploy-target: test deploying into a local rootfs path AdrianF
2026-08-30 21:48 ` [PATCH v2 20/25] oe-selftest: tinfoil: test prepared task runner AdrianF
2026-08-30 21:48 ` [PATCH v2 21/25] devtool: ide-sdk: run do_install through BitBake AdrianF
2026-08-30 21:48 ` [PATCH v2 22/25] oe-selftest: devtool ide-sdk: test install task AdrianF
2026-08-30 21:48 ` [PATCH v2 23/25] devtool: ide-sdk: support NFS rootfs AdrianF
2026-08-30 21:48 ` [PATCH v2 24/25] oe-selftest: devtool ide-sdk: test NFS debug rootfs AdrianF
2026-08-30 21:48 ` [PATCH v2 25/25] devtool: ide-sdk: fix GDB loading stale libs instead of recipe's own build AdrianF
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=a4725550357587748e1c4ae6cd76690886c6f596.camel@linuxfoundation.org \
--to=richard.purdie@linuxfoundation.org \
--cc=adrian.freihofer@siemens.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.