diff mbox series

[2/4] datadir: Use bundle mechanism

Message ID 20210708172541.29530-2-akihiko.odaki@gmail.com
State New
Headers show
Series [1/4] cutils: Introduce bundle mechanism | expand

Commit Message

Akihiko Odaki July 8, 2021, 5:25 p.m. UTC
bundle mechanism and softmmu/datadir.c provides some overlapped
functionality. Use bundle mechanism in softmmu/datadir.c to remove the
redundancy.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
 configure         |  2 ++
 meson.build       |  2 +-
 softmmu/datadir.c | 35 ++++++++++++-----------------------
 3 files changed, 15 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/configure b/configure
index 650d9c07358..cff5a8ac280 100755
--- a/configure
+++ b/configure
@@ -5058,6 +5058,8 @@  for f in $UNLINK ; do
     fi
 done
 
+symlink ../../pc-bios qemu-bundle/share/qemu
+
 (for i in $cross_cc_vars; do
   export $i
 done
diff --git a/meson.build b/meson.build
index 877d4fa0b6a..44adc660e23 100644
--- a/meson.build
+++ b/meson.build
@@ -1197,7 +1197,7 @@  endif
 config_host_data.set_quoted('CONFIG_BINDIR', get_option('prefix') / get_option('bindir'))
 config_host_data.set_quoted('CONFIG_PREFIX', get_option('prefix'))
 config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', get_option('prefix') / qemu_confdir)
-config_host_data.set_quoted('CONFIG_QEMU_DATADIR', get_option('prefix') / qemu_datadir)
+config_host_data.set_quoted('CONFIG_QEMU_BUNDLE_DATADIR', qemu_datadir)
 config_host_data.set_quoted('CONFIG_QEMU_DESKTOPDIR', get_option('prefix') / qemu_desktopdir)
 config_host_data.set_quoted('CONFIG_QEMU_FIRMWAREPATH', get_option('qemu_firmwarepath'))
 config_host_data.set_quoted('CONFIG_QEMU_HELPERDIR', get_option('prefix') / get_option('libexecdir'))
diff --git a/softmmu/datadir.c b/softmmu/datadir.c
index 504c4665bed..2d8366039d9 100644
--- a/softmmu/datadir.c
+++ b/softmmu/datadir.c
@@ -36,6 +36,7 @@  char *qemu_find_file(int type, const char *name)
     int i;
     const char *subdir;
     char *buf;
+    char *bundle;
 
     /* Try the name as a straight path first */
     if (access(name, R_OK) == 0) {
@@ -62,6 +63,16 @@  char *qemu_find_file(int type, const char *name)
         }
         g_free(buf);
     }
+
+    bundle = g_strdup_printf("%s/%s%s",
+                             CONFIG_QEMU_BUNDLE_DATADIR, subdir, name);
+    buf = find_bundle(bundle);
+    g_free(bundle);
+    if (buf) {
+        trace_load_file(name, buf);
+        return buf;
+    }
+
     return NULL;
 }
 
@@ -84,26 +95,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;
@@ -115,9 +106,6 @@  void qemu_add_default_firmwarepath(void)
         qemu_add_data_dir(get_relocated_path(dirs[i]));
     }
     g_strfreev(dirs);
-
-    /* try to find datadir relative to the executable path */
-    qemu_add_data_dir(find_datadir());
 }
 
 void qemu_list_data_dirs(void)
@@ -126,4 +114,5 @@  void qemu_list_data_dirs(void)
     for (i = 0; i < data_dir_idx; i++) {
         printf("%s\n", data_dir[i]);
     }
+    list_bundle_candidates(CONFIG_QEMU_BUNDLE_DATADIR);
 }