[swell-foop/wip/inigomartinez/meson: 2/5] meson: Change config.h handling
- From: Iñigo Martínez <inigomartinez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [swell-foop/wip/inigomartinez/meson: 2/5] meson: Change config.h handling
- Date: Thu, 15 Mar 2018 08:44:39 +0000 (UTC)
commit efd2faa017e80cdda1e82f5eab29de902cc8de45
Author: Iñigo Martínez <inigomartinez gmail com>
Date: Sat Feb 10 15:30:07 2018 +0100
meson: Change config.h handling
The `config.h` file handling, which is done through the
`config.vapi` file, has been changed following Vala
recommendations[0].
To do this, the global variables in the `config.vapi` file has been
moved to the `Config` namespace.
The `DATADIR` and `LOCALEDIR` variables, although they still exist
in the `config.vapi` file, they are not set in the `config.h` file
because they will be set by the compiler's macro definitions when
using compiler flags.
https://bugzilla.gnome.org/show_bug.cgi?id=793340
[0] https://wiki.gnome.org/Projects/Vala/GameDevelopmentSeries/Setup
meson.build | 2 --
src/config.vapi | 11 +++++++----
src/game-view.vala | 6 ++++--
src/meson.build | 9 ++++-----
src/swell-foop.vala | 16 +++++++++-------
5 files changed, 24 insertions(+), 20 deletions(-)
---
diff --git a/meson.build b/meson.build
index 6264249..4c93d23 100644
--- a/meson.build
+++ b/meson.build
@@ -35,8 +35,6 @@ posix_dep = valac.find_library('posix')
conf = configuration_data()
conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
-conf.set_quoted('LOCALEDIR', localedir)
-conf.set_quoted('DATADIR', pkgdatadir)
conf.set_quoted('VERSION', meson.project_version())
config_h_inc = include_directories('.')
diff --git a/src/config.vapi b/src/config.vapi
index a527e17..705a1fb 100644
--- a/src/config.vapi
+++ b/src/config.vapi
@@ -8,7 +8,10 @@
* license.
*/
-public const string DATADIR;
-public const string LOCALEDIR;
-public const string GETTEXT_PACKAGE;
-public const string VERSION;
+[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
+namespace Config {
+ public const string DATADIR;
+ public const string GETTEXT_PACKAGE;
+ public const string LOCALEDIR;
+ public const string VERSION;
+}
diff --git a/src/game-view.vala b/src/game-view.vala
index b14bf4a..a4c1b0b 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -15,6 +15,8 @@
* events.
*/
+using Config;
+
public class GameView : Clutter.Group
{
private TileActor highlighted = null;
@@ -358,12 +360,12 @@ public class Theme : Object
try
{
for (int i = 0; i < 4; i++) {
- var pixbuf = new Gdk.Pixbuf.from_file (Path.build_filename (DATADIR, "themes", name,
colors[i] + ".svg"));
+ var pixbuf = new Gdk.Pixbuf.from_file (Path.build_filename (Config.DATADIR, "themes", name,
colors[i] + ".svg"));
textures[i] = new Clutter.Image ();
textures[i].set_data (pixbuf.get_pixels (), Cogl.PixelFormat.RGBA_8888,
pixbuf.get_width (), pixbuf.get_height (), pixbuf.get_rowstride ());
}
- var pixbuf = new Gdk.Pixbuf.from_file (Path.build_filename (DATADIR, "themes", name,
"highlight.svg"));
+ var pixbuf = new Gdk.Pixbuf.from_file (Path.build_filename (Config.DATADIR, "themes", name,
"highlight.svg"));
cursor = new Clutter.Image ();
cursor.set_data (pixbuf.get_pixels (), Cogl.PixelFormat.RGBA_8888,
pixbuf.get_width (), pixbuf.get_height (), pixbuf.get_rowstride ());
diff --git a/src/meson.build b/src/meson.build
index d1ab2b9..2547bb1 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -18,11 +18,10 @@ deps = [
clutter_gtk_dep,
]
-c_flags = [
- '-DVERSION="@0@"'.format (meson.project_version ()),
- '-DGETTEXT_PACKAGE="@0@"'.format (meson.project_name()),
- '-DLOCALEDIR="@0@"'.format (localedir),
- '-DDATADIR="@0@"'.format (pkgdatadir),
+c_flags = [
+ '-DDATADIR="@0@"'.format(pkgdatadir),
+ '-DLOCALEDIR="@0@"'.format(localedir),
+ '-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name())
]
executable('swell-foop', sources,
diff --git a/src/swell-foop.vala b/src/swell-foop.vala
index b7d64fe..bab49a5 100644
--- a/src/swell-foop.vala
+++ b/src/swell-foop.vala
@@ -8,6 +8,8 @@
* license.
*/
+using Config;
+
public class SwellFoop : Gtk.Application
{
/* Application settings */
@@ -56,7 +58,7 @@ public class SwellFoop : Gtk.Application
private void load_css ()
{
var css_provider = new Gtk.CssProvider ();
- var css_path = Path.build_filename (DATADIR, "swell-foop.css");
+ var css_path = Path.build_filename (Config.DATADIR, "swell-foop.css");
try
{
css_provider.load_from_path (css_path);
@@ -301,7 +303,7 @@ public class SwellFoop : Gtk.Application
var preferences_builder = new Gtk.Builder ();
try
{
- preferences_builder.add_from_file (Path.build_filename (DATADIR, "preferences.ui", null));
+ preferences_builder.add_from_file (Path.build_filename (Config.DATADIR, "preferences.ui", null));
}
catch (Error e)
{
@@ -453,7 +455,7 @@ public class SwellFoop : Gtk.Application
Gtk.show_about_dialog (window,
"program-name", _("Swell Foop"),
- "version", VERSION,
+ "version", Config.VERSION,
"comments",
_("I want to play that game!\nYou know, they all light-up and you click on
them and they vanish!"),
"copyright", _("Copyright \xc2\xa9 2009 Tim Horton"),
@@ -508,9 +510,9 @@ public class SwellFoop : Gtk.Application
public static int main (string[] args)
{
Intl.setlocale (LocaleCategory.ALL, "");
- Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
- Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- Intl.textdomain (GETTEXT_PACKAGE);
+ Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
+ Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
+ Intl.textdomain (Config.GETTEXT_PACKAGE);
if (GtkClutter.init (ref args) != Clutter.InitError.SUCCESS)
{
@@ -519,7 +521,7 @@ public class SwellFoop : Gtk.Application
}
var context = new OptionContext (null);
- context.set_translation_domain (GETTEXT_PACKAGE);
+ context.set_translation_domain (Config.GETTEXT_PACKAGE);
context.add_group (Gtk.get_option_group (true));
context.add_group (Clutter.get_option_group_without_init ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]