Commit a2935b7a authored by Felix Häcker's avatar Felix Häcker

Improve cargo/meson build configuration

parent 67c7e58e
Pipeline #64294 failed with stages
in 1 minute and 17 seconds
......@@ -19,3 +19,4 @@ resources.gresource
*.gresource
tags.*
wip
src/config.rs
#!/bin/sh
export CARGO_HOME=$1/target/cargo-home
export LOCALEDIR="$3"
export APP_ID="$4"
export NAME_SUFFIX="$5"
export VERSION="$6"
export PROFILE="$7"
export MESON_BUILD_ROOT="$1"
export MESON_SOURCE_ROOT="$2"
export CARGO_TARGET_DIR="$MESON_BUILD_ROOT"/target
export CARGO_HOME="$CARGO_TARGET_DIR"/cargo-home
export SHORTWAVE_LOCALEDIR="$4"
if [ "$PROFILE" = "Devel" ]
then
if [[ $5 = "Devel" ]]
then
echo "DEBUG MODE"
cargo build --manifest-path $1/Cargo.toml -p shortwave && cp $1/target/debug/shortwave $2
cargo build --manifest-path \
"$MESON_SOURCE_ROOT"/Cargo.toml && \
cp "$CARGO_TARGET_DIR"/debug/shortwave $3
else
echo "RELEASE MODE"
cargo build --manifest-path $1/Cargo.toml --release -p shortwave && cp $1/target/release/shortwave $2
cargo build --manifest-path \
"$MESON_SOURCE_ROOT"/Cargo.toml --release && \
cp "$CARGO_TARGET_DIR"/release/shortwave $3
fi
#!/bin/sh
export DIST="$1"
export SOURCE_ROOT="$2"
cd "$SOURCE_ROOT"
mkdir "$DIST"/.cargo
cargo vendor | sed 's/^directory = ".*"/directory = "vendor"/g' > $DIST/.cargo/config
# Move vendor into dist tarball directory
mv vendor "$DIST"
#!/bin/sh
find src
find src/widgets
find src/player
find src/player/controller
find data/gtk
find data
find ../src -name "*.rs"
find ../data/gtk -name "*.ui"
#!/bin/bash
current=$(cat meson.build | grep -Eo "version: '(.*)'" | grep -Eo "[0-9]+\.[0-9]+.[0-9]+")
mayor=$(echo $current | cut -d"." -f1)
minor=$(echo $current | cut -d"." -f2)
rev=$(echo $current | cut -d"." -f3)
case $1 in
"mayor")
next=$(echo $(($mayor + 1)).0.0)
;;
"minor")
next=$(echo $mayor.$(($minor + 1)).0)
;;
*)
next=$(echo $mayor.$minor.$(($rev + 1)))
;;
esac
sed -i "s/$current/$next/" meson.build
sed -i "s/$current/$next/" Cargo.toml
sed -i "s/version=\"$current\".*/version=\"$next\" date=\"$(date +%Y-%m-%d)\"\/>/" data/de.haeckerfelix.Shortwave.appdata.xml
cargo check
git commit -av
git tag -s $next
ninja -C _build release
#git push --tags
# TODO
\ No newline at end of file
......@@ -2,7 +2,7 @@ scalable_dir = join_paths('hicolor', 'scalable', 'apps')
install_data(
join_paths(scalable_dir, 'de.haeckerfelix.Shortwave.svg'),
install_dir: join_paths(datadir, 'icons', scalable_dir),
install_dir: join_paths(shortwave_datadir, 'icons', scalable_dir),
rename: '@0@.svg'.format(application_id)
)
......@@ -10,6 +10,6 @@ symbolic_dir = join_paths('hicolor', 'symbolic', 'apps')
install_data(
join_paths(symbolic_dir, 'de.haeckerfelix.Shortwave-symbolic.svg'),
install_dir: join_paths(datadir, 'icons', symbolic_dir),
install_dir: join_paths(shortwave_datadir, 'icons', symbolic_dir),
rename: '@0@-symbolic.svg'.format(application_id)
)
......@@ -13,7 +13,7 @@ desktop_file = i18n.merge_file (
output: '@0@.desktop'.format(application_id),
po_dir: podir,
install: true,
install_dir: join_paths (datadir, 'applications')
install_dir: join_paths (shortwave_datadir, 'applications')
)
# Validate Desktop file
desktop_file_validate = find_program('desktop-file-validate', required: false)
......@@ -39,7 +39,7 @@ appdata_file = i18n.merge_file (
output: '@0@.appdata.xml'.format(application_id),
po_dir: podir,
install: true,
install_dir: join_paths (datadir, 'metainfo')
install_dir: join_paths (shortwave_datadir, 'metainfo')
)
# Validate Appdata
appstream_util = find_program('appstream-util', required: false)
......@@ -60,8 +60,8 @@ configure_file(
input: 'de.haeckerfelix.Shortwave.service.in',
output: '@0@.service'.format(application_id),
configuration: service_conf,
install_dir: join_paths(datadir,'dbus-1', 'services')
install_dir: join_paths(shortwave_datadir,'dbus-1', 'services')
)
# gschema
install_data('de.haeckerfelix.Shortwave.gschema.xml', install_dir: join_paths(get_option('datadir'), 'glib-2.0', 'schemas'))
install_data('de.haeckerfelix.Shortwave.gschema.xml', install_dir: join_paths(shortwave_datadir, 'glib-2.0', 'schemas'))
......@@ -43,7 +43,6 @@
"buildsystem" : "meson",
"config-opts" : [
"-Dintrospection=enabled",
"-Dgtk-doc=false",
"-Dtests=false",
"-Dexamples=false",
"-Dvapi=false",
......
# Adatped from:
# https://gitlab.gnome.org/danigm/fractal/blob/6e2911f9d2353c99a18a6c19fab7f903c4bbb431/meson.build
# Adatped from GNOME Social by Christopher Davis (GPLv3)
# https://gitlab.gnome.org/BrainBlasted/Social/blob/7e8f36b5e1b96fd64d152de995e15171a823836c/meson.build
project(
'shortwave', 'rust',
......@@ -7,9 +7,23 @@ project(
license: 'GPLv3',
)
shortwave_version = meson.project_version()
version_array = shortwave_version.split('.')
shortwave_major_version = version_array[0].to_int()
shortwave_minor_version = version_array[1].to_int()
shortwave_version_micro = version_array[2].to_int()
shortwave_prefix = get_option('prefix')
shortwave_bindir = join_paths(shortwave_prefix, get_option('bindir'))
shortwave_localedir = join_paths(shortwave_prefix, get_option('localedir'))
shortwave_datadir = get_option('datadir')
shortwave_pkgdatadir = join_paths(shortwave_datadir, meson.project_name())
shortwave_icondir = join_paths(shortwave_datadir, 'icons')
if get_option('profile') == 'development'
profile = 'Devel'
name_suffix = ' (Development)'
name_prefix = '(Development) '
vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD').stdout().strip()
if vcs_tag == ''
version_suffix = '-devel'
......@@ -18,26 +32,15 @@ if get_option('profile') == 'development'
endif
else
profile = ''
name_suffix = ''
name_prefix = ''
version_suffix = ''
endif
application_id = 'de.haeckerfelix.Shortwave@0@'.format(profile)
shortwave_version = meson.project_version()
version_array = shortwave_version.split('.')
shortwave_major_version = version_array[0].to_int()
shortwave_minor_version = version_array[1].to_int()
shortwave_version_micro = version_array[2].to_int()
shortwave_prefix = get_option('prefix')
shortwave_bindir = join_paths(shortwave_prefix, get_option('bindir'))
shortwave_localedir = join_paths(shortwave_prefix, get_option('localedir'))
datadir = get_option('datadir')
application_name = 'Shortwave'
i18n = import('i18n')
gnome = import('gnome')
podir = join_paths (meson.source_root (), 'po')
subdir('po')
......@@ -48,30 +51,13 @@ gresource = find_program('glib-compile-resources', required: false)
cargo_vendor = find_program('cargo-vendor', required: false)
cargo_script = find_program('build-aux/cargo.sh')
grabber = find_program('build-aux/grabber.sh')
cargo_release = find_program('build-aux/release.sh')
c = run_command(grabber)
sources = c.stdout().strip().split('\n')
cargo_release = custom_target('cargo-build',
build_by_default: true,
input: sources,
output: ['shortwave'],
install: true,
install_dir: shortwave_bindir,
console: true,
command: [cargo_script,
'@CURRENT_SOURCE_DIR@',
'@OUTPUT@',
shortwave_localedir,
application_id,
name_suffix,
shortwave_version + version_suffix,
profile
])
subdir('src')
run_target('release', command: ['build-aux/release.sh',
meson.project_name() + '-' + shortwave_version
])
meson.add_dist_script(
'build-aux/dist-vendor.sh',
join_paths(meson.build_root(), 'meson-dist', meson.project_name() + '-' + shortwave_version),
meson.source_root()
)
meson.add_install_script('build-aux/meson_post_install.py')
......@@ -6,4 +6,4 @@ option (
'development'
],
value: 'default'
)
\ No newline at end of file
)
......@@ -6,6 +6,7 @@ use rustio::{Station, StationSearch};
use std::cell::RefCell;
use std::rc::Rc;
use crate::config;
use crate::library::Library;
use crate::player::{PlaybackState, Player};
use crate::search::Search;
......@@ -30,16 +31,7 @@ pub enum Action {
SearchFor(StationSearch),
}
#[derive(Clone)]
pub struct AppInfo {
pub version: String,
pub profile: String,
pub app_name: String,
pub app_id: String,
}
pub struct App {
info: AppInfo,
gtk_app: gtk::Application,
sender: Sender<Action>,
......@@ -53,25 +45,18 @@ pub struct App {
impl App {
pub fn new() -> Rc<Self> {
let info = AppInfo {
version: option_env!("VERSION").unwrap_or("0.0.0").to_string(),
profile: option_env!("PROFILE").unwrap_or("default").to_string(),
app_name: "Shortwave".to_string(),
app_id: option_env!("APP_ID").unwrap_or("de.haeckerfelix.Shortwave").to_string(),
};
// Set custom style
let p = gtk::CssProvider::new();
gtk::CssProvider::load_from_resource(&p, "/de/haeckerfelix/Shortwave/gtk/style.css");
gtk::StyleContext::add_provider_for_screen(&gdk::Screen::get_default().unwrap(), &p, 500);
let gtk_app = gtk::Application::new(info.app_id.as_str(), gio::ApplicationFlags::FLAGS_NONE).unwrap();
let gtk_app = gtk::Application::new(config::APP_ID, gio::ApplicationFlags::FLAGS_NONE).unwrap();
let (sender, r) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
let receiver = RefCell::new(Some(r));
let window = Window::new(sender.clone(), &info);
let window = Window::new(sender.clone());
let player = Player::new(sender.clone());
let library = Library::new(sender.clone(), &info);
let library = Library::new(sender.clone());
let search = Search::new(sender.clone());
window.player_box.add(&player.widget);
......@@ -84,7 +69,6 @@ impl App {
window.widget.set_help_overlay(Some(&dialog));
let app = Rc::new(Self {
info,
gtk_app,
sender,
receiver,
......@@ -94,9 +78,9 @@ impl App {
search,
});
glib::set_application_name(&app.info.app_name);
glib::set_application_name(config::NAME);
glib::set_prgname(Some("shortwave"));
gtk::Window::set_default_icon_name(&app.info.app_id);
gtk::Window::set_default_icon_name(config::APP_ID);
app.setup_gaction();
app.setup_signals();
......@@ -104,8 +88,9 @@ impl App {
}
pub fn run(&self, app: Rc<Self>) {
info!("{} ({})", self.info.app_name, self.info.app_id);
info!("Version: {} ({})", self.info.version, self.info.profile);
info!("{}{} ({})", config::NAME_PREFIX, config::NAME, config::APP_ID);
info!("Version: {} ({})", config::VERSION, config::PROFILE);
info!("Datadir: {}", config::PKGDATADIR);
let a = app.clone();
let receiver = self.receiver.borrow_mut().take().unwrap();
......@@ -124,9 +109,8 @@ impl App {
// About
let window = self.window.widget.clone();
let info = self.info.clone();
self.add_gaction("about", move |_, _| {
Self::show_about_dialog(info.clone(), window.clone());
Self::show_about_dialog(window.clone());
});
// Save library
......@@ -239,14 +223,14 @@ impl App {
glib::Continue(true)
}
fn show_about_dialog(info: AppInfo, window: gtk::ApplicationWindow) {
fn show_about_dialog(window: gtk::ApplicationWindow) {
let dialog = gtk::AboutDialog::new();
dialog.set_program_name(info.app_name.as_str());
dialog.set_logo_icon_name(info.app_id.as_str());
dialog.set_program_name(config::NAME);
dialog.set_logo_icon_name(config::APP_ID);
dialog.set_comments("A web radio client");
dialog.set_copyright("© 2019 Felix Häcker");
dialog.set_license_type(gtk::License::Gpl30);
dialog.set_version(info.version.as_str());
dialog.set_version(config::VERSION);
dialog.set_transient_for(&window);
dialog.set_modal(true);
......
pub static APP_ID: &'static str = @APP_ID@;
pub static PKGDATADIR: &'static str = @PKGDATADIR@;
pub static PROFILE: &'static str = @PROFILE@;
pub static NAME_PREFIX: &'static str = @NAME_PREFIX@;
pub static NAME: &'static str = @NAME@;
pub static VERSION: &'static str = @VERSION@;
......@@ -11,7 +11,8 @@ use std::path::PathBuf;
use std::result::Result;
use std::thread;
use crate::app::{Action, AppInfo};
use crate::app::Action;
use crate::config;
use crate::station_model::{Order, Sorting};
use crate::widgets::station_listbox::StationListBox;
use crate::widgets::station_row::ContentType;
......@@ -31,7 +32,7 @@ pub struct Library {
}
impl Library {
pub fn new(sender: Sender<Action>, info: &AppInfo) -> Self {
pub fn new(sender: Sender<Action>) -> Self {
let builder = gtk::Builder::new_from_resource("/de/haeckerfelix/Shortwave/gtk/library.ui");
let widget: gtk::Box = builder.get_object("library").unwrap();
let content_box: gtk::Box = builder.get_object("content_box").unwrap();
......@@ -41,9 +42,9 @@ impl Library {
let db_path = Self::get_database_path("shortwave.db").expect("Could not open database path...");
let logo_image: gtk::Image = builder.get_object("logo_image").unwrap();
logo_image.set_from_icon_name(Some(format!("{}-symbolic", info.app_id).as_str()), gtk::IconSize::__Unknown(128));
logo_image.set_from_icon_name(Some(format!("{}-symbolic", config::APP_ID).as_str()), gtk::IconSize::__Unknown(128));
let welcome_text: gtk::Label = builder.get_object("welcome_text").unwrap();
welcome_text.set_text(format!("Welcome to {}", info.app_name).as_str());
welcome_text.set_text(format!("Welcome to {}", config::NAME).as_str());
let library = Self {
widget,
......@@ -223,3 +224,7 @@ quick_error! {
}
}
}
// TODO
// Lösung: Das Model/station_listbox einfach öffentlich (statisch) für alle module verfügbar machen
// ordentliches station model implementieren
......@@ -6,6 +6,7 @@ extern crate pretty_env_logger;
extern crate quick_error;
mod app;
mod config;
mod library;
mod player;
mod search;
......
global_conf = configuration_data()
global_conf.set_quoted('APP_ID', application_id)
global_conf.set_quoted('PKGDATADIR', join_paths(shortwave_prefix, shortwave_pkgdatadir))
global_conf.set_quoted('PROFILE', profile)
global_conf.set_quoted('NAME_PREFIX', name_prefix)
global_conf.set_quoted('NAME', application_name)
global_conf.set_quoted('VERSION', shortwave_version + version_suffix)
config = configure_file(
input: 'config.rs.in',
output: 'config.rs',
configuration: global_conf
)
c = run_command(grabber)
sources = c.stdout().strip().split('\n')
# Copy the configuration into src for Cargo
run_command(
'cp',
join_paths(meson.build_root(), 'src', 'config.rs'),
join_paths(meson.source_root(), 'src', 'config.rs'),
check: true
)
cargo_release = custom_target('cargo-build',
build_by_default: true,
input: [sources],
output: ['shortwave'],
console: true,
install: true,
install_dir: shortwave_bindir,
command: [cargo_script,
meson.build_root(),
meson.source_root(),
'@OUTPUT@',
shortwave_localedir,
profile])
......@@ -2,7 +2,8 @@ use glib::Sender;
use gtk::prelude::*;
use libhandy::LeafletExt;
use crate::app::{Action, AppInfo};
use crate::app::Action;
use crate::config;
use crate::widgets::notification::Notification;
#[derive(Debug, Clone, PartialEq)]
......@@ -24,14 +25,14 @@ pub struct Window {
}
impl Window {
pub fn new(sender: Sender<Action>, appinfo: &AppInfo) -> Self {
pub fn new(sender: Sender<Action>) -> Self {
let builder = gtk::Builder::new_from_resource("/de/haeckerfelix/Shortwave/gtk/window.ui");
let menu_builder = gtk::Builder::new_from_resource("/de/haeckerfelix/Shortwave/gtk/menu.ui");
let window: gtk::ApplicationWindow = builder.get_object("window").unwrap();
let view_headerbar: gtk::HeaderBar = builder.get_object("view_headerbar").unwrap();
view_headerbar.set_title(Some(appinfo.app_name.as_ref()));
window.set_title(&appinfo.app_name);
view_headerbar.set_title(Some(config::NAME));
window.set_title(config::NAME);
let player_box: gtk::Box = builder.get_object("player_box").unwrap();
let library_box: gtk::Box = builder.get_object("library_box").unwrap();
......@@ -53,7 +54,7 @@ impl Window {
appmenu_button.set_popover(Some(&popover_menu));
// Devel style class
if appinfo.app_id.ends_with("Devel") {
if config::APP_ID.ends_with("Devel") {
let ctx = window.widget.get_style_context();
ctx.add_class("devel");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment