From 395e31ff858fa8fa32c68f08e9e5688c2bb627ab Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Mon, 4 Mar 2019 00:17:45 -0500 Subject: [PATCH] build: Use config.rs instead of env! macro Previously we were using the env! macro to determine build-time variables like version, app ID, and locale dir. Instead of relying on env vars, we can create a configuration file with meson and import it. --- .gitignore | 3 +++ meson.build | 15 +----------- podcasts-gtk/src/app.rs | 22 ++++-------------- podcasts-gtk/src/config.rs.in | 23 ++++++++++++++++++ podcasts-gtk/src/main.rs | 1 + podcasts-gtk/src/meson.build | 31 +++++++++++++++++++++++++ podcasts-gtk/src/widgets/aboutdialog.rs | 6 ++--- podcasts-gtk/src/widgets/empty.rs | 4 ++-- 8 files changed, 68 insertions(+), 37 deletions(-) create mode 100644 podcasts-gtk/src/config.rs.in create mode 100644 podcasts-gtk/src/meson.build diff --git a/.gitignore b/.gitignore index fefc6ff..f5cb1ce 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ target_*/ .flatpak-builder/ app/ repo/ + +# Files configured by meson +podcasts-gtk/src/config.rs diff --git a/meson.build b/meson.build index 7fc5e17..89a111c 100644 --- a/meson.build +++ b/meson.build @@ -65,20 +65,7 @@ subdir('podcasts-gtk/resources') cargo_script = find_program('scripts/cargo.sh') -cargo_release = custom_target('cargo-build', - build_always_stale: true, - output: ['gnome-podcasts'], - install: true, - install_dir: podcasts_bindir, - console: true, - command: [cargo_script, - '@CURRENT_SOURCE_DIR@', - '@OUTPUT@', - podcasts_localedir, - application_id, - podcasts_version + version_suffix, - profile - ]) +subdir('podcasts-gtk/src') run_target('release', command: ['scripts/release.sh', meson.project_name() + '-' + podcasts_version diff --git a/podcasts-gtk/src/app.rs b/podcasts-gtk/src/app.rs index df556a8..0e82949 100644 --- a/podcasts-gtk/src/app.rs +++ b/podcasts-gtk/src/app.rs @@ -46,23 +46,9 @@ use std::env; use std::rc::Rc; use std::sync::Arc; +use crate::config::{APP_ID, LOCALEDIR}; use crate::i18n::i18n; -#[rustfmt::skip] -lazy_static! { - pub static ref APP_ID: &'static str = { - option_env!("APP_ID").unwrap_or("org.gnome.Podcasts") - }; - - pub static ref VERSION: &'static str = { - option_env!("VERSION").unwrap_or("0.0.1") - }; - - pub static ref LOCALEDIR: &'static str = { - option_env!("LOCALEDIR").unwrap_or("./podcasts-gtk/po") - }; -} - /// Creates an action named `name` in the action map `T with the handler `F` fn action(thing: &T, name: &str, action: F) where @@ -428,10 +414,10 @@ impl App { pub(crate) fn run() { // Set up the textdomain for gettext setlocale(LocaleCategory::LcAll, ""); - bindtextdomain("gnome-podcasts", *LOCALEDIR); + bindtextdomain("gnome-podcasts", LOCALEDIR); textdomain("gnome-podcasts"); - let application = gtk::Application::new(*APP_ID, gio::ApplicationFlags::empty()) + let application = gtk::Application::new(APP_ID, gio::ApplicationFlags::empty()) .expect("Application initialization failed..."); application.set_resource_base_path("/org/gnome/Podcasts"); @@ -462,7 +448,7 @@ impl App { // Weird magic I copy-pasted that sets the Application Name in the Shell. glib::set_application_name(&i18n("Podcasts")); glib::set_prgname(Some("gnome-podcasts")); - gtk::Window::set_default_icon_name(*APP_ID); + gtk::Window::set_default_icon_name(APP_ID); let args: Vec = env::args().collect(); ApplicationExtManual::run(&application, &args); } diff --git a/podcasts-gtk/src/config.rs.in b/podcasts-gtk/src/config.rs.in new file mode 100644 index 0000000..7de9911 --- /dev/null +++ b/podcasts-gtk/src/config.rs.in @@ -0,0 +1,23 @@ +/* config.rs.in + * + * Copyright 2019 Christopher Davis + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +pub static APP_ID: &'static str = @APP_ID@; +pub static VERSION: &'static str = @VERSION@; +pub static LOCALEDIR: &'static str = @LOCALEDIR@; diff --git a/podcasts-gtk/src/main.rs b/podcasts-gtk/src/main.rs index ee9db90..0a720dd 100644 --- a/podcasts-gtk/src/main.rs +++ b/podcasts-gtk/src/main.rs @@ -109,6 +109,7 @@ mod stacks; mod widgets; mod app; +mod config; mod headerbar; mod prefs; diff --git a/podcasts-gtk/src/meson.build b/podcasts-gtk/src/meson.build new file mode 100644 index 0000000..55a9607 --- /dev/null +++ b/podcasts-gtk/src/meson.build @@ -0,0 +1,31 @@ +global_conf = configuration_data() +global_conf.set_quoted('APP_ID', application_id) +global_conf.set_quoted('VERSION', podcasts_version + version_suffix) +global_conf.set_quoted('LOCALEDIR', podcasts_localedir) +config_rs = configure_file( + input: 'config.rs.in', + output: 'config.rs', + configuration: global_conf +) + +run_command( + 'cp', + config_rs, + meson.current_source_dir(), + check: true +) + +cargo_release = custom_target('cargo-build', + build_always_stale: true, + output: ['gnome-podcasts'], + install: true, + install_dir: podcasts_bindir, + console: true, + command: [cargo_script, + '@SOURCE_ROOT@', + '@OUTPUT@', + podcasts_localedir, + application_id, + podcasts_version + version_suffix, + profile + ]) diff --git a/podcasts-gtk/src/widgets/aboutdialog.rs b/podcasts-gtk/src/widgets/aboutdialog.rs index f29ce06..1e35841 100644 --- a/podcasts-gtk/src/widgets/aboutdialog.rs +++ b/podcasts-gtk/src/widgets/aboutdialog.rs @@ -17,7 +17,7 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -use crate::app::{APP_ID, VERSION}; +use crate::config::{APP_ID, VERSION}; use gtk; use gtk::prelude::*; @@ -47,12 +47,12 @@ pub(crate) fn about_dialog(window: >k::ApplicationWindow) { ]; let dialog = gtk::AboutDialog::new(); - dialog.set_logo_icon_name(*APP_ID); + dialog.set_logo_icon_name(APP_ID); dialog.set_comments(i18n("Podcast Client for the GNOME Desktop.").as_str()); dialog.set_copyright("© 2017, 2018 Jordan Petridis"); dialog.set_license_type(gtk::License::Gpl30); dialog.set_modal(true); - dialog.set_version(*VERSION); + dialog.set_version(VERSION); dialog.set_program_name(&i18n("Podcasts")); dialog.set_website("https://wiki.gnome.org/Apps/Podcasts"); dialog.set_website_label(i18n("Learn more about GNOME Podcasts").as_str()); diff --git a/podcasts-gtk/src/widgets/empty.rs b/podcasts-gtk/src/widgets/empty.rs index 5087078..66633b3 100644 --- a/podcasts-gtk/src/widgets/empty.rs +++ b/podcasts-gtk/src/widgets/empty.rs @@ -17,7 +17,7 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -use crate::app::APP_ID; +use crate::config::APP_ID; use gtk::{self, prelude::*}; use std::ops::Deref; @@ -37,7 +37,7 @@ impl Default for EmptyView { let view: gtk::Box = builder.get_object("empty_view").unwrap(); let image: gtk::Image = builder.get_object("image").unwrap(); image.set_from_icon_name( - format!("{}-symbolic", *APP_ID).as_str(), + format!("{}-symbolic", APP_ID).as_str(), gtk::IconSize::__Unknown(256), ); EmptyView(view)