[gnome-news/wip/jfelder/meson-support: 5/5] build: Add meson support



commit ba0c5b86d21ee29eaa46348efec3327ac1810e75
Author: Jean Felder <jean felder gmail com>
Date:   Fri Jan 11 22:21:30 2019 +0100

    build: Add meson support
    
    Closes: #3

 data/meson.build      | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
 gnome-news.in         |  7 +++--
 meson.build           | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++
 meson_post_conf.py    | 12 ++++++++
 meson_post_install.py | 21 ++++++++++++++
 po/meson.build        |  1 +
 6 files changed, 187 insertions(+), 3 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
new file mode 100644
index 0000000..090f461
--- /dev/null
+++ b/data/meson.build
@@ -0,0 +1,73 @@
+# Compiling the resources
+gnome.compile_resources(
+  PROJECT_RDNN_NAME,
+  PROJECT_RDNN_NAME + '.gresource.xml',
+  gresource_bundle: true,
+  source_dir: meson.current_build_dir(),
+  install_dir: PKGDATA_DIR,
+  install: true
+)
+
+# Installing the schema file
+install_data(
+  'org.gnome.News.gschema.xml',
+  install_dir: 'share/glib-2.0/schemas'
+)
+
+# Merging the translations with the desktop file
+i18n.merge_file(
+  type: 'desktop',
+  input:  APPLICATION_ID + '.desktop.in',
+  output: APPLICATION_ID + '.desktop',
+  po_dir: join_paths(meson.source_root(), 'po'),
+  install: true,
+  install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'applications')
+)
+
+# Validating the desktop file
+desktop_file_validate = find_program('desktop-file-validate', required:false)
+if desktop_file_validate.found()
+  test (
+    'Validate desktop file',
+    desktop_file_validate,
+    args: join_paths(meson.current_build_dir (), APPLICATION_ID + '.desktop')
+  )
+endif
+
+# Merging the translations with the appdata file
+i18n.merge_file(
+  'appdata',
+  input: APPLICATION_ID +  '.appdata.xml.in',
+  output: APPLICATION_ID + '.appdata.xml',
+  po_dir: join_paths(meson.source_root(), 'po'),
+  install: true,
+  install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'metainfo')
+)
+
+# Validating the appdata file
+appstreamcli = find_program(['appstreamcli', 'appstream-util'], required: false)
+if appstreamcli.found()
+  test (
+    'Validate appdata file',
+    appstreamcli,
+    args: ['validate', join_paths(meson.current_build_dir (), APPLICATION_ID + '.appdata.xml')]
+  )
+endif
+
+# # Installing the icons
+# icon_sizes = ['scalable']
+
+# foreach i : icon_sizes
+#   install_data(
+#     join_paths('icons/hicolor', i , 'apps', PROJECT_RDNN_NAME + '.svg'),
+#     install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'icons', 'hicolor', i , 'apps'),
+#     rename: '@0@.svg'.format(APPLICATION_ID)
+#   )
+# endforeach
+
+# Installing the symbolic icon
+# install_data(
+#     join_paths('icons/hicolor/symbolic/apps', PROJECT_RDNN_NAME + '-symbolic.svg'),
+#     install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'icons/hicolor/symbolic/apps'),
+#     rename: '@0 -symbolic svg'.format(APPLICATION_ID)
+# )
diff --git a/gnome-news.in b/gnome-news.in
index f5555ae..8759e39 100755
--- a/gnome-news.in
+++ b/gnome-news.in
@@ -31,14 +31,14 @@ from gi.repository import Gio
 import gnomenews
 
 localedir = "@localedir@"
+pkgdatadir = "@pkgdatadir@"
+
 srcdir = os.path.abspath(os.path.join(os.path.dirname(gnomenews.__file__), ".."))
 if os.path.exists(os.path.join(srcdir, "gnome-news.doap")):
     print("Running from source tree, using local files")
-    pkgdatadir = os.path.join(srcdir, "data")
     if not os.environ.get("GSETTINGS_SCHEMA_DIR"):
         os.environ["GSETTINGS_SCHEMA_DIR"] = pkgdatadir
-else:
-    pkgdatadir = "@pkgdatadir@"
+    os.environ["XDG_DATA_DIRS"] = '@schemasdir@:' + os.environ.get("XDG_DATA_DIRS", "")
 
 def install_excepthook():
     """ Make sure we exit when an unhandled exception occurs. """
@@ -53,6 +53,7 @@ def install_excepthook():
     sys.excepthook = new_hook
 
 if __name__ == "__main__":
+
     install_excepthook()
 
     parser = argparse.ArgumentParser()
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..6606726
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,76 @@
+project('gnome-news',
+    version: '0.0.1',
+    meson_version: '>= 0.46.0'
+)
+
+# Importing modules
+gnome = import('gnome')
+i18n  = import('i18n')
+python = import('python')
+
+# Module objects
+py_installation = python.find_installation('python3')
+
+# Make sure Python is installed and found
+if not py_installation.found()
+    error('No valid python3 binary found')
+endif
+
+# Constants
+PROJECT_RDNN_NAME = 'gnome-news'
+APPLICATION_ID = 'org.gnome.News'
+PYTHON_DIR = py_installation.get_path('purelib')
+PKGDATA_DIR = join_paths(get_option('prefix'), get_option('datadir'), APPLICATION_ID)
+PKGLIB_DIR = join_paths(get_option('prefix'), get_option('libdir'), APPLICATION_ID)
+
+# Dependencies
+dependency('goa-1.0')
+dependency('gobject-introspection-1.0', version: '>= 1.35.0')
+dependency('gtk+-3.0', version: '>= 3.23.1')
+dependency('tracker-sparql-2.0', version: '>= 1.99.1')
+dependency('pygobject-3.0', version: '>= 3.29.1')
+dependency('py3cairo', version: '>= 1.14.0')
+
+subdir('data')
+subdir('po')
+
+install_subdir(
+    'gnomenews',
+    install_dir: py_installation.get_install_dir()
+)
+
+# Install the executable file
+bin_config = configuration_data()
+bin_config.set('application_id', APPLICATION_ID)
+bin_config.set('rdnn_name', PROJECT_RDNN_NAME)
+bin_config.set('pkgdatadir', PKGDATA_DIR)
+bin_config.set('localedir', join_paths(get_option('prefix'), get_option('datadir'), 'locale'))
+bin_config.set('pythondir', PYTHON_DIR)
+bin_config.set('pyexecdir', py_installation.get_path('stdlib'))
+bin_config.set('schemasdir', '')
+bin_config.set('version', meson.project_version())
+
+configure_file(
+    input: 'gnome-news.in',
+    output: 'gnome-news',
+    configuration: bin_config,
+    install_dir: get_option('bindir')
+)
+
+# Install the builddir executable
+local_config = configuration_data()
+local_config.set('pkgdatadir', join_paths(meson.build_root(), 'data'))
+local_config.set('localedir', join_paths(get_option('prefix'), get_option('datadir'), 'locale'))
+local_config.set('pythondir', meson.source_root())
+local_config.set('pyexecdir', meson.source_root())
+local_config.set('schemasdir', join_paths(meson.build_root(), 'data'))
+local_config.set('version', meson.project_version())
+
+configure_file(
+    input: 'gnome-news.in',
+    output: 'local-news',
+    configuration: local_config
+)
+
+meson.add_postconf_script('meson_post_conf.py')
+meson.add_install_script('meson_post_install.py')
diff --git a/meson_post_conf.py b/meson_post_conf.py
new file mode 100755
index 0000000..a5c2105
--- /dev/null
+++ b/meson_post_conf.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python3
+
+import os
+import subprocess
+
+build_root = os.environ.get('MESON_BUILD_ROOT')
+source_root = os.environ.get('MESON_SOURCE_ROOT')
+
+print('Install schemas in build dir...')
+subprocess.call(['glib-compile-schemas', source_root + '/data/'])
+subprocess.call(['mkdir', '-p', build_root + '/data/glib-2.0/schemas'])
+subprocess.call(['mv', source_root + '/data/gschemas.compiled', build_root + '/data/glib-2.0/schemas'])
diff --git a/meson_post_install.py b/meson_post_install.py
new file mode 100755
index 0000000..4c3a2b7
--- /dev/null
+++ b/meson_post_install.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+import os
+import subprocess
+
+prefix = os.environ.get('MESON_INSTALL_PREFIX', '/usr/local')
+datadir = os.path.join(prefix, 'share')
+
+# Packaging tools define DESTDIR and this isn't needed for them
+if 'DESTDIR' not in os.environ:
+    print('Updating icon cache...')
+    icon_cache_dir = os.path.join(datadir, 'icons', 'hicolor')
+    subprocess.call(['gtk-update-icon-cache', '-qtf', icon_cache_dir])
+
+    print("Compiling the schema...")
+    schemas_dir = os.path.join(datadir, 'glib-2.0/schemas')
+    subprocess.call(['glib-compile-schemas', schemas_dir])
+
+    print('Updating desktop database...')
+    desktop_database_dir = os.path.join(datadir, 'applications')
+    subprocess.call(['update-desktop-database', '-q', desktop_database_dir])
diff --git a/po/meson.build b/po/meson.build
new file mode 100644
index 0000000..da86d01
--- /dev/null
+++ b/po/meson.build
@@ -0,0 +1 @@
+i18n.gettext(APPLICATION_ID, preset:'glib')


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