cutils: Introduce bundle mechanism
v8 cover cutils: Introduce bundle mechanism
Developers often run QEMU without installing. The bundle mechanism allows to look up files which should be present in installation even in such a situation.
It is a general mechanism and can find any files located relative to the installation tree. The build tree must have a new directory, qemu-bundle, to represent what files the installation tree would have for reference by the executables.
Note that this abandons compatibility with Windows older than 8 to use PathCchSkipRoot(). The extended support for the prior version, 7 ended more than 2 years ago, and it is unlikely that anyone would like to run the latest QEMU on such an old system.
v8:
* Pass absolute paths to get_relocated_path() (Paolo Bonzini)
* Use meson introspection (Paolo Bonzini)
* Drop "qga: Relocate a path emitted in the help text" as it is no longer relevant for the bundle mechanism.
v7: Properly fix --firmwarepath (Daniel P. Berrangé)
v6: Reuse get_relocated_path() in find_bundle() (Paolo Bonzini)
v5:
* Prefer qemu-bundle if it exists. (Daniel P. Berrangé)
* Check install_blobs option before installing BIOSes (Paolo Bonzini)
* Add common code to set up qemu-bundle to the top level meson.build (Paolo Bonzini)
v4:
* Add Daniel P. Berrangé to CC. Hopefully this helps merging his patch:
https://mail.gnu.org/archive/html/qemu-devel/2022-06/msg02276.html
* Rebased to the latest QEMU.
v3:
* Note that the bundle mechanism is for any files located relative to the installation tree including but not limited to datadir. (Peter Maydell)
* Fix "bridge" typo (Philippe Mathieu-Daudé)
v2: Rebased to the latest QEMU.
Akihiko Odaki (3):
cutils: Introduce bundle mechanism
datadir: Use bundle mechanism
module: Use bundle mechanism
Paolo Bonzini (1):
tests/vm: do not specify -bios option
.travis.yml | 2 +- docs/about/build-platforms.rst | 2 +- include/qemu/cutils.h | 18 +++++++-- meson.build | 4 ++ pc-bios/keymaps/meson.build | 21 +++------- pc-bios/meson.build | 13 ++----- scripts/oss-fuzz/build.sh | 2 +- scripts/symlink-install-tree.py | 37 ++++++++++++++++++ softmmu/datadir.c | 22 +---------- tests/qtest/fuzz/fuzz.c | 15 -------- tests/vm/fedora | 1 - tests/vm/freebsd | 1 - tests/vm/netbsd | 1 - tests/vm/openbsd | 1 - util/cutils.c | 68 +++++++++++++++++++++++---------- util/meson.build | 1 + util/module.c | 1 - 17 files changed, 117 insertions(+), 93 deletions(-) create mode 100755 scripts/symlink-install-tree.py
Signature · 1 line
2.32.1 (Apple Git-133)
PATCH v8 1/4 tests/vm: do not specify -bios option
From: Paolo Bonzini <[email protected]>
When running from the build tree, the executable is able to find the BIOS on its own; when running from the source tree, a firmware blob should already be installed and there is no guarantee that the one in the source tree works with the QEMU that is being used for the installation.
Just remove the -bios option, since it is unnecessary and in fact there are other x86 VM tests that do not bother specifying it.
Message-Id: <[email protected]>
--- tests/vm/fedora | 1 - tests/vm/freebsd | 1 - tests/vm/netbsd | 1 - tests/vm/openbsd | 1 - 4 files changed, 4 deletions(-)
tests/vm/fedora +0 -1
@@ -79,7 +79,6 @@ class FedoraVM(basevm.BaseVM): self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size) self.print_step("Booting installer") self.boot(img_tmp, extra_args = [ - "-bios", "pc-bios/bios-256k.bin", "-machine", "graphics=off", "-device", "VGA", "-cdrom", iso
tests/vm/freebsd +0 -1
@@ -95,7 +95,6 @@ class FreeBSDVM(basevm.BaseVM): self.print_step("Booting installer") self.boot(img_tmp, extra_args = [ - "-bios", "pc-bios/bios-256k.bin", "-machine", "graphics=off", "-device", "VGA", "-cdrom", iso
tests/vm/netbsd +0 -1
@@ -86,7 +86,6 @@ class NetBSDVM(basevm.BaseVM): self.print_step("Booting installer") self.boot(img_tmp, extra_args = [ - "-bios", "pc-bios/bios-256k.bin", "-machine", "graphics=off", "-cdrom", iso ])
tests/vm/openbsd +0 -1
@@ -82,7 +82,6 @@ class OpenBSDVM(basevm.BaseVM): self.print_step("Booting installer") self.boot(img_tmp, extra_args = [ - "-bios", "pc-bios/bios-256k.bin", "-machine", "graphics=off", "-device", "VGA", "-cdrom", iso
Signature · 1 line
2.32.1 (Apple Git-133)
PATCH v8 2/4 cutils: Introduce bundle mechanism
In reply to Akihiko OdakiDevelopers often run QEMU without installing. The bundle mechanism allows to look up files which should be present in installation even in such a situation.
It is a general mechanism and can find any files in the installation tree. The build tree will have a new directory, qemu-bundle, to represent what files the installation tree would have for reference by the executables.
Note that it abandons compatibility with Windows older than 8. The extended support for the prior version, 7 ended more than 2 years ago, and it is unlikely that someone would like to run the latest QEMU on such an old system.
--- docs/about/build-platforms.rst | 2 +- include/qemu/cutils.h | 18 +++++++-- meson.build | 4 ++ scripts/symlink-install-tree.py | 37 ++++++++++++++++++ util/cutils.c | 68 +++++++++++++++++++++++---------- util/meson.build | 1 + 6 files changed, 105 insertions(+), 25 deletions(-) create mode 100755 scripts/symlink-install-tree.py
docs/about/build-platforms.rst +1 -1
@@ -88,7 +88,7 @@ Windows The project aims to support the two most recent versions of Windows that are still supported by the vendor. The minimum Windows API that is currently -targeted is "Windows 7", so theoretically the QEMU binaries can still be run +targeted is "Windows 8", so theoretically the QEMU binaries can still be run on older versions of Windows, too. However, such old versions of Windows are not tested anymore, so it is recommended to use one of the latest versions of Windows instead.
include/qemu/cutils.h +15 -3
@@ -224,9 +224,21 @@ const char *qemu_get_exec_dir(void);* @dir: the directory (typically a `CONFIG_*DIR` variable) to be relocated. * * Returns a path for @dir that uses the directory of the running executable -* as the prefix. For example, if `bindir` is `/usr/bin` and @dir is -* `/usr/share/qemu`, the function will append `../share/qemu` to the -* directory that contains the running executable and return the result. +* as the prefix. +* +* When a directory named `qemu-bundle` exists in the directory of the running +* executable, the path to the directory will be prepended to @dir. For +* example, if the directory of the running executable is `/qemu/build` @dir +* is `/usr/share/qemu`, the result will be +* `/qemu/build/qemu-bundle/usr/share/qemu`. The directory is expected to exist +* in the build tree. +* +* Otherwise, the directory of the running executable will be used as the +* prefix and it appends the relative path from `bindir` to @dir. For example, +* if the directory of the running executable is `/opt/qemu/bin`, `bindir` is +* `/usr/bin` and @dir is `/usr/share/qemu`, the result will be +* `/opt/qemu/bin/../share/qemu`. +* * The returned string should be freed by the caller. */ char *get_relocated_path (const char *dir);
meson.build +4 -0
@@ -7,6 +7,8 @@ add_test_setup('quick', exclude_suites: ['slow', 'thorough'], is_default: true) add_test_setup('slow', exclude_suites: ['thorough'], env: ['G_TEST_SLOW=1', 'SPEED=slow']) add_test_setup('thorough', env: ['G_TEST_SLOW=1', 'SPEED=thorough']) +meson.add_postconf_script('scripts/symlink-install-tree.py') + not_found = dependency('', required: false) keyval = import('keyval') ss = import('sourceset')
@@ -356,10 +358,12 @@ nvmm =not_found hvf = not_found midl = not_found widl = not_found +pathcch = not_found host_dsosuf = '.so' if targetos == 'windows' midl = find_program('midl', required: false) widl = find_program('widl', required: false) + pathcch = cc.find_library('pathcch') socket = cc.find_library('ws2_32') winmm = cc.find_library('winmm')
scripts/symlink-install-tree.py new file +37 -0
@@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +from pathlib import Path +import errno +import json +import os +import subprocess +import sys + +def destdir_join(d1: str, d2: str) -> str: + if not d1: + return d2 + d2_path = Path(d2) + d2_parts = d2_path.parts + # c:\destdir + c:\prefix must produce c:\destdir\prefix + if d2_path.drive or d2_path.root: + d2_parts = d2_parts[1:] + return str(Path(d1, *d2_parts)) + +introspect = os.environ.get('MESONINTROSPECT') +out = subprocess.run([*introspect.split(' '), '--installed'], + stdout=subprocess.PIPE, check=True).stdout +for source, dest in json.loads(out).items(): + assert os.path.isabs(source) + bundle_dest = destdir_join('qemu-bundle', dest) + path = os.path.dirname(bundle_dest) + try: + os.makedirs(path, exist_ok=True) + except BaseException as e: + print(f'error making directory {path}', file=sys.stderr) + raise e + try: + os.symlink(source, bundle_dest) + except BaseException as e: + if not isinstance(e, OSError) or e.errno != errno.EEXIST: + print(f'error making symbolic link {dest}', file=sys.stderr) + raise e
util/cutils.c +47 -21
84 lines not on this page · raw message
util/meson.build +1 -0
@@ -23,6 +23,7 @@ util_ss.add(when: 'CONFIG_WIN32', if_true: files('event_notifier-win32.c')) util_ss.add(when: 'CONFIG_WIN32', if_true: files('oslib-win32.c')) util_ss.add(when: 'CONFIG_WIN32', if_true: files('qemu-thread-win32.c')) util_ss.add(when: 'CONFIG_WIN32', if_true: winmm) +util_ss.add(when: 'CONFIG_WIN32', if_true: pathcch) util_ss.add(files('envlist.c', 'path.c', 'module.c')) util_ss.add(files('host-utils.c')) util_ss.add(files('bitmap.c', 'bitops.c'))
Signature · 1 line
2.32.1 (Apple Git-133)
Quoted 31 lines · Akihiko Odaki
Developers often run QEMU without installing. The bundle mechanism allows to look up files which should be present in installation even in such a situation.
It is a general mechanism and can find any files in the installation tree. The build tree will have a new directory, qemu-bundle, to represent what files the installation tree would have for reference by the executables.
Note that it abandons compatibility with Windows older than 8. The extended support for the prior version, 7 ended more than 2 years ago, and it is unlikely that someone would like to run the latest QEMU on such an old system.
Signed-off-by Akihiko Odaki <[email protected]>Suggested-by Paolo Bonzini <[email protected]>--- docs/about/build-platforms.rst | 2 +- include/qemu/cutils.h | 18 +++++++-- meson.build | 4 ++ scripts/symlink-install-tree.py | 37 ++++++++++++++++++ util/cutils.c | 68 +++++++++++++++++++++++---------- util/meson.build | 1 + 6 files changed, 105 insertions(+), 25 deletions(-)create mode 100755
scripts/symlink-install-tree.pydocs/about/build-platforms.rst +0
-0
docs/about/build-platforms.rst Windows · line 94
Quoted 8 lines
docs/about/build-platforms.rst +1
-1@@ -88,7 +88,7 @@ Windows The project aims to support the two most recent versions of Windows that are still supported by the vendor. The minimum Windows API that is currently -targeted is "Windows 7", so theoretically the QEMU binaries can still be run +targeted is "Windows 8", so theoretically the QEMU binaries can still be run on older versions of Windows, too. However, such old versions of Windows are not tested anymore, so it is recommended to use one of the latest versions of Windows instead.
Please update _WIN32_WINNT in include/qemu/osdep.h accordingly.
Thanks,
Thomas
PATCH v8 3/4 datadir: Use bundle mechanism
In reply to Akihiko Odakisoftmmu/datadir.c had its own implementation to find files in the build tree, but now bundle mechanism provides the unified implementation which works for datadir and the other files.
--- .travis.yml | 2 +- pc-bios/keymaps/meson.build | 21 ++++++--------------- pc-bios/meson.build | 13 +++---------- scripts/oss-fuzz/build.sh | 2 +- softmmu/datadir.c | 22 +--------------------- tests/qtest/fuzz/fuzz.c | 15 --------------- 6 files changed, 12 insertions(+), 63 deletions(-)
.travis.yml +1 -1
@@ -223,7 +223,7 @@ jobs: - BUILD_RC=0 && make -j${JOBS} || BUILD_RC=$? - | if [ "$BUILD_RC" -eq 0 ] ; then - mv pc-bios/s390-ccw/*.img pc-bios/ ; + mv pc-bios/s390-ccw/*.img qemu-bundle/usr/local/share/qemu ; ${TEST_CMD} ; else $(exit $BUILD_RC);
pc-bios/keymaps/meson.build +6 -15
@@ -40,9 +40,9 @@ else endif cp = find_program('cp') -t = [] -foreach km, args: keymaps - if native_qemu_keymap.found() +if native_qemu_keymap.found() + t = [] + foreach km, args: keymaps # generate with qemu-kvm t += custom_target(km, build_by_default: true,
@@ -50,20 +50,11 @@ foreach km, args: keymaps command: [native_qemu_keymap, '-f', '@OUTPUT@', args.split()], install: true, install_dir: qemu_datadir / 'keymaps') - else - # copy from source tree - t += custom_target(km, - build_by_default: true, - input: km, - output: km, - command: [cp, '@INPUT@', '@OUTPUT@'], - install: true, - install_dir: qemu_datadir / 'keymaps') - endif -endforeach + endforeach -if native_qemu_keymap.found() alias_target('update-keymaps', t) +else + install_data(keymaps.keys(), install_dir: qemu_datadir / 'keymaps') endif install_data(['sl', 'sv'], install_dir: qemu_datadir / 'keymaps')
pc-bios/meson.build +3 -10
@@ -85,16 +85,9 @@ blobs = [ 'vof-nvram.bin', ] -ln_s = [find_program('ln', required: true), '-sf'] -foreach f : blobs - roms += custom_target(f, - build_by_default: have_system, - output: f, - input: files('meson.build'), # dummy input - install: get_option('install_blobs'), - install_dir: qemu_datadir, - command: [ ln_s, meson.project_source_root() / 'pc-bios' / f, '@OUTPUT@' ]) -endforeach +if get_option('install_blobs') + install_data(blobs, install_dir: qemu_datadir) +endif subdir('descriptors') subdir('keymaps')
scripts/oss-fuzz/build.sh +1 -1
@@ -88,7 +88,7 @@ if [ "$GITLAB_CI" != "true" ]; then fi # Copy over the datadir -cp -r ../pc-bios/ "$DEST_DIR/pc-bios" +cp -r ../pc-bios/ "$DEST_DIR/data" targets=$(./qemu-fuzz-i386 | awk '$1 ~ /\*/ {print $2}') base_copy="$DEST_DIR/qemu-fuzz-i386-target-$(echo "$targets" | head -n 1)"
softmmu/datadir.c +1 -21
@@ -83,26 +83,6 @@ void qemu_add_data_dir(char *path) data_dir[data_dir_idx++] = path; } -/* -* Find a likely location for support files using the location of the binary. -* When running from the build tree this will be "$bindir/pc-bios". -* Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated). -* -* The caller must use g_free() to free the returned data when it is -* no longer required. -*/ -static char *find_datadir (void ) -{ - g_autofree char *dir = NULL; - - dir =g_build_filename (qemu_get_exec_dir (),"pc-bios" ,NULL ); -if (g_file_test (dir,G_FILE_TEST_IS_DIR )) { -return g_steal_pointer (&dir); - } - -return get_relocated_path (CONFIG_QEMU_DATADIR ); -} -void qemu_add_default_firmwarepath (void ) {char **dirs;
@@ -116,7 +96,7 @@ void qemu_add_default_firmwarepath(void)g_strfreev (dirs);/* try to find datadir relative to the executable path */ -qemu_add_data_dir (find_datadir ()); +qemu_add_data_dir (get_relocated_path (CONFIG_QEMU_DATADIR )); }void qemu_list_data_dirs (void )
tests/qtest/fuzz/fuzz.c +0 -15
@@ -174,21 +174,6 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp) target_name =strstr (**argv,"-target-" );if (target_name) {/* The binary name specifies the target */ target_name +=strlen ("-target-" ); -/* -* With oss-fuzz, the executable is kept in the root of a directory (we -* cannot assume the path). All data (including bios binaries) must be -* in the same dir, or a subdir. Thus, we cannot place the pc-bios so -* that it would be in exec_dir/../pc-bios. -* As a workaround, oss-fuzz allows us to use argv[0] to get the -* location of the executable. Using this we add exec_dir/pc-bios to -* the datadirs. -*/ - bindir =qemu_get_exec_dir (); - datadir =g_build_filename (bindir,"pc-bios" ,NULL ); -if (g_file_test (datadir,G_FILE_TEST_IS_DIR )) { -qemu_add_data_dir (datadir); - }else { -g_free (datadir); } }else if (*argc >1 ) {/* The target is specified as an argument */ target_name = (*argv)[1 ];
Signature · 1 line
2.32.1 (Apple Git-133)
PATCH v8 4/4 module: Use bundle mechanism
In reply to Akihiko OdakiBefore this change, the directory of the executable was being added to resolve modules in the build tree. However, get_relocated_path() can now resolve them with the new bundle mechanism.
--- util/module.c | 1 - 1 file changed, 1 deletion(-)
util/module.c +0 -1
@@ -274,7 +274,6 @@ bool module_load_one(const char *prefix, const char *lib_name, bool mayfail) dirs[n_dirs++] =g_strdup_printf ("%s" , search_dir); } dirs[n_dirs++] =get_relocated_path (CONFIG_QEMU_MODDIR ); - dirs[n_dirs++] =g_strdup (qemu_get_exec_dir ());#ifdef CONFIG_MODULE_UPGRADES version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
Signature · 1 line
2.32.1 (Apple Git-133)
Quoted 9 lines · Akihiko Odaki
Developers often run QEMU without installing. The bundle mechanism allows to look up files which should be present in installation even in such a situation.
It is a general mechanism and can find any files located relative to the installation tree. The build tree must have a new directory, qemu-bundle, to represent what files the installation tree would have for reference by the executables.
Quoted 4 lines
Note that this abandons compatibility with Windows older than 8 to use
PathCchSkipRoot(). The extended support for the prior version, 7 ended more than 2 years ago, and it is unlikely that anyone would like to run the latest QEMU on such an old system.
Thanks, this looks good. Even though technically it adds more lines than it removes (thanks Windows...), it replaces lots of special cases with a single general mechanism, which is nice and future proof.
The only change I'd make (which I can do when queueing the patch) is to change the directory name to something "strange" like "=install", so that it's unlikely to have a directory named like that in the $bindir.
Any opinions?
Paolo
Quoted 56 lines
v8:
* Pass absolute paths toget_relocated_path()(Paolo Bonzini)
* Use meson introspection (Paolo Bonzini)
* Drop "qga: Relocate a path emitted in the help text" as it is no longer relevant for the bundle mechanism.v7: Properly fix --firmwarepath (Daniel P. Berrangé)
v6: Reuse
get_relocated_path()infind_bundle()(Paolo Bonzini)v5:
* Prefer qemu-bundle if it exists. (Daniel P. Berrangé)
* Checkinstall_blobsoption before installing BIOSes (Paolo Bonzini)
* Add common code to set up qemu-bundle to the top level meson.build (Paolo Bonzini)v4:
* Add Daniel P. Berrangé to CC. Hopefully this helps merging his patch:https://mail.gnu.org/archive/html/qemu-devel/2022-06/msg02276.html* Rebased to the latest QEMU.
v3:
* Note that the bundle mechanism is for any files located relative to the installation tree including but not limited to datadir. (Peter Maydell)
* Fix "bridge" typo (Philippe Mathieu-Daudé)v2: Rebased to the latest QEMU.
Akihiko Odaki (3):
cutils: Introduce bundle mechanism
datadir: Use bundle mechanism
module: Use bundle mechanismPaolo Bonzini (1):
tests/vm: do not specify -bios option.travis.yml | 2 +- docs/about/build-platforms.rst | 2 +- include/qemu/cutils.h | 18 +++++++-- meson.build | 4 ++ pc-bios/keymaps/meson.build | 21 +++------- pc-bios/meson.build | 13 ++----- scripts/oss-fuzz/build.sh | 2 +- scripts/symlink-install-tree.py | 37 ++++++++++++++++++ softmmu/datadir.c | 22 +---------- tests/qtest/fuzz/fuzz.c | 15 -------- tests/vm/fedora | 1 - tests/vm/freebsd | 1 - tests/vm/netbsd | 1 - tests/vm/openbsd | 1 - util/cutils.c | 68 +++++++++++++++++++++++---------- util/meson.build | 1 + util/module.c | 1 - 17 files changed, 117 insertions(+), 93 deletions(-)create mode 100755
scripts/symlink-install-tree.py
Quoted 3 lines · Paolo Bonzini
The only change I'd make (which I can do when queueing the patch) is to change the directory name to something "strange" like "=install", so that it's unlikely to have a directory named like that in the $bindir.
Any opinions?
Actually I prepended qemu- to the directory because all executables of QEMU has the prefix. We can safely say QEMU installation will never collide if no file prefixed with qemu- exists in the bindir.
If anyone has an idea what should follow "qemu-", please tell us.
Regards,
Akihiko Odaki