lib/classes/conf: refactor qemu.bbclass functions into library functions
PATCH v5 1/1 lib/classes/conf: refactor qemu.bbclass functions into library functions
From: Chen Qi <[email protected]>
Move the functions in qemu.bbclass to meta/lib/oe/qemu.py as they are generally useful.
Now the QEMU_OPTIONS settings are moved to bitbake.conf as they are needed for qemu.py functions to work well.
The qemu.bbclass is still kept, and recipes can continue to use functions from it, though they have become wrapper functions on qemu.py functions.
--- meta/classes-recipe/qemu.bbclass | 51 ++---------------------------- meta/conf/bitbake.conf | 9 ++++++ meta/lib/oe/__init__.py | 2 +- meta/lib/oe/qemu.py | 54 ++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 49 deletions(-) create mode 100644 meta/lib/oe/qemu.py
meta/classes-recipe/qemu.bbclass +3 -48
@@ -10,55 +10,10 @@ # def qemu_target_binary(data): - package_arch = data.getVar("PACKAGE_ARCH") - qemu_target_binary = (data.getVar("QEMU_TARGET_BINARY_%s" % package_arch) or "") - if qemu_target_binary: - return qemu_target_binary - - target_arch = data.getVar("TARGET_ARCH") - if target_arch in ("i486", "i586", "i686"): - target_arch = "i386" - elif target_arch == "powerpc": - target_arch = "ppc" - elif target_arch == "powerpc64": - target_arch = "ppc64" - elif target_arch == "powerpc64le": - target_arch = "ppc64le" - - return "qemu-" + target_arch + return oe.qemu.qemu_target_binary(data) def qemu_wrapper_cmdline(data, rootfs_path, library_paths): - import string - - qemu_binary = qemu_target_binary(data) - if qemu_binary == "qemu-allarch": - qemu_binary = "qemuwrapper" - - qemu_options = data.getVar("QEMU_OPTIONS") or "" - - return "PSEUDO_UNLOAD=1 " + qemu_binary + " " + qemu_options + " -L " + rootfs_path\ - + " -E LD_LIBRARY_PATH=" + ":".join(library_paths) + " " + return oe.qemu.qemu_wrapper_cmdline(data, rootfs_path, library_paths) -# Next function will return a string containing the command that is needed to -# to run a certain binary through qemu. For example, in order to make a certain -# postinstall scriptlet run at do_rootfs time and running the postinstall is -# architecture dependent, we can run it through qemu. For example, in the -# postinstall scriptlet, we could use the following: -# -# ${@qemu_run_binary(d, '$D', '/usr/bin/test_app')} [test_app arguments] -# def qemu_run_binary(data, rootfs_path, binary): - libdir = rootfs_path + data.getVar("libdir", False) - base_libdir = rootfs_path + data.getVar("base_libdir", False) - - return qemu_wrapper_cmdline(data, rootfs_path, [libdir, base_libdir]) + rootfs_path + binary - -# QEMU_EXTRAOPTIONS is not meant to be directly used, the extensions are -# PACKAGE_ARCH, *NOT* overrides. -# In some cases (e.g. ppc) simply being arch specific (apparently) isn't good -# enough and a PACKAGE_ARCH specific -cpu option is needed (hence we have to do -# this dance). For others (e.g. arm) a -cpu option is not necessary, since the -# qemu-arm default CPU supports all required architecture levels. - -QEMU_OPTIONS = "-r ${OLDEST_KERNEL} ${@d.getVar("QEMU_EXTRAOPTIONS:tune-%s" % d.getVar('TUNE_PKGARCH')) or ""}" -QEMU_OPTIONS[vardeps] += "QEMU_EXTRAOPTIONS:tune-${TUNE_PKGARCH}" + return oe.qemu.qemu_run_binary(data, rootfs_path, binary)
meta/conf/bitbake.conf +9 -0
@@ -892,6 +892,15 @@ ZSTD_DEFAULTS[vardepsexclude] = "ZSTD_THREADS" # may fallback to using all CPUs export OMP_NUM_THREADS = "${BB_NUMBER_THREADS}" +# QEMU_EXTRAOPTIONS is not meant to be directly used, the extensions are +# PACKAGE_ARCH, *NOT* overrides. +# In some cases (e.g. ppc) simply being arch specific (apparently) isn't good +# enough and a PACKAGE_ARCH specific -cpu option is needed (hence we have to do +# this dance). For others (e.g. arm) a -cpu option is not necessary, since the +# qemu-arm default CPU supports all required architecture levels. +QEMU_OPTIONS = "-r ${OLDEST_KERNEL} ${@d.getVar("QEMU_EXTRAOPTIONS:tune-%s" % d.getVar('TUNE_PKGARCH')) or ""}" +QEMU_OPTIONS[vardeps] += "QEMU_EXTRAOPTIONS:tune-${TUNE_PKGARCH}" + ################################################################## # Magic Cookie for SANITY CHECK ##################################################################
meta/lib/oe/__init__.py +1 -1
@@ -10,6 +10,6 @@ __path__ = extend_path(__path__, __name__) # Modules with vistorcode need to go first else anything depending on them won't be # processed correctly (e.g. qa) BBIMPORTS = ["qa", "data", "path", "utils", "types", "package", "packagedata", \ - "packagegroup", "sstatesig", "lsb", "cachedpath", "license", \ + "packagegroup", "sstatesig", "lsb", "cachedpath", "license", "qemu", \ "reproducible", "rust", "buildcfg", "go", "spdx30_tasks", "spdx_common", \ "cve_check"]
meta/lib/oe/qemu.py new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 7 lines · Chen Qi via lists.openembedded.org
From: Chen Qi <[email protected]>
Move the functions in qemu.bbclass to
meta/lib/oe/qemu.pyas they are generally useful.Now the
QEMU_OPTIONSsettings are moved to bitbake.conf as they are needed forqemu.pyfunctions to work well.
This is the bit I disagree with, I'm not sure these should move.
I want it to be difficult/obvious for people to be using user mode qemu, it is not something we want to encourage or make too easy.
The reason is that we target many platforms with aren't supported by user mode qemu. I don't want the project to gain a dependency on qemu user mode support by stealth.
Cheers,
Richard
Quoted 13 lines · Richard Purdie
Quoted 7 lines · Chen Qi via lists.openembedded.org
From: Chen Qi <[email protected]>
Move the functions in qemu.bbclass to
meta/lib/oe/qemu.pyas they are generally useful.Now the
QEMU_OPTIONSsettings are moved to bitbake.conf as they are needed forqemu.pyfunctions to work well.This is the bit I disagree with, I'm not sure these should move.
I want it to be difficult/obvious for people to be using user mode qemu, it is not something we want to encourage or make too easy.
Quoted 7 lines
The reason is that we target many platforms with aren't supported by user mode qemu. I don't want the project to gain a dependency on qemu user mode support by stealth.
Cheers,
Richard
Got it. Thanks a lot for your detailed explanation. I'll send out a new patch.
By the way, I totally agree that Yocto should not gain a dependency on qemu user mode support.
Regards,
Qi