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.
This commit is contained in:
parent
dd0d828794
commit
395e31ff85
3
.gitignore
vendored
3
.gitignore
vendored
@ -17,3 +17,6 @@ target_*/
|
||||
.flatpak-builder/
|
||||
app/
|
||||
repo/
|
||||
|
||||
# Files configured by meson
|
||||
podcasts-gtk/src/config.rs
|
||||
|
||||
15
meson.build
15
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
|
||||
|
||||
@ -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<T, F>(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<String> = env::args().collect();
|
||||
ApplicationExtManual::run(&application, &args);
|
||||
}
|
||||
|
||||
23
podcasts-gtk/src/config.rs.in
Normal file
23
podcasts-gtk/src/config.rs.in
Normal file
@ -0,0 +1,23 @@
|
||||
/* config.rs.in
|
||||
*
|
||||
* Copyright 2019 Christopher Davis <brainblasted@disroot.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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@;
|
||||
@ -109,6 +109,7 @@ mod stacks;
|
||||
mod widgets;
|
||||
|
||||
mod app;
|
||||
mod config;
|
||||
mod headerbar;
|
||||
mod prefs;
|
||||
|
||||
|
||||
31
podcasts-gtk/src/meson.build
Normal file
31
podcasts-gtk/src/meson.build
Normal file
@ -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
|
||||
])
|
||||
@ -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());
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user