[fractal] build: Use config.rs instead of env! macro
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] build: Use config.rs instead of env! macro
- Date: Sat, 27 Apr 2019 16:40:16 +0000 (UTC)
commit bd4d7b885973df4346127a328350d70eb4f6a57c
Author: Christopher Davis <brainblasted disroot org>
Date: Mon Apr 22 00:51:21 2019 -0400
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 +++
.gitlab-ci.yml | 1 +
fractal-gtk/src/app/mod.rs | 4 ++--
fractal-gtk/src/appop/about.rs | 11 ++++-------
fractal-gtk/src/config.rs.in | 23 +++++++++++++++++++++++
fractal-gtk/src/globals.rs | 5 -----
fractal-gtk/src/main.rs | 4 ++--
fractal-gtk/src/meson.build | 34 ++++++++++++++++++++++++++++++++++
meson.build | 20 +-------------------
scripts/cargo.sh | 6 +-----
10 files changed, 71 insertions(+), 40 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 0fe75156..efa4603b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,6 @@ Makefile
_build
vendor
*.gresource
+
+# Files configured by meson
+fractal-gtk/src/config.rs
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d949c0b2..07c9cd91 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -99,6 +99,7 @@ pages:
- flatpak-builder --stop-at=${FLATPAK_MODULE} --force-clean app ${MANIFEST_PATH}
# Force regeneration of gresources regardless of artifacts chage
- flatpak-builder --run app ${MANIFEST_PATH} glib-compile-resources --sourcedir=fractal-gtk/res/
fractal-gtk/res/resources.xml
+ - flatpak-builder --run app ${MANIFEST_PATH} meson _build
- |
flatpak-builder --run \
diff --git a/fractal-gtk/src/app/mod.rs b/fractal-gtk/src/app/mod.rs
index 328b27bb..0d91fdb4 100644
--- a/fractal-gtk/src/app/mod.rs
+++ b/fractal-gtk/src/app/mod.rs
@@ -14,7 +14,7 @@ use crate::backend::BKResponse;
use crate::backend::Backend;
use crate::actions;
-use crate::globals;
+use crate::config;
use crate::uibuilder;
use crate::widgets;
@@ -85,7 +85,7 @@ impl App {
// Set up the textdomain for gettext
setlocale(LocaleCategory::LcAll, "");
- bindtextdomain("fractal", globals::LOCALEDIR.unwrap_or("./fractal-gtk/po"));
+ bindtextdomain("fractal", config::LOCALEDIR);
textdomain("fractal");
glib::set_application_name("fractal");
diff --git a/fractal-gtk/src/appop/about.rs b/fractal-gtk/src/appop/about.rs
index fb494f6f..649f6854 100644
--- a/fractal-gtk/src/appop/about.rs
+++ b/fractal-gtk/src/appop/about.rs
@@ -4,7 +4,7 @@ use gtk;
use gtk::prelude::*;
use crate::appop::AppOp;
-use crate::globals;
+use crate::config;
impl AppOp {
pub fn about_dialog(&self) {
@@ -14,18 +14,15 @@ impl AppOp {
.get_object("main_window")
.expect("Can't find main_window in ui file.");
- let program_name = format!(
- "Fractal{}",
- globals::NAME_SUFFIX.unwrap_or(" (Development)")
- );
+ let program_name = format!("Fractal{}", config::NAME_SUFFIX);
let dialog = gtk::AboutDialog::new();
- dialog.set_logo_icon_name(globals::APP_ID.unwrap_or("org.gnome.FractalDevel"));
+ dialog.set_logo_icon_name(config::APP_ID);
dialog.set_comments(i18n("A Matrix.org client for GNOME").as_str());
dialog.set_copyright(i18n("© 2017–2018 Daniel García Moreno, et al.").as_str());
dialog.set_license_type(gtk::License::Gpl30);
dialog.set_modal(true);
- dialog.set_version(globals::VERSION.unwrap_or("0.0.0"));
+ dialog.set_version(config::VERSION);
dialog.set_program_name(&program_name);
dialog.set_website("https://wiki.gnome.org/Fractal");
dialog.set_website_label(i18n("Learn more about Fractal").as_str());
diff --git a/fractal-gtk/src/config.rs.in b/fractal-gtk/src/config.rs.in
new file mode 100644
index 00000000..751e9160
--- /dev/null
+++ b/fractal-gtk/src/config.rs.in
@@ -0,0 +1,23 @@
+// config.rs
+//
+// 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 LOCALEDIR: &'static str = @LOCALEDIR@;
+pub static APP_ID: &'static str = @APP_ID@;
+pub static NAME_SUFFIX: &'static str = @NAME_SUFFIX@;
+pub static VERSION: &'static str = @VERSION@;
diff --git a/fractal-gtk/src/globals.rs b/fractal-gtk/src/globals.rs
index 0657f9d0..40cd2318 100644
--- a/fractal-gtk/src/globals.rs
+++ b/fractal-gtk/src/globals.rs
@@ -10,8 +10,3 @@ pub static RIOT_REGISTER_URL: &'static str = "https://riot.im/app/#/register";
pub static MAX_IMAGE_SIZE: (i32, i32) = (600, 400);
pub static MAX_STICKER_SIZE: (i32, i32) = (200, 130);
-
-pub static LOCALEDIR: Option<&'static str> = option_env!("FRACTAL_LOCALEDIR");
-pub static APP_ID: Option<&'static str> = option_env!("FRACTAL_APP_ID");
-pub static NAME_SUFFIX: Option<&'static str> = option_env!("FRACTAL_NAME_SUFFIX");
-pub static VERSION: Option<&'static str> = option_env!("FRACTAL_VERSION");
diff --git a/fractal-gtk/src/main.rs b/fractal-gtk/src/main.rs
index 17f65329..e50b5d1b 100644
--- a/fractal-gtk/src/main.rs
+++ b/fractal-gtk/src/main.rs
@@ -2,6 +2,7 @@ use fractal_api::backend;
use fractal_api::error;
use fractal_api::types;
+mod config;
mod globals;
mod i18n;
#[macro_use]
@@ -55,8 +56,7 @@ fn main() -> Result<(), Box<dyn Error>> {
gst::init()?;
// Create a Application with default flags
- let appid = globals::APP_ID.unwrap_or("org.gnome.FractalDevel");
- let application = gtk::Application::new(appid, gio::ApplicationFlags::empty())?;
+ let application = gtk::Application::new(config::APP_ID, gio::ApplicationFlags::empty())?;
application.set_property_resource_base_path(Some("/org/gnome/Fractal"));
diff --git a/fractal-gtk/src/meson.build b/fractal-gtk/src/meson.build
new file mode 100644
index 00000000..f407fe01
--- /dev/null
+++ b/fractal-gtk/src/meson.build
@@ -0,0 +1,34 @@
+global_conf = configuration_data()
+global_conf.set_quoted('APP_ID', application_id)
+global_conf.set_quoted('VERSION', fractal_version + version_suffix)
+global_conf.set_quoted('LOCALEDIR', fractal_localedir)
+global_conf.set_quoted('NAME_SUFFIX', name_suffix)
+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
+)
+
+c = run_command(grabber)
+sources = c.stdout().strip().split('\n')
+
+cargo_release = custom_target('cargo-build',
+ build_by_default: true,
+ input: sources,
+ output: ['fractal'],
+ install: true,
+ install_dir: fractal_bindir,
+ console: true,
+ command: [cargo_script,
+ '@SOURCE_ROOT@',
+ '@OUTPUT@',
+ profile
+ ])
+
diff --git a/meson.build b/meson.build
index 9725dc42..7eba5d80 100644
--- a/meson.build
+++ b/meson.build
@@ -73,25 +73,7 @@ cargo_script = find_program('scripts/cargo.sh')
grabber = find_program('scripts/grabber.sh')
cargo_release = find_program('scripts/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: ['fractal'],
- install: true,
- install_dir: fractal_bindir,
- console: true,
- command: [cargo_script,
- '@CURRENT_SOURCE_DIR@',
- '@OUTPUT@',
- fractal_localedir,
- application_id,
- name_suffix,
- fractal_version + version_suffix,
- profile
- ])
+subdir('fractal-gtk/src')
run_target('release', command: ['scripts/release.sh',
meson.project_name() + '-' + fractal_version
diff --git a/scripts/cargo.sh b/scripts/cargo.sh
index da15a769..7d4051a1 100755
--- a/scripts/cargo.sh
+++ b/scripts/cargo.sh
@@ -1,11 +1,7 @@
#!/bin/sh
export CARGO_HOME=$1/target/cargo-home
-export FRACTAL_LOCALEDIR="$3"
-export FRACTAL_APP_ID="$4"
-export FRACTAL_NAME_SUFFIX="$5"
-export FRACTAL_VERSION="$6"
-export FRACTAL_PROFILE="$7"
+export FRACTAL_PROFILE="$3"
if [ "$FRACTAL_PROFILE" = "Devel" ]
then
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]