Skip to content

Commit 8cbd660

Browse files
committed
feat: rewrite some parts of Meson configuration to make it more readable
1 parent 98fc751 commit 8cbd660

File tree

10 files changed

+135
-110
lines changed

10 files changed

+135
-110
lines changed

data/com.ranfdev.Geopard.desktop.in.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Terminal=false
77
Categories=GNOME;GTK;Network;
88
Keywords=Gnome;GTK;browser;gemini;rust;
99
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
10-
Icon=@icon@
10+
Icon=@APP_ID@
1111
StartupNotify=true
1212
MimeType=x-scheme-handler/gemini;text/gemini;text/plain;
1313
X-Purism-FormFactor=Workstation;Mobile;

data/com.ranfdev.Geopard.gschema.xml.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<schemalist>
3-
<schema path="/com/ranfdev/Geopard/" id="@app-id@" gettext-domain="@gettext-package@">
2+
<schemalist gettext-domain="geopard">
3+
<schema id="@APP_ID@" path="@ROOT_PATH@/">
44
<key name="window-width" type="i">
55
<default>600</default>
66
<summary>Window width</summary>

data/com.ranfdev.Geopard.metainfo.xml.in.in

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<component type="desktop-application">
3-
<id>@app-id@</id>
3+
<id>@APP_ID@</id>
44
<name translate="no">Geopard</name>
55
<summary>Browse Gemini pages</summary>
66
<developer id="com.ranfdev">
77
<name translate="no">Lorenzo Miglietta</name>
88
</developer>
99

10-
<launchable type="desktop-id">@app-id@.desktop</launchable>
11-
<translation type="gettext">@gettext-package@</translation>
10+
<launchable type="desktop-id">@APP_ID@.desktop</launchable>
11+
<translation type="gettext">geopard</translation>
1212
<metadata_license>CC0</metadata_license>
1313
<project_license>GPL-3.0-or-later</project_license>
1414
<update_contact>[email protected]</update_contact>
@@ -51,9 +51,10 @@
5151
</screenshot>
5252
</screenshots>
5353

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

5859
<branding>
5960
<color type="primary" scheme_preference="light">#deddda</color>

data/icons/meson.build

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
scalable_dir = join_paths('hicolor', 'scalable', 'apps')
22
install_data(
3-
join_paths(scalable_dir, '@[email protected]'.format(application_id)),
3+
join_paths(scalable_dir, ('@[email protected]').format(APPLICATION_ID)),
44
install_dir: join_paths(get_option('datadir'), 'icons', scalable_dir),
55
)
66

77
symbolic_dir = join_paths('hicolor', 'symbolic', 'apps')
88
install_data(
9-
join_paths(symbolic_dir, 'com.ranfdev.Geopard-symbolic.svg'),
9+
join_paths(symbolic_dir, ('@0@-symbolic.svg').format(PROJECT_RDNN_NAME)),
1010
install_dir: join_paths(get_option('datadir'), 'icons', symbolic_dir),
11-
rename: '@[email protected]'.format(application_id)
11+
rename: '@[email protected]'.format(APPLICATION_ID)
1212
)

data/meson.build

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
1-
# Desktop file
2-
desktop_conf = configuration_data()
3-
desktop_conf.set('icon', application_id)
1+
# Translate and install desktop file
42
desktop_file = i18n.merge_file(
5-
type: 'desktop',
63
input: configure_file(
7-
input: '@[email protected]'.format(base_id),
4+
input: '@[email protected]'.format(PROJECT_RDNN_NAME),
85
output: '@BASENAME@',
9-
configuration: desktop_conf
6+
configuration: conf
107
),
11-
output: '@[email protected]'.format(application_id),
12-
po_dir: podir,
8+
output: '@[email protected]'.format(APPLICATION_ID),
9+
type: 'desktop',
10+
po_dir: '../po',
1311
install: true,
1412
install_dir: join_paths(get_option('datadir'), 'applications')
1513
)
1614

17-
# Validate Desktop file
18-
if desktop_file_validate.found()
19-
test(
20-
'validate-desktop',
21-
desktop_file_validate,
22-
args: [
23-
desktop_file.full_path()
24-
],
25-
depends: desktop_file,
15+
# Validate desktop file
16+
desktop_utils = find_program('desktop-file-validate', required: false)
17+
if desktop_utils.found()
18+
test('Validate desktop file', desktop_utils,
19+
args: [desktop_file.full_path()],
20+
depends: desktop_file
2621
)
2722
endif
2823

2924
# Translate and install Metainfo file
3025
metainfo_file = i18n.merge_file(
3126
input: configure_file(
32-
input: '@[email protected]'.format(base_id),
27+
input: '@[email protected]'.format(PROJECT_RDNN_NAME),
3328
output: '@BASENAME@',
3429
configuration: configuration_data({
35-
'app-id': application_id,
36-
'gettext-package': gettext_package
30+
'APP_ID': APPLICATION_ID,
31+
'PROJECT_URL': PROJECT_URL,
32+
'REPO_URL': REPO_URL,
33+
'BUGTRACKER_URL': BUGTRACKER_URL,
34+
'DONATIONS_URL': DONATIONS_URL,
35+
#'TRANSLATE_URL': TRANSLATE_URL
3736
})
3837
),
39-
output: '@[email protected]'.format(application_id),
40-
po_dir: podir,
38+
output: '@[email protected]'.format(APPLICATION_ID),
39+
po_dir: '../po',
4140
install: true,
4241
install_dir: join_paths(get_option('datadir'), 'metainfo')
4342
)
@@ -51,26 +50,20 @@ if appstream_cli.found()
5150
)
5251
endif
5352

54-
# GSchema
55-
gschema_conf = configuration_data()
56-
gschema_conf.set('app-id', application_id)
57-
gschema_conf.set('gettext-package', gettext_package)
58-
53+
# Install GSettings schema
5954
configure_file(
60-
input: '@[email protected]'.format(base_id),
61-
output: '@[email protected]'.format(application_id),
62-
configuration: gschema_conf,
55+
input: '@[email protected]'.format(PROJECT_RDNN_NAME),
56+
output: '@[email protected]'.format(APPLICATION_ID),
57+
configuration: conf,
6358
install: true,
6459
install_dir: join_paths(get_option('datadir'), 'glib-2.0/schemas')
6560
)
6661

67-
# Validata GSchema
68-
if glib_compile_schemas.found()
69-
test(
70-
'validate-gschema', glib_compile_schemas,
71-
args: [
72-
'--strict', '--dry-run', meson.current_build_dir()
73-
],
62+
# Validate GSchema file
63+
compile_schemas = find_program('glib-compile-schemas', required: false)
64+
if compile_schemas.found()
65+
test('Validate schema file', compile_schemas,
66+
args: ['--strict', '--dry-run', meson.current_build_dir()],
7467
)
7568
endif
7669

data/resources/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ resources = gnome.compile_resources(
1616
gresource_bundle: true,
1717
source_dir: meson.current_build_dir(),
1818
install: true,
19+
install_dir: PKGDATA_DIR,
1920
dependencies: blueprints,
20-
install_dir: pkgdatadir,
2121
)
2222

meson.build

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,85 @@
1-
project(
2-
'geopard',
3-
'rust',
4-
version: '1.5.0',
5-
meson_version: '>= 0.59',
6-
# license: MIT,
1+
project('geopard', 'rust',
2+
version: '1.5.0',
3+
license: 'GPL-3.0-or-later',
4+
meson_version: '>= 0.62.0',
5+
default_options: ['warning_level=2',
6+
'werror=false',
7+
],
78
)
89

10+
# Import modules
911
i18n = import('i18n')
1012
gnome = import('gnome')
1113

12-
base_id = 'com.ranfdev.Geopard'
14+
# Project information
15+
PROJECT_URL = 'https://ranfdev.com/projects/Geopard'
16+
REPO_URL = 'https://github.com/ranfdev/Geopard'
17+
BUGTRACKER_URL = 'https://github.com/ranfdev/Geopard/issues'
18+
DONATIONS_URL = 'https://github.com/sponsors/ranfdev'
19+
#TRANSLATE_URL = 'https://hosted.weblate.org/projects/ranfdev/Geopard'
1320

14-
dependency('glib-2.0', version: '>= 2.66')
15-
dependency('gio-2.0', version: '>= 2.66')
16-
dependency('gtk4', version: '>= 4.0.0')
17-
18-
glib_compile_resources = find_program('glib-compile-resources', required: true)
19-
glib_compile_schemas = find_program('glib-compile-schemas', required: true)
20-
desktop_file_validate = find_program('desktop-file-validate', required: false)
21-
22-
cargo = find_program('cargo', required: true)
21+
# Constants
22+
PROJECT_RDNN_NAME = 'com.ranfdev.Geopard'
23+
ROOT_PATH = '/com/ranfdev/Geopard'
24+
BIN_DIR = join_paths(get_option('prefix'), get_option('bindir'))
25+
PKGDATA_DIR = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
2326

24-
version = meson.project_version()
25-
26-
bindir = join_paths(get_option('prefix'), get_option('bindir'))
27-
localedir = join_paths(get_option('prefix'), get_option('localedir'))
28-
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
29-
iconsdir = join_paths(get_option('prefix'), get_option('datadir'), 'icons')
30-
podir = join_paths(meson.project_source_root(), 'po')
31-
32-
gettext_package = meson.project_name()
27+
# Check if cargo and git exist
28+
cargo_bin = find_program('cargo', required: true)
29+
git_bin = find_program('git', required: false)
3330

31+
# Set APPLICATION_ID and VERSION_SUFFIX
3432
if get_option('profile') == 'development'
35-
profile = 'Devel'
36-
vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD', check: true).stdout().strip()
37-
if vcs_tag == ''
38-
version_suffix = '-devel'
33+
if git_bin.found()
34+
VCS_TAG = run_command('git', 'rev-parse', '--short', 'HEAD', check: true).stdout().strip()
35+
else
36+
VCS_TAG = ''
37+
endif
38+
if VCS_TAG == ''
39+
VERSION_SUFFIX = '-devel'
3940
else
40-
version_suffix = '-@0@'.format(vcs_tag)
41+
VERSION_SUFFIX = '-@0@'.format(VCS_TAG)
4142
endif
42-
application_id = '@0@.@1@'.format(base_id, profile)
43+
APPLICATION_ID = '@0@.Devel'.format(PROJECT_RDNN_NAME)
4344
else
44-
profile = ''
45-
version_suffix = ''
46-
application_id = base_id
45+
VERSION_SUFFIX = ''
46+
APPLICATION_ID = PROJECT_RDNN_NAME
4747
endif
4848

49+
# Required dependencies
50+
dependency('glib-2.0', version: '>= 2.66')
51+
dependency('gio-2.0', version: '>= 2.66')
52+
dependency('gtk4', version: '>= 4.12.0')
53+
dependency('libadwaita-1', version: '>= 1.5.0')
4954

5055
meson.add_dist_script(
5156
'build-aux/dist-vendor.sh',
52-
join_paths(meson.project_build_root(), 'meson-dist', meson.project_name() + '-' + version),
57+
join_paths(meson.project_build_root(), 'meson-dist', meson.project_name() + '-' + meson.project_version()),
5358
meson.project_source_root()
5459
)
5560

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

68+
# Set configuration data
69+
conf = configuration_data()
70+
conf.set('APP_ID', APPLICATION_ID)
71+
conf.set('ROOT_PATH', ROOT_PATH)
72+
conf.set('PKGDATA_DIR', PKGDATA_DIR)
73+
conf.set('LOCALE_DIR', join_paths(get_option('prefix'), get_option('localedir')))
74+
conf.set('VERSION', meson.project_version() + VERSION_SUFFIX)
75+
conf.set('GETTEXT_PACKAGE', meson.project_name())
76+
77+
# Subdirs
6378
subdir('data')
6479
subdir('po')
6580
subdir('src')
6681

82+
# Create devenv if profile is set to 'development'
6783
if get_option('profile') == 'development'
6884
devenv = environment()
6985

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

93+
# Execute post-installation GTK/GNOME scripts
7794
gnome.post_install(
78-
gtk_update_icon_cache: true,
7995
glib_compile_schemas: true,
96+
gtk_update_icon_cache: true,
8097
update_desktop_database: true,
8198
)
82-

po/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
i18n.gettext(gettext_package, preset: 'glib')
1+
i18n.gettext('geopard', preset: 'glib')

src/build_config.rs.in

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
pub const APP_ID: &str = @APP_ID@;
2-
pub const _GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@;
3-
pub const _LOCALEDIR: &str = @LOCALEDIR@;
4-
pub const _PKGDATADIR: &str = @PKGDATADIR@;
5-
pub const _PROFILE: &str = @PROFILE@;
6-
pub const RESOURCES_FILE: &str = concat!(@PKGDATADIR@, "/resources.gresource");
7-
pub const VERSION: &str = @VERSION@;
1+
pub const _ROOT_PATH: &str = "@ROOT_PATH@";
2+
pub const _PKGDATADIR: &str = "@PKGDATA_DIR@";
3+
pub const _LOCALEDIR: &str = "@LOCALE_DIR@";
4+
pub const _GETTEXT_PACKAGE: &str = "@GETTEXT_PACKAGE@";
5+
pub const RESOURCES_FILE: &str = concat!("@PKGDATA_DIR@", "/resources.gresource");
6+
7+
pub const APP_ID: &str = "@APP_ID@";
8+
pub const _RELEASE_VER: &str = "@RELEASE_VER@";
9+
pub const VERSION: &str = "@VERSION@";
10+
pub const _PROFILE: &str = "@PROFILE@";
11+
12+
pub const PROJECT_URL: &str = "@PROJECT_URL@";
13+
pub const REPO_URL: &str = "@REPO_URL@";
14+
pub const BUGTRACKER_URL: &str = "@BUGTRACKER_URL@";
15+
pub const DONATIONS_URL: &str = "@DONATIONS_URL@";

src/meson.build

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
global_conf = configuration_data()
2-
global_conf.set_quoted('APP_ID', application_id)
3-
global_conf.set_quoted('PKGDATADIR', pkgdatadir)
4-
global_conf.set_quoted('PROFILE', profile)
5-
global_conf.set_quoted('VERSION', version + version_suffix)
6-
global_conf.set_quoted('GETTEXT_PACKAGE', gettext_package)
7-
global_conf.set_quoted('LOCALEDIR', localedir)
8-
9-
config = configure_file(
1+
# Generate config module
2+
configure_file(
103
input: 'build_config.rs.in',
114
output: 'build_config.rs',
12-
configuration: global_conf
5+
configuration: configuration_data({
6+
'APP_ID': APPLICATION_ID,
7+
'ROOT_PATH': ROOT_PATH,
8+
'RELEASE_VER': meson.project_version(),
9+
'VERSION': meson.project_version() + VERSION_SUFFIX,
10+
'PROFILE': get_option('profile'),
11+
'PROJECT_URL': PROJECT_URL,
12+
'REPO_URL': REPO_URL,
13+
'BUGTRACKER_URL': BUGTRACKER_URL,
14+
'DONATIONS_URL': DONATIONS_URL,
15+
#'TRANSLATE_URL': TRANSLATE_URL,
16+
'PKGDATA_DIR': PKGDATA_DIR,
17+
'LOCALE_DIR': conf.get('LOCALE_DIR'),
18+
'GETTEXT_PACKAGE': meson.project_name()
19+
})
1320
)
1421

1522
# Copy the config.rs output to the source directory.
@@ -39,19 +46,19 @@ endif
3946

4047
cargo_env = [ 'CARGO_HOME=' + join_paths(meson.project_build_root(), 'cargo-home') ]
4148

42-
cargo_build = custom_target(
49+
custom_target(
4350
'cargo-build',
4451
build_by_default: true,
4552
build_always_stale: true,
4653
output: meson.project_name(),
4754
console: true,
4855
install: true,
49-
install_dir: bindir,
56+
install_dir: BIN_DIR,
5057
depends: resources,
5158
command: [
5259
'env',
5360
cargo_env,
54-
cargo, 'build',
61+
cargo_bin, 'build',
5562
cargo_options,
5663
'&&',
5764
'cp', join_paths('src', rust_target, meson.project_name()), '@OUTPUT@',

0 commit comments

Comments
 (0)