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>,
Gerd Hoffmann <kraxel@redhat.com>,
Akihiko Odaki <akihiko.odaki@gmail.com>
Subject: [PATCH 1/4] cutils: Introduce bundle mechanism
Date: Fri, 9 Jul 2021 02:25:38 +0900 [thread overview]
Message-ID: <20210708172541.29530-1-akihiko.odaki@gmail.com> (raw)
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.
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
include/qemu/cutils.h | 19 +++++++++++++++++++
util/cutils.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 986ed8e15f4..6060e56b877 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -209,4 +209,23 @@ int qemu_pstrcmp0(const char **str1, const char **str2);
*/
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);
+
#endif
diff --git a/util/cutils.c b/util/cutils.c
index c9b91e7535a..b4e4cda71c8 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -1057,3 +1057,36 @@ char *get_relocated_path(const char *dir)
}
return g_string_free(result, false);
}
+
+static const char * const bundle_formats[] = {
+ "%s" G_DIR_SEPARATOR_S ".." G_DIR_SEPARATOR_S "%s",
+ "%s" G_DIR_SEPARATOR_S "qemu-bundle" G_DIR_SEPARATOR_S "%s"
+};
+
+char *find_bundle(const char *path)
+{
+ const char *dir = qemu_get_exec_dir();
+ char *candidate;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(bundle_formats); i++) {
+ candidate = g_strdup_printf(bundle_formats[i], dir, path);
+ if (access(candidate, R_OK) == 0) {
+ return candidate;
+ }
+ g_free(candidate);
+ }
+
+ return NULL;
+}
+
+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.30.1 (Apple Git-130)
next reply other threads:[~2021-07-08 17:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-08 17:25 Akihiko Odaki [this message]
2021-07-08 17:25 ` [PATCH 2/4] datadir: Use bundle mechanism Akihiko Odaki
2021-07-08 17:25 ` [PATCH 3/4] ui/icons: " Akihiko Odaki
2021-07-08 18:52 ` Programmingkid
2021-07-09 0:31 ` Akihiko Odaki
2021-07-10 2:48 ` Programmingkid
2021-07-08 17:25 ` [PATCH 4/4] net: " 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=20210708172541.29530-1-akihiko.odaki@gmail.com \
--to=akihiko.odaki@gmail.com \
--cc=jasowang@redhat.com \
--cc=kraxel@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.