Skip to content

Commit

Permalink
Add a ashpd-demo.devel that can run from the meson builddir
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
whot committed Aug 7, 2023
1 parent 5a78d76 commit 9763c8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions ashpd-demo/src/config.rs.in
Original file line number Diff line number Diff line change
Expand Up @@ -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");
9 changes: 7 additions & 2 deletions ashpd-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions ashpd-demo/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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(), '@[email protected]',
]
)

0 comments on commit 9763c8e

Please sign in to comment.