[gtranslator/commit-about] Show commit hash in about dialog in development




commit b597d13c517b1ca7a2f24ce643ac77f1a51512ce
Author: Daniel GarcĂ­a Moreno <dani danigm net>
Date:   Mon Apr 5 13:58:53 2021 +0200

    Show commit hash in about dialog in development
    
    This patch adds the git commit hash to the about dialog when building in
    development mode so it's easy to detect the exact version for nightly
    builds.
    
    Fix https://gitlab.gnome.org/GNOME/gtranslator/-/issues/126

 build-aux/flatpak/org.gnome.Gtranslator.json |  3 +++
 meson.build                                  |  1 +
 meson_options.txt                            |  9 +++++++++
 src/gtr-actions-app.c                        | 13 +++++++++++--
 src/gtr-build-ident.h.in                     | 24 ++++++++++++++++++++++++
 src/meson.build                              |  8 +++++++-
 6 files changed, 55 insertions(+), 3 deletions(-)
---
diff --git a/build-aux/flatpak/org.gnome.Gtranslator.json b/build-aux/flatpak/org.gnome.Gtranslator.json
index b726a69e..fc37791a 100644
--- a/build-aux/flatpak/org.gnome.Gtranslator.json
+++ b/build-aux/flatpak/org.gnome.Gtranslator.json
@@ -128,6 +128,9 @@
         {
             "name" : "gtranslator",
             "buildsystem" : "meson",
+            "config-opts": [
+                "-Dprofile=development"
+            ],
             "sources" : [
                 {
                     "type" : "git",
diff --git a/meson.build b/meson.build
index 021ac296..f304eee6 100644
--- a/meson.build
+++ b/meson.build
@@ -61,6 +61,7 @@ set_defines = [
   ['PACKAGE_URL', 'https://wiki.gnome.org/Apps/Gtranslator'],
   ['PACKAGE_VERSION', gtr_version],
   ['PACKAGE_APPID', gtr_app_id],
+  ['PROFILE', get_option('profile')],
   # i18
   ['GETTEXT_PACKAGE', meson.project_name()],
 ]
diff --git a/meson_options.txt b/meson_options.txt
index 658725e8..80f18fb6 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1 +1,10 @@
 option('gtk_doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation')
+option (
+  'profile',
+  type: 'combo',
+  choices: [
+    'default',
+    'development'
+  ],
+  value: 'default'
+)
diff --git a/src/gtr-actions-app.c b/src/gtr-actions-app.c
index 0f060655..4d2c251b 100644
--- a/src/gtr-actions-app.c
+++ b/src/gtr-actions-app.c
@@ -27,6 +27,7 @@
 #include "gtr-dirs.h"
 #include "gtr-utils.h"
 #include "gtr-window.h"
+#include "gtr-build-ident.h"
 
 #include <glib.h>
 #include <glib/gi18n.h>
@@ -40,6 +41,15 @@ gtr_show_help (GtkWindow *window)
   gtr_utils_help_display (GTK_WINDOW (window));
 }
 
+static const char *
+get_version (void)
+{
+  if (g_strcmp0 (PROFILE, "development") == 0)
+    return GTR_BUILD_IDENTIFIER;
+  else
+    return PACKAGE_VERSION;
+}
+
 /* Creates and shows the about box for gtranslator */
 void
 gtr_about_dialog (GtrWindow *window)
@@ -99,9 +109,8 @@ gtr_about_dialog (GtrWindow *window)
                           * up in the "about" box
                           */
                          "translator-credits", _("translator-credits"),
-                         "version", PACKAGE_VERSION,
+                         "version", get_version (),
                          "website", PACKAGE_URL,
                          "website-label", _("Translation Editor Web Site"),
                          NULL);
-
 }
diff --git a/src/gtr-build-ident.h.in b/src/gtr-build-ident.h.in
new file mode 100644
index 00000000..0b55aeb2
--- /dev/null
+++ b/src/gtr-build-ident.h.in
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION:gtr-build-ident
+ * @title: Build Identifier
+ * @short_description: Identify a build by unique build identifier
+ *
+ * Since: 41
+ */
+
+/**
+ * GTR_BUILD_IDENTIFIER:
+ *
+ * A string containing a tag that defines the version of Gtranslator that
+ * was built. Generally, this will be a small version tag plus some
+ * information to identify the git commit hash when applicable.
+ */
+#define GTR_BUILD_IDENTIFIER "@VCS_TAG@"
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index e2f0ac83..c4d7216b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -3,6 +3,12 @@ src_inc = include_directories('.')
 subdir('translation-memory')
 subdir('codeview')
 
+gtr_build_ident_h = vcs_tag(
+     fallback: meson.project_version(),
+        input: 'gtr-build-ident.h.in',
+       output: 'gtr-build-ident.h',
+)
+
 enum_headers = files(
   'gtr-application.h',
   'gtr-context.h',
@@ -127,7 +133,7 @@ incs = [
 
 libgtranslator = shared_library(
   meson.project_name(),
-  sources: sources + translation_mem_sources + codeview_sources,
+  sources: sources + translation_mem_sources + codeview_sources + [gtr_build_ident_h],
   include_directories: incs,
   dependencies: gtr_deps,
 )


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