From ab4f3f4004b08751b6e6ab3c418e5223163f8162 Mon Sep 17 00:00:00 2001 From: Robert Yang Date: Fri, 8 Feb 2019 13:23:17 -0500 Subject: [PATCH] qemu: Load GTK modules/resources from chroot (!1749) We are running qemu that is installed in the chroot. The GTK framework needs to be configured to load resources from the chroot as well. https://developer.gnome.org/gtk3/stable/gtk-running.html --- pmb/qemu/run.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pmb/qemu/run.py b/pmb/qemu/run.py index 75d41673..c5e6dbe7 100644 --- a/pmb/qemu/run.py +++ b/pmb/qemu/run.py @@ -99,6 +99,29 @@ def command_spice(args): return ["remote-viewer", "spice://127.0.0.1?port=" + args.spice_port] +def create_gdk_loader_cache(args): + """ + Create a gdk loader cache that can be used for running GTK UIs outside of + the chroot. + """ + gdk_cache_dir = "/usr/lib/gdk-pixbuf-2.0/2.10.0/" + custom_cache_path = gdk_cache_dir + "loaders-pmos-chroot.cache" + rootfs_native = args.work + "/chroot_native" + if os.path.isfile(rootfs_native + custom_cache_path): + return rootfs_native + custom_cache_path + + cache_path = gdk_cache_dir + "loaders.cache" + if not os.path.isfile(rootfs_native + cache_path): + raise RuntimeError("gdk pixbuf cache file not found: " + cache_path) + + pmb.chroot.root(args, ["cp", cache_path, custom_cache_path]) + cmd = ["sed", "-i", "-e", + "s@\"" + gdk_cache_dir + "@\"" + rootfs_native + gdk_cache_dir + "@", + custom_cache_path] + pmb.chroot.root(args, cmd) + return rootfs_native + custom_cache_path + + def command_qemu(args, arch, device, img_path, spice_enabled): """ Generate the full qemu command with arguments to run postmarketOS @@ -129,6 +152,13 @@ def command_qemu(args, arch, device, img_path, spice_enabled): "GBM_DRIVERS_PATH": rootfs_native + "/usr/lib/xorg/modules/dri", "LIBGL_DRIVERS_PATH": rootfs_native + "/usr/lib/xorg/modules/dri"} + if "gtk" in args.qemu_display: + gdk_cache = create_gdk_loader_cache(args) + env.update({"GTK_THEME": "Default", + "GDK_PIXBUF_MODULE_FILE": gdk_cache, + "XDG_DATA_DIRS": rootfs_native + "/usr/local/share:" + + rootfs_native + "/usr/share"}) + command = [rootfs_native + "/lib/ld-musl-" + args.arch_native + ".so.1"] command += ["--library-path=" + rootfs_native + "/lib:" +