From 9763c8ee2c087e7ed54c48985c439b087186255e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 7 Aug 2023 23:08:16 +0300 Subject: [PATCH] Add a ashpd-demo.devel that can run from the meson builddir Running the demo from the builddir fails with the missing gresources file. Hack around this by copying the binary into a ashpd-demo.devel and, if argv0 ends with .devel, loading the gresources file from the meson builddir instead. --- ashpd-demo/src/config.rs.in | 1 + ashpd-demo/src/main.rs | 9 +++++++-- ashpd-demo/src/meson.build | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ashpd-demo/src/config.rs.in b/ashpd-demo/src/config.rs.in index 699897f02..9a1b3c611 100644 --- a/ashpd-demo/src/config.rs.in +++ b/ashpd-demo/src/config.rs.in @@ -5,3 +5,4 @@ pub const PKGDATADIR: &str = @PKGDATADIR@; pub const PROFILE: &str = @PROFILE@; pub const RESOURCES_FILE: &str = concat!(@PKGDATADIR@, "/resources.gresource"); pub const VERSION: &str = @VERSION@; +pub const BUILDDIR_RESOURCES_FILE: &str = concat!(@BUILDDATADIR@, "/resources.gresource"); diff --git a/ashpd-demo/src/main.rs b/ashpd-demo/src/main.rs index 2d65bfcf8..d98de7306 100644 --- a/ashpd-demo/src/main.rs +++ b/ashpd-demo/src/main.rs @@ -6,7 +6,7 @@ mod widgets; mod window; use application::Application; -use config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE}; +use config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE, BUILDDIR_RESOURCES_FILE}; use gettextrs::*; use gtk::{gio, glib}; @@ -24,7 +24,12 @@ fn main() -> glib::ExitCode { gst4gtk::plugin_register_static().expect("Failed to register gstgtk4 plugin"); - let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file"); + let argv0 = std::env::args().next(); + let res = if argv0.is_some() && argv0.unwrap().ends_with(".devel") { + gio::Resource::load(BUILDDIR_RESOURCES_FILE) + } else { + gio::Resource::load(RESOURCES_FILE) + }.expect("Could not load gresource file"); gio::resources_register(&res); let mut args = std::env::args(); diff --git a/ashpd-demo/src/meson.build b/ashpd-demo/src/meson.build index d99036d68..d00aaf11f 100644 --- a/ashpd-demo/src/meson.build +++ b/ashpd-demo/src/meson.build @@ -5,6 +5,7 @@ global_conf.set_quoted('PROFILE', profile) global_conf.set_quoted('VERSION', version + version_suffix) global_conf.set_quoted('GETTEXT_PACKAGE', gettext_package) global_conf.set_quoted('LOCALEDIR', localedir) +global_conf.set_quoted('BUILDDATADIR', meson.project_build_root() / 'data') config = configure_file( input: 'config.rs.in', output: 'config.rs', @@ -48,5 +49,7 @@ cargo_build = custom_target( cargo_options, '&&', 'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@', + '&&', + 'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@.devel', ] )