From nobody Mon Feb 9 23:17:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1657789832; cv=none; d=zohomail.com; s=zohoarc; b=P7toS+OW/Fe+5scovMbvX2oQzgFbhiCcD9FZLQpC1pLx2bXOMILgjY+JDSoCvOPT0olG5VylQeYvteWcghJjNMKsSDXvV2lql2JACNw5w/UyYh8OiI+2sPwsDSOnpoUXYvovtjscf9+5UkF2Wu62VV1dbD78YVwX2Ym/khduWtQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657789832; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fX03v0kOkH7rjZboIn4udYC6Bm8zLRFu9JPvkv7s92s=; b=G1IfXO3LJlazwRr3pvkLUcrG3bxptoV7EbPxIswsBShx9OnX7uwD7cB/8biYEQbINniDLKVdc2TnMk0J2rAIcx23D9XBirvB1bDeNbZR3E6lk/bf+UFnpBUQmuOmOKZheia1z+h0NyGGpGHiYtf97VBzroek7qD1/rsM6rpMuvw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165778983239213.886313176173417; Thu, 14 Jul 2022 02:10:32 -0700 (PDT) Received: from localhost ([::1]:55920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBurf-0002mH-9r for importer@patchew.org; Thu, 14 Jul 2022 05:10:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBujn-00050s-Vt for qemu-devel@nongnu.org; Thu, 14 Jul 2022 05:02:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBujl-0005uO-LA for qemu-devel@nongnu.org; Thu, 14 Jul 2022 05:02:23 -0400 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-77--iWUFzGwOOKGq5lizLeVCA-1; Thu, 14 Jul 2022 05:02:19 -0400 Received: by mail-ed1-f69.google.com with SMTP id m13-20020a056402430d00b0043ac2f27d83so1098907edc.20 for ; Thu, 14 Jul 2022 02:02:19 -0700 (PDT) Received: from goa-sendmail ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id b6-20020a170906038600b00711edab7622sm455347eja.40.2022.07.14.02.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 02:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657789340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fX03v0kOkH7rjZboIn4udYC6Bm8zLRFu9JPvkv7s92s=; b=dr98QUMLzqy5x/ecMJbL8/DuI7APbcNE5FnYIwtOTV2CZ1lNsD921AjE+rFwln+VoHQ9BZ Naud8clZ+yjBqpXyMW6PRLxKhyhHZHsBTG3kQKzUL4H0T8q81pbb4bzC5OHRjRpcbVSiv0 iiZqPBikPgL8lJrLao4jdfzgg9zP0f8= X-MC-Unique: -iWUFzGwOOKGq5lizLeVCA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fX03v0kOkH7rjZboIn4udYC6Bm8zLRFu9JPvkv7s92s=; b=oJ4eH9ZBNp9dog1SCnul2RF5RTOne0oIiMTWtEHcibrGYPmXhqY4DA7aalWSLP4GYI /9GgCmLtSpuJLnQWWHVb9kXgN9JaTgwmz9yYuPkIgBMPO22K/l28XTOFRzeVfmZE4Pph LS6sjOpnJcKa7pdq67o1p7xrZMER54dOzS6w8LH8UhYt62tk0ZEAoqWyDA5wjlj+QaWK OmNiFuU2t48nix94so2hggkabUvzD4LBGACC6RjsIO21//kvCpzeV/qfYDIkfm51RNOa 8Bu/9rX6Ln3IU+azItEbTTQ46pUY6dkFnfEnASOpL3/3ntHZfqTjWebbWuRjaPLIOeBZ 8Wxw== X-Gm-Message-State: AJIora9v081t0+opqcBKVx6TFfdte3PzqzSJWR+fwN8IPNSl+qggQRWJ afb1piuYHBFnhtjB3eQR2ng7DF4u0ePEcQzIstpyndzOX/8nuXIDOAP3NxXuxblc+mpJ54o/lYc q40NIZh6UCd6re9VJO99G1eF/0/cQI4vM0T7/6quOqJ9qTKIK92KtHJg6l8tN71OIDwA= X-Received: by 2002:a05:6402:42c8:b0:43a:a1ee:a097 with SMTP id i8-20020a05640242c800b0043aa1eea097mr10826056edc.150.1657789337772; Thu, 14 Jul 2022 02:02:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t8mcBP6RVEwVkjfl0g6SDFObhG/kl39YNBjb5ls03fDdfQrUyNAmpr6ZwH4rV+EX/x90MLyA== X-Received: by 2002:a05:6402:42c8:b0:43a:a1ee:a097 with SMTP id i8-20020a05640242c800b0043aa1eea097mr10826026edc.150.1657789337396; Thu, 14 Jul 2022 02:02:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PULL 02/20] cutils: Introduce bundle mechanism Date: Thu, 14 Jul 2022 11:01:53 +0200 Message-Id: <20220714090211.304305-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220714090211.304305-1-pbonzini@redhat.com> References: <20220714090211.304305-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657789832772100001 Content-Type: text/plain; charset="utf-8" From: 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 Suggested-by: Paolo Bonzini Message-Id: <20220624145039.49929-3-akihiko.odaki@gmail.com> Signed-off-by: Paolo Bonzini --- Makefile | 2 +- docs/about/build-platforms.rst | 2 +- include/qemu/cutils.h | 18 +++++++-- meson.build | 4 ++ scripts/symlink-install-tree.py | 33 +++++++++++++++++ util/cutils.c | 66 +++++++++++++++++++++++---------- util/meson.build | 1 + 7 files changed, 101 insertions(+), 25 deletions(-) create mode 100644 scripts/symlink-install-tree.py diff --git a/Makefile b/Makefile index b4feda93c8..13234f2aa4 100644 --- a/Makefile +++ b/Makefile @@ -216,7 +216,7 @@ qemu-%.tar.bz2: =20 distclean: clean -$(quiet-@)test -f build.ninja && $(NINJA) $(NINJAFLAGS) -t clean -g || : - rm -f config-host.mak + rm -f config-host.mak qemu-bundle rm -f tests/tcg/config-*.mak rm -f config.status rm -f roms/seabios/config.mak diff --git a/docs/about/build-platforms.rst b/docs/about/build-platforms.rst index 1958edb430..ebde20f981 100644 --- a/docs/about/build-platforms.rst +++ b/docs/about/build-platforms.rst @@ -88,7 +88,7 @@ Windows =20 The project aims to support the two most recent versions of Windows that a= re still supported by the vendor. The minimum Windows API that is currently -targeted is "Windows 7", so theoretically the QEMU binaries can still be r= un +targeted is "Windows 8", so theoretically the QEMU binaries can still be r= un on older versions of Windows, too. However, such old versions of Windows a= re not tested anymore, so it is recommended to use one of the latest versions= of Windows instead. diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index d3e532b64c..92c436d8c7 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -224,9 +224,21 @@ const char *qemu_get_exec_dir(void); * @dir: the directory (typically a `CONFIG_*DIR` variable) to be relocate= d. * * Returns a path for @dir that uses the directory of the running executab= le - * 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 run= ning + * executable, the path to the directory will be prepended to @dir. For + * example, if the directory of the running executable is `/qemu/build` @d= ir + * 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 exam= ple, + * 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); diff --git a/meson.build b/meson.build index ad92d288a6..da76edc7c7 100644 --- a/meson.build +++ b/meson.build @@ -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=3D= 1', 'SPEED=3Dslow']) add_test_setup('thorough', env: ['G_TEST_SLOW=3D1', 'SPEED=3Dthorough']) =20 +meson.add_postconf_script(find_program('scripts/symlink-install-tree.py')) + not_found =3D dependency('', required: false) keyval =3D import('keyval') ss =3D import('sourceset') @@ -356,10 +358,12 @@ nvmm =3Dnot_found hvf =3D not_found midl =3D not_found widl =3D not_found +pathcch =3D not_found host_dsosuf =3D '.so' if targetos =3D=3D 'windows' midl =3D find_program('midl', required: false) widl =3D find_program('widl', required: false) + pathcch =3D cc.find_library('pathcch') socket =3D cc.find_library('ws2_32') winmm =3D cc.find_library('winmm') =20 diff --git a/scripts/symlink-install-tree.py b/scripts/symlink-install-tree= .py new file mode 100644 index 0000000000..a5bf0b0d6d --- /dev/null +++ b/scripts/symlink-install-tree.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +from pathlib import PurePath +import errno +import json +import os +import subprocess +import sys + +def destdir_join(d1: str, d2: str) -> str: + if not d1: + return d2 + # c:\destdir + c:\prefix must produce c:\destdir\prefix + return str(PurePath(d1, *PurePath(d2).parts[1:])) + +introspect =3D os.environ.get('MESONINTROSPECT') +out =3D subprocess.run([*introspect.split(' '), '--installed'], + stdout=3Dsubprocess.PIPE, check=3DTrue).stdout +for source, dest in json.loads(out).items(): + assert os.path.isabs(source) + bundle_dest =3D destdir_join('qemu-bundle', dest) + path =3D os.path.dirname(bundle_dest) + try: + os.makedirs(path, exist_ok=3DTrue) + except BaseException as e: + print(f'error making directory {path}', file=3Dsys.stderr) + raise e + try: + os.symlink(source, bundle_dest) + except BaseException as e: + if not isinstance(e, OSError) or e.errno !=3D errno.EEXIST: + print(f'error making symbolic link {dest}', file=3Dsys.stderr) + raise e diff --git a/util/cutils.c b/util/cutils.c index 6d04e52907..8199dac598 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -35,6 +35,11 @@ #include #endif =20 +#ifdef G_OS_WIN32 +#include +#include +#endif + #include "qemu/ctype.h" #include "qemu/cutils.h" #include "qemu/error-report.h" @@ -1074,31 +1079,52 @@ char *get_relocated_path(const char *dir) =20 /* Fail if qemu_init_exec_dir was not called. */ assert(exec_dir[0]); - if (!starts_with_prefix(dir) || !starts_with_prefix(bindir)) { - return g_strdup(dir); - } =20 result =3D g_string_new(exec_dir); + g_string_append(result, "/qemu-bundle"); + if (access(result->str, R_OK) =3D=3D 0) { +#ifdef G_OS_WIN32 + size_t size =3D mbsrtowcs(NULL, &dir, 0, &(mbstate_t){0}) + 1; + PWSTR wdir =3D g_new(WCHAR, size); + mbsrtowcs(wdir, &dir, size, &(mbstate_t){0}); =20 - /* Advance over common components. */ - len_dir =3D len_bindir =3D prefix_len; - do { - dir +=3D len_dir; - bindir +=3D len_bindir; - dir =3D next_component(dir, &len_dir); - bindir =3D next_component(bindir, &len_bindir); - } while (len_dir && len_dir =3D=3D len_bindir && !memcmp(dir, bindir, = len_dir)); + PCWSTR wdir_skipped_root; + PathCchSkipRoot(wdir, &wdir_skipped_root); =20 - /* Ascend from bindir to the common prefix with dir. */ - while (len_bindir) { - bindir +=3D len_bindir; - g_string_append(result, "/.."); - bindir =3D next_component(bindir, &len_bindir); + size =3D wcsrtombs(NULL, &wdir_skipped_root, 0, &(mbstate_t){0}); + char *cursor =3D result->str + result->len; + g_string_set_size(result, result->len + size); + wcsrtombs(cursor, &wdir_skipped_root, size + 1, &(mbstate_t){0}); + g_free(wdir); +#else + g_string_append(result, dir); +#endif + } else if (!starts_with_prefix(dir) || !starts_with_prefix(bindir)) { + g_string_assign(result, dir); + } else { + g_string_assign(result, exec_dir); + + /* Advance over common components. */ + len_dir =3D len_bindir =3D prefix_len; + do { + dir +=3D len_dir; + bindir +=3D len_bindir; + dir =3D next_component(dir, &len_dir); + bindir =3D next_component(bindir, &len_bindir); + } while (len_dir && len_dir =3D=3D len_bindir && !memcmp(dir, bind= ir, len_dir)); + + /* Ascend from bindir to the common prefix with dir. */ + while (len_bindir) { + bindir +=3D len_bindir; + g_string_append(result, "/.."); + bindir =3D next_component(bindir, &len_bindir); + } + + if (*dir) { + assert(G_IS_DIR_SEPARATOR(dir[-1])); + g_string_append(result, dir - 1); + } } =20 - if (*dir) { - assert(G_IS_DIR_SEPARATOR(dir[-1])); - g_string_append(result, dir - 1); - } return g_string_free(result, false); } diff --git a/util/meson.build b/util/meson.build index 8cce8f8968..5e282130df 100644 --- a/util/meson.build +++ b/util/meson.build @@ -23,6 +23,7 @@ util_ss.add(when: 'CONFIG_WIN32', if_true: files('event_n= otifier-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')) --=20 2.36.1