[gnome-characters/bilelmoussaoui/devel-mode] misc: implement a proper devel mode




commit 3b84cc750b70482a1cc30864dc51cde60df0332d
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Fri Nov 26 10:50:17 2021 +0100

    misc: implement a proper devel mode
    
    Instead of depending on the build profile
    Fixes #62

 ...ers.Devel.svg => org.gnome.CharactersDevel.svg} |  0
 data/icons/meson.build                             |  9 ++--
 data/meson.build                                   | 59 ++++++++++----------
 ...g.gnome.Characters.BackgroundService.service.in |  4 +-
 meson.build                                        | 26 ++++++---
 meson_options.txt                                  | 11 ++++
 meson_post_install.py                              | 32 ++++-------
 po/meson.build                                     |  2 +-
 src/main.js                                        |  5 +-
 src/meson.build                                    | 62 +++++++++++++---------
 src/org.gnome.Characters.BackgroundService.in      |  3 +-
 ...racters.BackgroundService.src.gresource.xml.in} |  2 +-
 src/org.gnome.Characters.in                        |  3 +-
 ...l => org.gnome.Characters.src.gresource.xml.in} |  2 +-
 src/searchProvider.js                              |  3 +-
 src/service.js                                     |  3 +-
 src/window.js                                      |  2 +-
 tests/meson.build                                  |  4 +-
 18 files changed, 126 insertions(+), 106 deletions(-)
---
diff --git a/data/icons/hicolor/scalable/apps/org.gnome.Characters.Devel.svg 
b/data/icons/hicolor/scalable/apps/org.gnome.CharactersDevel.svg
similarity index 100%
rename from data/icons/hicolor/scalable/apps/org.gnome.Characters.Devel.svg
rename to data/icons/hicolor/scalable/apps/org.gnome.CharactersDevel.svg
diff --git a/data/icons/meson.build b/data/icons/meson.build
index 8161cf2..4ae68d1 100644
--- a/data/icons/meson.build
+++ b/data/icons/meson.build
@@ -4,13 +4,12 @@ scalable_path = join_paths('hicolor', 'scalable', 'apps')
 symbolic_path = join_paths('hicolor', 'symbolic', 'apps')
 
 install_data(
-  join_paths(scalable_path, 'org.gnome.Characters.svg'),
-  install_dir: join_paths(icons_dir, scalable_path),
-  rename: '@0@.svg'.format(characters_application_id)
+  join_paths(scalable_path, application_id + '.svg'),
+  install_dir: join_paths(icons_dir, scalable_path)
 )
 
 install_data(
   join_paths(symbolic_path, 'org.gnome.Characters-symbolic.svg'),
   install_dir: join_paths(icons_dir, symbolic_path),
-  rename: '@0 -symbolic svg'.format(characters_application_id)
-)
\ No newline at end of file
+  rename: '@0 -symbolic svg'.format(application_id)
+)
diff --git a/data/meson.build b/data/meson.build
index 2ad8c05..202d1f7 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -15,46 +15,44 @@ resource_data = files(
   'window.ui',
 )
 
-resources = [
-  [characters_name, resource_data],
-  [characters_background_name, files('ShellSearchProvider2.xml')]
-]
-
-foreach resource: resources
-  name = resource[0] + '.data'
+gnome.compile_resources(
+    application_id + '.data',
+    'org.gnome.Characters.data.gresource.xml',
+    gresource_bundle: true,
+    dependencies: resource_data,
+    install: true,
+    install_dir: characters_pkgdatadir
+)
 
-  gnome.compile_resources(
-    name,
-    name + '.gresource.xml',
+gnome.compile_resources(
+    application_id + '.BackgroundService.data',
+    'org.gnome.Characters.BackgroundService.data.gresource.xml',
     gresource_bundle: true,
-    dependencies: resource[1],
+    dependencies: files('ShellSearchProvider2.xml'),
     install: true,
     install_dir: characters_pkgdatadir
-  )
-endforeach
+)
 
 desktop_conf = configuration_data ()
-desktop_conf.set('appid', characters_application_id)
+desktop_conf.set('appid', application_id)
 desktop_conf.set('bindir', characters_bindir)
 
 i18n.merge_file(
-  'desktop-file',
   type: 'desktop',
   input: configure_file (
-    input: characters_name + '.desktop.in',
-    output: characters_name + '.desktop.in',
+    input: 'org.gnome.Characters.desktop.in',
+    output: '@BASENAME@',
     configuration: desktop_conf
   ),
-  output: characters_application_id + '.desktop',
+  output: application_id + '.desktop',
   po_dir: po_dir,
   install: true,
   install_dir: join_paths(characters_datadir, 'applications')
 )
 
 appdata_file = i18n.merge_file(
-  'appdata-file',
-  input: characters_name + '.appdata.xml.in',
-  output: characters_application_id + '.appdata.xml',
+  input: 'org.gnome.Characters.appdata.xml.in',
+  output: application_id + '.appdata.xml',
   po_dir: po_dir,
   install: true,
   install_dir: join_paths(characters_datadir, 'metainfo')
@@ -71,38 +69,37 @@ if appstream_util.found()
 endif
 
 service_conf = configuration_data()
-service_conf.set('appid', characters_application_id)
+service_conf.set('appid', application_id)
 service_conf.set('bindir', characters_bindir)
-service_conf.set('PACKAGE_NAME', characters_name)
 service_conf.set('pkgdatadir', characters_pkgdatadir)
 
 configure_file(
-  input: characters_name + '.service.in',
-  output: characters_application_id + '.service',
+  input: 'org.gnome.Characters.service.in',
+  output: application_id + '.service',
   configuration: service_conf,
   install: true,
   install_dir: dbus_service_dir
 )
 
 configure_file(
-  input: characters_background_name + '.service.in',
-  output: characters_background_name + '.service',
+  input: 'org.gnome.Characters.BackgroundService.service.in',
+  output: application_id + '.BackgroundService.service',
   configuration: service_conf,
   install: true,
   install_dir: dbus_service_dir
 )
 
 install_data(
-  characters_name + '.gschema.xml',
+  'org.gnome.Characters.gschema.xml',
   install_dir: join_paths(characters_datadir, 'glib-2.0', 'schemas')
 )
 
 search_provider_conf = configuration_data()
-search_provider_conf.set('appid', characters_application_id)
+search_provider_conf.set('appid', application_id)
 
 configure_file(
-  input: characters_name + '.search-provider.ini',
-  output: characters_name + '.search-provider.ini',
+  input: 'org.gnome.Characters.search-provider.ini',
+  output: application_id + '.search-provider.ini',
   configuration: search_provider_conf,
   install: true,
   install_dir: join_paths(characters_datadir, 'gnome-shell', 'search-providers')
diff --git a/data/org.gnome.Characters.BackgroundService.service.in 
b/data/org.gnome.Characters.BackgroundService.service.in
index 484a690..88fd8c0 100644
--- a/data/org.gnome.Characters.BackgroundService.service.in
+++ b/data/org.gnome.Characters.BackgroundService.service.in
@@ -1,3 +1,3 @@
 [D-BUS Service]
-Name=@PACKAGE_NAME@.BackgroundService
-Exec=@pkgdatadir@/@PACKAGE_NAME@.BackgroundService
+Name=@appid@.BackgroundService
+Exec=@pkgdatadir@/@appid@.BackgroundService
diff --git a/meson.build b/meson.build
index 893b935..86afcfa 100644
--- a/meson.build
+++ b/meson.build
@@ -6,9 +6,20 @@ project(
   meson_version: '>= 0.46.0'
 )
 
-characters_name = 'org.gnome.Characters'
-characters_background_name = characters_name + '.BackgroundService'
-characters_application_id = characters_name + (get_option('buildtype').contains('debug') ? 'Devel' : '')
+if get_option('profile') == 'development'
+  profile = 'Devel'
+  vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD').stdout().strip()
+  if vcs_tag == ''
+    version_suffix = '-devel'
+  else
+    version_suffix = '-@0@'.format (vcs_tag)
+  endif
+else
+  profile = ''
+  version_suffix = ''
+endif
+application_id = 'org.gnome.Characters@0@'.format(profile)
+background_service_id = application_id + '.BackgroundService'
 
 characters_version = meson.project_version()
 
@@ -18,8 +29,8 @@ characters_datadir = join_paths(characters_prefix, get_option('datadir'))
 characters_libdir = join_paths(characters_prefix, get_option('libdir'))
 characters_libexecdir = join_paths(characters_prefix, get_option('libexecdir'))
 
-characters_pkgdatadir = join_paths(characters_datadir, characters_name)
-characters_pkglibdir = join_paths(characters_libdir, characters_name)
+characters_pkgdatadir = join_paths(characters_datadir, application_id)
+characters_pkglibdir = join_paths(characters_libdir, application_id)
 
 characters_gir_version = '1.0'
 characters_ns = 'Gc'
@@ -84,5 +95,8 @@ configure_file(
 meson.add_install_script(
   'meson_post_install.py',
   characters_datadir,
-  characters_bindir
+  characters_bindir,
+  characters_pkgdatadir,
+  application_id
 )
+
diff --git a/meson_options.txt b/meson_options.txt
index 62ff6fa..4e031ad 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,3 +1,14 @@
 option('dbus_service_dir', type: 'string', value: '', description: 'custom directory for dbus service files')
 option('pangoft2', type: 'boolean', value: true, description: 'enable pangoft2 support')
 option('installed_tests', type: 'boolean', value: false, description: 'Enable installation of some test 
cases')
+option(
+  'profile',
+  type: 'combo',
+  choices: [
+    'default',
+    'development'
+  ],
+  value: 'default',
+  description: 'The build profile for GTK Rust Template. One of "default" or "development".'
+)
+
diff --git a/meson_post_install.py b/meson_post_install.py
index 749f574..64c0ab0 100644
--- a/meson_post_install.py
+++ b/meson_post_install.py
@@ -1,41 +1,29 @@
 #!/usr/bin/env python3
 
-import glob
 import os
-import re
 import subprocess
 import sys
 
-datadir = sys.argv[1]
-
 destdir = os.environ.get('DESTDIR', '')
+datadir = sys.argv[1]
 bindir = os.path.normpath(destdir + os.sep + sys.argv[2])
+pkgdatadir = sys.argv[3]
+application_id = sys.argv[4]
 
-# FIXME: meson will not track the creation of these files
-#        https://github.com/mesonbuild/meson/blob/master/mesonbuild/scripts/uninstall.py#L39
 if not os.path.exists(bindir):
   os.makedirs(bindir)
 
-src = os.path.join(datadir, 'org.gnome.Characters', 'org.gnome.Characters')
+src = os.path.join(pkgdatadir, application_id)
 dest = os.path.join(bindir, 'gnome-characters')
 subprocess.call(['ln', '-s', '-f', src, dest])
 
 if not os.environ.get('DESTDIR'):
-  icondir = os.path.join(datadir, 'icons', 'hicolor')
-
-  print('Update icon cache...')
-  subprocess.call(['gtk-update-icon-cache', '-f', '-t', icondir])
+    print('Compiling gsettings schemas...')
+    subprocess.call(['glib-compile-schemas', os.path.join(datadir, 'glib-2.0', 'schemas')])
 
-  schemadir = os.path.join(datadir, 'glib-2.0', 'schemas')
-  print('Compiling gsettings schemas...')
-  subprocess.call(['glib-compile-schemas', schemadir])
+    print('Updating icon cache...')
+    subprocess.call(['gtk-update-icon-cache', '-qtf', os.path.join(datadir, 'icons', 'hicolor')])
 
-  # FIXME
-  '''
-  search_pattern = '/*.desktop'
+    print('Updating desktop database...')
+    subprocess.call(['update-desktop-database', '-q', os.path.join(datadir, 'applications')])
 
-  desktopdir = os.path.join(datadir, 'applications')
-  print('Validate desktop files...')
-  [subprocess.call(['desktop-file-validate', file])
-   for file in glob.glob(desktopdir + search_pattern, recursive=False)]
-  '''
diff --git a/po/meson.build b/po/meson.build
index cb7909d..24846bf 100644
--- a/po/meson.build
+++ b/po/meson.build
@@ -1 +1 @@
-i18n.gettext(characters_name, preset: 'glib')
+i18n.gettext('org.gnome.Characters', preset: 'glib')
diff --git a/src/main.js b/src/main.js
index d2ffde7..d84d3f3 100644
--- a/src/main.js
+++ b/src/main.js
@@ -46,13 +46,12 @@ const { MainWindow } = imports.window;
 const Util = imports.util;
 
 var settings = null;
-var applicationId = pkg.name;
 
 var MyApplication = GObject.registerClass({
 }, class MyApplication extends Adw.Application {
     _init() {
         super._init({
-            application_id: applicationId,
+            application_id: pkg.name,
             flags: Gio.ApplicationFlags.FLAGS_NONE,
             resource_base_path: '/org/gnome/Characters',
         });
@@ -97,6 +96,8 @@ var MyApplication = GObject.registerClass({
         if (!this._appwindow)
             this._appwindow = new MainWindow(this);
 
+        if (pkg.name.endsWith('Devel'))
+            this._appwindow.add_css_class('devel');
 
         this._appwindow.present();
         log('Characters Application activated');
diff --git a/src/meson.build b/src/meson.build
index f9401a2..26d9be1 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,24 +1,25 @@
 script_conf = configuration_data()
 script_conf.set('GJS', find_program('gjs').path())
 script_conf.set('PACKAGE_VERSION', characters_version)
-script_conf.set('appid', characters_application_id)
+script_conf.set('appid', application_id)
 script_conf.set('libdir', characters_libdir)
 script_conf.set('prefix', characters_prefix)
 
-scripts = [
-  characters_name,
-  characters_background_name
-]
+configure_file(
+    input: 'org.gnome.Characters.in',
+    output: application_id,
+    configuration: script_conf,
+    install: true,
+    install_dir: characters_pkgdatadir
+)
 
-foreach script: scripts
-  configure_file(
-    input: script + '.in',
-    output: '@BASENAME@',
+configure_file(
+    input: 'org.gnome.Characters.BackgroundService.in',
+    output: application_id + '.BackgroundService',
     configuration: script_conf,
     install: true,
     install_dir: characters_pkgdatadir
-  )
-endforeach
+)
 
 common_resource_data = files(
   'util.js'
@@ -32,23 +33,36 @@ resource_data = common_resource_data + files(
   'sidebarRow.js',
   'window.js'
 )
-resources = [[characters_name, resource_data]]
 
 resource_data = common_resource_data + files(
   'searchProvider.js',
   'service.js'
 )
-resources += [[characters_background_name, resource_data]]
+resources_conf = configuration_data()
+resources_conf.set('profile', profile)
 
-foreach resource: resources
-  name = resource[0] + '.src'
+gnome.compile_resources(
+  application_id + '.src',
+  configure_file(
+    input: 'org.gnome.Characters.src.gresource.xml.in',
+    output: '@BASENAME@',
+    configuration: resources_conf
+  ),
+  gresource_bundle: true,
+  dependencies: resource_data,
+  install: true,
+  install_dir: characters_pkgdatadir
+)
 
-  gnome.compile_resources(
-    name,
-    name + '.gresource.xml',
-    gresource_bundle: true,
-    dependencies: resource[1],
-    install: true,
-    install_dir: characters_pkgdatadir
-  )
-endforeach
+gnome.compile_resources(
+  application_id + '.BackgroundService.src',
+  configure_file(
+    input: 'org.gnome.Characters.BackgroundService.src.gresource.xml.in',
+    output: '@BASENAME@',
+    configuration: resources_conf
+  ),
+  gresource_bundle: true,
+  dependencies: resource_data,
+  install: true,
+  install_dir: characters_pkgdatadir
+)
diff --git a/src/org.gnome.Characters.BackgroundService.in b/src/org.gnome.Characters.BackgroundService.in
index 78859da..8f322ff 100755
--- a/src/org.gnome.Characters.BackgroundService.in
+++ b/src/org.gnome.Characters.BackgroundService.in
@@ -1,7 +1,6 @@
 #!@GJS@
-imports.package.init({ name: "org.gnome.Characters",
+imports.package.init({ name: "@appid@",
                        version: "@PACKAGE_VERSION@",
                        prefix: "@prefix@",
                        libdir: "@libdir@" });
-imports.service.applicationId = "@appid@";
 imports.package.run(imports.service);
diff --git a/src/org.gnome.Characters.BackgroundService.src.gresource.xml 
b/src/org.gnome.Characters.BackgroundService.src.gresource.xml.in
similarity index 69%
rename from src/org.gnome.Characters.BackgroundService.src.gresource.xml
rename to src/org.gnome.Characters.BackgroundService.src.gresource.xml.in
index 1541df5..85e0ac8 100644
--- a/src/org.gnome.Characters.BackgroundService.src.gresource.xml
+++ b/src/org.gnome.Characters.BackgroundService.src.gresource.xml.in
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gnome/Characters/BackgroundService/js">
+  <gresource prefix="/org/gnome/Characters@profile@/BackgroundService/js">
     <file>service.js</file>
     <file>searchProvider.js</file>
     <file>util.js</file>
diff --git a/src/org.gnome.Characters.in b/src/org.gnome.Characters.in
index ea9520b..8a57c2a 100755
--- a/src/org.gnome.Characters.in
+++ b/src/org.gnome.Characters.in
@@ -1,7 +1,6 @@
 #!@GJS@
-imports.package.init({ name: "org.gnome.Characters",
+imports.package.init({ name: "@appid@",
                        version: "@PACKAGE_VERSION@",
                        prefix: "@prefix@",
                        libdir: "@libdir@" });
-imports.main.applicationId = "@appid@";
 imports.package.run(imports.main);
diff --git a/src/org.gnome.Characters.src.gresource.xml b/src/org.gnome.Characters.src.gresource.xml.in
similarity index 83%
rename from src/org.gnome.Characters.src.gresource.xml
rename to src/org.gnome.Characters.src.gresource.xml.in
index 17f3ef6..b71d75d 100644
--- a/src/org.gnome.Characters.src.gresource.xml
+++ b/src/org.gnome.Characters.src.gresource.xml.in
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gnome/Characters/js">
+  <gresource prefix="/org/gnome/Characters@profile@/js">
     <file>main.js</file>
     <file>sidebar.js</file>
     <file>sidebarRow.js</file>
diff --git a/src/searchProvider.js b/src/searchProvider.js
index 2ec6634..a9baf02 100644
--- a/src/searchProvider.js
+++ b/src/searchProvider.js
@@ -21,7 +21,6 @@
 const { Gc, Gdk, Gio, GLib, GObject } = imports.gi;
 
 const ByteArray = imports.byteArray;
-const Service = imports.service;
 const Util = imports.util;
 
 const MAX_SEARCH_RESULTS = 100;
@@ -101,7 +100,7 @@ var SearchProvider = GObject.registerClass({
                 name: new GLib.Variant('s', name),
                 id: new GLib.Variant('s', identifiers[i]),
                 description: new GLib.Variant('s', summary),
-                icon: new Gio.ThemedIcon({ name: Service.applicationId }).serialize(),
+                icon: new Gio.ThemedIcon({ name: pkg.name }).serialize(),
                 clipboardText: new GLib.Variant('s', character),
             });
         }
diff --git a/src/service.js b/src/service.js
index be1ff6b..3bcb40a 100644
--- a/src/service.js
+++ b/src/service.js
@@ -32,7 +32,6 @@ const { Gio, GLib, GObject, Gtk } = imports.gi;
 const Util = imports.util;
 const SearchProvider = imports.searchProvider;
 
-var applicationId = pkg.name;
 
 const BackgroundService = GObject.registerClass({
     // This needs to be a Gtk.Application instead of Gio.Application,
@@ -40,7 +39,7 @@ const BackgroundService = GObject.registerClass({
 }, class BackgroundService extends Gtk.Application {
     _init() {
         super._init({
-            application_id: applicationId,
+            application_id: pkg.name,
             flags: Gio.ApplicationFlags.IS_SERVICE,
             inactivity_timeout: 30000,
         });
diff --git a/src/window.js b/src/window.js
index 06c4205..6e72d93 100644
--- a/src/window.js
+++ b/src/window.js
@@ -182,7 +182,7 @@ var MainWindow = GObject.registerClass({
             comments: _('Character Map'),
             copyright: 'Copyright 2014-2018 Daiki Ueno',
             license_type: Gtk.License.GPL_2_0,
-            logo_icon_name: Main.applicationId,
+            logo_icon_name: pkg.name,
             version: pkg.version,
             website: 'https://wiki.gnome.org/Apps/Characters',
             wrap_license: true,
diff --git a/tests/meson.build b/tests/meson.build
index 98a06ec..a575df5 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,5 +1,5 @@
-installed_tests_execdir = join_paths(characters_libexecdir, 'installed-tests', characters_name)
-installed_tests_metadir = join_paths(characters_datadir, 'installed-tests', characters_name)
+installed_tests_execdir = join_paths(characters_libexecdir, 'installed-tests', application_id)
+installed_tests_metadir = join_paths(characters_datadir, 'installed-tests', application_id)
 
 tests = ['smoke_test.py']
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]