Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Meson configuration more readable #107

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/com.ranfdev.Geopard.desktop.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Terminal=false
Categories=GNOME;GTK;Network;
Keywords=Gnome;GTK;browser;gemini;rust;
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
Icon=@icon@
Icon=@APP_ID@
StartupNotify=true
MimeType=x-scheme-handler/gemini;text/gemini;text/plain;
X-Purism-FormFactor=Workstation;Mobile;
4 changes: 2 additions & 2 deletions data/com.ranfdev.Geopard.gschema.xml.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<schemalist>
<schema path="/com/ranfdev/Geopard/" id="@app-id@" gettext-domain="@gettext-package@">
<schemalist gettext-domain="geopard">
<schema id="@APP_ID@" path="@ROOT_PATH@/">
<key name="window-width" type="i">
<default>600</default>
<summary>Window width</summary>
Expand Down
13 changes: 7 additions & 6 deletions data/com.ranfdev.Geopard.metainfo.xml.in.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>@app-id@</id>
<id>@APP_ID@</id>
<name translate="no">Geopard</name>
<summary>Browse Gemini pages</summary>
<developer id="com.ranfdev">
<name translate="no">Lorenzo Miglietta</name>
</developer>

<launchable type="desktop-id">@app-id@.desktop</launchable>
<translation type="gettext">@gettext-package@</translation>
<launchable type="desktop-id">@APP_ID@.desktop</launchable>
<translation type="gettext">geopard</translation>
<metadata_license>CC0</metadata_license>
<project_license>GPL-3.0-or-later</project_license>
<update_contact>ranfdev@gmail.com</update_contact>
Expand Down Expand Up @@ -51,9 +51,10 @@
</screenshot>
</screenshots>

<url type="homepage">https://ranfdev.com/projects/Geopard</url>
<url type="bugtracker">https://github.com/ranfdev/Geopard/issues/</url>
<url type="donation">https://github.com/sponsors/ranfdev</url>
<url type="homepage">@PROJECT_URL@</url>
<url type="vcs-browser">@REPO_URL@</url>
<url type="bugtracker">@BUGTRACKER_URL@</url>
<url type="donation">@DONATIONS_URL@</url>

<branding>
<color type="primary" scheme_preference="light">#deddda</color>
Expand Down
6 changes: 3 additions & 3 deletions data/icons/meson.build
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
scalable_dir = join_paths('hicolor', 'scalable', 'apps')
install_data(
join_paths(scalable_dir, '@0@.svg'.format(application_id)),
join_paths(scalable_dir, ('@0@.svg').format(APPLICATION_ID)),
install_dir: join_paths(get_option('datadir'), 'icons', scalable_dir),
)

symbolic_dir = join_paths('hicolor', 'symbolic', 'apps')
install_data(
join_paths(symbolic_dir, 'com.ranfdev.Geopard-symbolic.svg'),
join_paths(symbolic_dir, ('@0@-symbolic.svg').format(PROJECT_RDNN_NAME)),
install_dir: join_paths(get_option('datadir'), 'icons', symbolic_dir),
rename: '@0@-symbolic.svg'.format(application_id)
rename: '@0@-symbolic.svg'.format(APPLICATION_ID)
)
67 changes: 30 additions & 37 deletions data/meson.build
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
# Desktop file
desktop_conf = configuration_data()
desktop_conf.set('icon', application_id)
# Translate and install desktop file
desktop_file = i18n.merge_file(
type: 'desktop',
input: configure_file(
input: '@0@.desktop.in.in'.format(base_id),
input: '@0@.desktop.in.in'.format(PROJECT_RDNN_NAME),
output: '@BASENAME@',
configuration: desktop_conf
configuration: conf
),
output: '@0@.desktop'.format(application_id),
po_dir: podir,
output: '@0@.desktop'.format(APPLICATION_ID),
type: 'desktop',
po_dir: '../po',
install: true,
install_dir: join_paths(get_option('datadir'), 'applications')
)

# Validate Desktop file
if desktop_file_validate.found()
test(
'validate-desktop',
desktop_file_validate,
args: [
desktop_file.full_path()
],
depends: desktop_file,
# Validate desktop file
desktop_utils = find_program('desktop-file-validate', required: false)
if desktop_utils.found()
test('Validate desktop file', desktop_utils,
args: [desktop_file.full_path()],
depends: desktop_file
)
endif

# Translate and install Metainfo file
metainfo_file = i18n.merge_file(
input: configure_file(
input: '@0@.metainfo.xml.in.in'.format(base_id),
input: '@0@.metainfo.xml.in.in'.format(PROJECT_RDNN_NAME),
output: '@BASENAME@',
configuration: configuration_data({
'app-id': application_id,
'gettext-package': gettext_package
'APP_ID': APPLICATION_ID,
'PROJECT_URL': PROJECT_URL,
'REPO_URL': REPO_URL,
'BUGTRACKER_URL': BUGTRACKER_URL,
'DONATIONS_URL': DONATIONS_URL,
#'TRANSLATE_URL': TRANSLATE_URL
})
),
output: '@0@.metainfo.xml'.format(application_id),
po_dir: podir,
output: '@0@.metainfo.xml'.format(APPLICATION_ID),
po_dir: '../po',
install: true,
install_dir: join_paths(get_option('datadir'), 'metainfo')
)
Expand All @@ -51,26 +50,20 @@ if appstream_cli.found()
)
endif

# GSchema
gschema_conf = configuration_data()
gschema_conf.set('app-id', application_id)
gschema_conf.set('gettext-package', gettext_package)

# Install GSettings schema
configure_file(
input: '@0@.gschema.xml.in'.format(base_id),
output: '@0@.gschema.xml'.format(application_id),
configuration: gschema_conf,
input: '@0@.gschema.xml.in'.format(PROJECT_RDNN_NAME),
output: '@0@.gschema.xml'.format(APPLICATION_ID),
configuration: conf,
install: true,
install_dir: join_paths(get_option('datadir'), 'glib-2.0/schemas')
)

# Validata GSchema
if glib_compile_schemas.found()
test(
'validate-gschema', glib_compile_schemas,
args: [
'--strict', '--dry-run', meson.current_build_dir()
],
# Validate GSchema file
compile_schemas = find_program('glib-compile-schemas', required: false)
if compile_schemas.found()
test('Validate schema file', compile_schemas,
args: ['--strict', '--dry-run', meson.current_build_dir()],
)
endif

Expand Down
2 changes: 1 addition & 1 deletion data/resources/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resources = gnome.compile_resources(
gresource_bundle: true,
source_dir: meson.current_build_dir(),
install: true,
install_dir: PKGDATA_DIR,
dependencies: blueprints,
install_dir: pkgdatadir,
)

2 changes: 2 additions & 0 deletions local-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if [[ "$answer" == "y" ]]; then
rm -r _build
fi

export RUST_LOG=debug

meson setup _build -Dprefix="$(pwd)/_build" -Dprofile=development
ninja -C _build install
meson devenv -C _build ./src/geopard
94 changes: 55 additions & 39 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,69 +1,85 @@
project(
'geopard',
'rust',
version: '1.6.0',
meson_version: '>= 0.59',
# license: MIT,
project('geopard', 'rust',
version: '1.6.0',
license: 'GPL-3.0-or-later',
meson_version: '>= 0.62.0',
default_options: ['warning_level=2',
'werror=false',
],
)

# Import modules
i18n = import('i18n')
gnome = import('gnome')

base_id = 'com.ranfdev.Geopard'
# Project information
PROJECT_URL = 'https://ranfdev.com/projects/Geopard'
REPO_URL = 'https://github.com/ranfdev/Geopard'
BUGTRACKER_URL = 'https://github.com/ranfdev/Geopard/issues'
DONATIONS_URL = 'https://github.com/sponsors/ranfdev'
#TRANSLATE_URL = 'https://hosted.weblate.org/projects/ranfdev/Geopard'

dependency('glib-2.0', version: '>= 2.66')
dependency('gio-2.0', version: '>= 2.66')
dependency('gtk4', version: '>= 4.0.0')

glib_compile_resources = find_program('glib-compile-resources', required: true)
glib_compile_schemas = find_program('glib-compile-schemas', required: true)
desktop_file_validate = find_program('desktop-file-validate', required: false)

cargo = find_program('cargo', required: true)
# Constants
PROJECT_RDNN_NAME = 'com.ranfdev.Geopard'
ROOT_PATH = '/com/ranfdev/Geopard'
BIN_DIR = join_paths(get_option('prefix'), get_option('bindir'))
PKGDATA_DIR = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())

version = meson.project_version()

bindir = join_paths(get_option('prefix'), get_option('bindir'))
localedir = join_paths(get_option('prefix'), get_option('localedir'))
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
iconsdir = join_paths(get_option('prefix'), get_option('datadir'), 'icons')
podir = join_paths(meson.project_source_root(), 'po')

gettext_package = meson.project_name()
# Check if cargo and git exist
cargo_bin = find_program('cargo', required: true)
git_bin = find_program('git', required: false)

# Set APPLICATION_ID and VERSION_SUFFIX
if get_option('profile') == 'development'
profile = 'Devel'
vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD', check: true).stdout().strip()
if vcs_tag == ''
version_suffix = '-devel'
if git_bin.found()
VCS_TAG = run_command('git', 'rev-parse', '--short', 'HEAD', check: true).stdout().strip()
else
VCS_TAG = ''
endif
if VCS_TAG == ''
VERSION_SUFFIX = '-devel'
else
version_suffix = '-@0@'.format(vcs_tag)
VERSION_SUFFIX = '-@0@'.format(VCS_TAG)
endif
application_id = '@0@.@1@'.format(base_id, profile)
APPLICATION_ID = '@0@.Devel'.format(PROJECT_RDNN_NAME)
else
profile = ''
version_suffix = ''
application_id = base_id
VERSION_SUFFIX = ''
APPLICATION_ID = PROJECT_RDNN_NAME
endif

# Required dependencies
dependency('glib-2.0', version: '>= 2.66')
dependency('gio-2.0', version: '>= 2.66')
dependency('gtk4', version: '>= 4.12.0')
dependency('libadwaita-1', version: '>= 1.5.0')

meson.add_dist_script(
'build-aux/dist-vendor.sh',
join_paths(meson.project_build_root(), 'meson-dist', meson.project_name() + '-' + version),
join_paths(meson.project_build_root(), 'meson-dist', meson.project_name() + '-' + meson.project_version()),
meson.project_source_root()
)

# Setup pre-commit hook to ensure the coding style is always consistent
if get_option('profile') == 'development'
# Setup pre-commit hook for ensuring coding style is always consistent
message('Setting up git pre-commit hook..')
message('Setting up git pre-commit hook...')
run_command('cp', '-f', 'hooks/pre-commit.hook', '.git/hooks/pre-commit', check: false)
run_command('chmod', '+x', '.git/hooks/pre-commit', check: false)
endif

# Set configuration data
conf = configuration_data()
conf.set('APP_ID', APPLICATION_ID)
conf.set('ROOT_PATH', ROOT_PATH)
conf.set('PKGDATA_DIR', PKGDATA_DIR)
conf.set('LOCALE_DIR', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('VERSION', meson.project_version() + VERSION_SUFFIX)
conf.set('GETTEXT_PACKAGE', meson.project_name())

# Subdirs
subdir('data')
subdir('po')
subdir('src')

# Create devenv if profile is set to 'development'
if get_option('profile') == 'development'
devenv = environment()

Expand All @@ -74,9 +90,9 @@ if get_option('profile') == 'development'
meson.add_devenv(devenv)
endif

# Execute post-installation GTK/GNOME scripts
gnome.post_install(
gtk_update_icon_cache: true,
glib_compile_schemas: true,
gtk_update_icon_cache: true,
update_desktop_database: true,
)

2 changes: 1 addition & 1 deletion po/meson.build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
i18n.gettext(gettext_package, preset: 'glib')
i18n.gettext('geopard', preset: 'glib')
22 changes: 15 additions & 7 deletions src/build_config.rs.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
pub const APP_ID: &str = @APP_ID@;
pub const _GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@;
pub const _LOCALEDIR: &str = @LOCALEDIR@;
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 _ROOT_PATH: &str = "@ROOT_PATH@";
pub const _PKGDATADIR: &str = "@PKGDATA_DIR@";
pub const _LOCALEDIR: &str = "@LOCALE_DIR@";
pub const _GETTEXT_PACKAGE: &str = "@GETTEXT_PACKAGE@";
pub const RESOURCES_FILE: &str = concat!("@PKGDATA_DIR@", "/resources.gresource");

pub const APP_ID: &str = "@APP_ID@";
pub const _RELEASE_VER: &str = "@RELEASE_VER@";
pub const VERSION: &str = "@VERSION@";
pub const _PROFILE: &str = "@PROFILE@";

pub const PROJECT_URL: &str = "@PROJECT_URL@";
pub const REPO_URL: &str = "@REPO_URL@";
pub const BUGTRACKER_URL: &str = "@BUGTRACKER_URL@";
pub const DONATIONS_URL: &str = "@DONATIONS_URL@";
Loading
Loading