All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akihiko Odaki <akihiko.odaki@gmail.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Jason Wang" <jasowang@redhat.com>,
	qemu-devel@nongnu.org, Programmingkid <programmingkidx@gmail.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Akihiko Odaki" <akihiko.odaki@gmail.com>
Subject: [PATCH v6 4/7] cutils: Introduce bundle mechanism
Date: Thu, 16 Jun 2022 00:56:31 +0900	[thread overview]
Message-ID: <20220615155634.578-5-akihiko.odaki@gmail.com> (raw)
In-Reply-To: <20220615155634.578-1-akihiko.odaki@gmail.com>

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.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
 include/qemu/cutils.h | 19 +++++++++++++++++++
 meson.build           | 12 ++++++++++++
 util/cutils.c         | 23 +++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 57de1da5c95..ca5bddb9e1c 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -213,6 +213,25 @@ const char *qemu_get_exec_dir(void);
  */
 char *get_relocated_path(const char *dir);
 
+/**
+ * find_bundle:
+ * @path: Relative path
+ *
+ * Returns a path for the specified directory or file bundled in QEMU. It uses
+ * the directory of the running executable as the prefix first. See
+ * get_relocated_path() for the details. The next candidate is "qemu-bundle"
+ * directory in the directory of the running executable. "qemu-bundle"
+ * directory is typically present in the build tree.
+ *
+ * The returned string should be freed by the caller.
+ *
+ * Returns: a path that can access the bundle, or NULL if no matching bundle
+ * exists.
+ */
+char *find_bundle(const char *path);
+
+void list_bundle_candidates(const char *path);
+
 static inline const char *yes_no(bool b)
 {
      return b ? "yes" : "no";
diff --git a/meson.build b/meson.build
index 01d5e32615e..ab5ab85bf4e 100644
--- a/meson.build
+++ b/meson.build
@@ -32,6 +32,7 @@ if get_option('qemu_suffix').startswith('/')
   error('qemu_suffix cannot start with a /')
 endif
 
+qemu_bundledir = meson.project_build_root() / 'qemu-bundle'
 qemu_confdir = get_option('sysconfdir') / get_option('qemu_suffix')
 qemu_datadir = get_option('datadir') / get_option('qemu_suffix')
 qemu_docdir = get_option('docdir') / get_option('qemu_suffix')
@@ -2843,6 +2844,8 @@ target_arch = {}
 target_softmmu_arch = {}
 target_user_arch = {}
 
+bundles = {}
+
 ###############
 # Trace files #
 ###############
@@ -3613,6 +3616,15 @@ if host_machine.system() == 'windows'
   alias_target('installer', nsis)
 endif
 
+###########
+# Bundles #
+###########
+
+foreach dst, src: bundles
+  run_command('mkdir', '-p', qemu_bundledir / fs.parent(dst), check: true)
+  run_command('ln', '-sf', src, qemu_bundledir / dst, check: true)
+endforeach
+
 #########################
 # Configuration summary #
 #########################
diff --git a/util/cutils.c b/util/cutils.c
index 983db97b4df..64cb1616b9c 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -1066,3 +1066,26 @@ char *get_relocated_path(const char *dir)
 
     return g_string_free(result, false);
 }
+
+char *find_bundle(const char *path)
+{
+    char *bundle = g_strdup_printf("%s/qemu-bundle/%s", qemu_get_exec_dir(), path);
+    if (access(bundle, R_OK) == 0) {
+        return bundle;
+    }
+
+    g_free(bundle);
+
+    return get_relocated_path(path);
+}
+
+void list_bundle_candidates(const char *path)
+{
+    const char *dir = qemu_get_exec_dir();
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(bundle_formats); i++) {
+        printf(bundle_formats[i], dir, path);
+        putc('\n', stdout);
+    }
+}
-- 
2.32.1 (Apple Git-133)



  parent reply	other threads:[~2022-06-15 16:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-15 15:56 [PATCH v6 0/7] cutils: Introduce bundle mechanism Akihiko Odaki
2022-06-15 15:56 ` [PATCH v6 1/7] datadir: Simplify firmware directory search Akihiko Odaki
2022-06-15 16:52   ` Daniel P. Berrangé
2022-06-15 15:56 ` [PATCH v6 2/7] qga: Relocate a path emitted in the help text Akihiko Odaki
2022-06-15 15:56 ` [PATCH v6 3/7] Remove prefixes from path configuration macros Akihiko Odaki
2022-06-15 19:25   ` Paolo Bonzini
2022-06-15 15:56 ` Akihiko Odaki [this message]
2022-06-15 19:26   ` [PATCH v6 4/7] cutils: Introduce bundle mechanism Paolo Bonzini
2022-06-15 15:56 ` [PATCH v6 5/7] datadir: Use " Akihiko Odaki
2022-06-15 19:23   ` Paolo Bonzini
2022-06-15 15:56 ` [PATCH v6 6/7] ui/icons: " Akihiko Odaki
2022-06-15 15:56 ` [PATCH v6 7/7] net: " Akihiko Odaki
2022-06-15 19:27 ` [PATCH v6 0/7] cutils: Introduce " Paolo Bonzini
2022-06-16  9:18   ` Paolo Bonzini
2022-06-24 16:33     ` Akihiko Odaki

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=20220615155634.578-5-akihiko.odaki@gmail.com \
    --to=akihiko.odaki@gmail.com \
    --cc=berrange@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=jasowang@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=programmingkidx@gmail.com \
    --cc=qemu-devel@nongnu.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.