gnucash maint: Add dedicated api to query build-time, version related compile constants

Geert Janssens gjanssens at code.gnucash.org
Thu Feb 21 11:00:22 EST 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/fce75ea7 (commit)
	from  https://github.com/Gnucash/gnucash/commit/b53d5c65 (commit)



commit fce75ea7481a6738ab88b459f8998a584ba75800
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Thu Feb 21 17:00:15 2019 +0100

    Add dedicated api to query build-time, version related compile constants
    
    And use it in several location in the code for consistent behaviour

diff --git a/.gitignore b/.gitignore
index b74a6cfa8..e669208f3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -124,7 +124,6 @@ libgnucash/backend/xml/test/test-xml-pricedb
 libgnucash/backend/xml/test/test-xml-transaction
 libgnucash/backend/xml/test/test-xml2-is-file
 libgnucash/core-utils/gnc-vcs-info.h
-libgnucash/core-utils/gnc-version.h
 libgnucash/core-utils/gncla-dir.h
 libgnucash/core-utils/gnucash
 libgnucash/core-utils/sw_core_utils.py
diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c
index 921e1b680..44e595010 100644
--- a/gnucash/gnome-utils/gnc-main-window.c
+++ b/gnucash/gnome-utils/gnc-main-window.c
@@ -4535,31 +4535,18 @@ gnc_main_window_cmd_help_about (GtkAction *action, GncMainWindow *window)
         gchar **authors = get_file_strsplit("AUTHORS");
         gchar **documenters = get_file_strsplit("DOCUMENTERS");
         gchar *license = get_file("LICENSE");
-        gchar *version = NULL;
-        gchar *vcs = NULL;
         GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
         GdkPixbuf *logo = gtk_icon_theme_load_icon (icon_theme,
                                                     GNC_ICON_APP,
                                                     128,
                                                     GTK_ICON_LOOKUP_USE_BUILTIN,
                                                     NULL);
-
-#ifdef GNC_VCS
-        vcs = GNC_VCS " ";
-#else
-        vcs = "";
-#endif
-
-        /* Allow builder to override the build id (eg distributions may want to
-         * print an package source version number (rpm, dpkg,...) instead of our git ref */
-        if (g_strcmp0("", GNUCASH_BUILD_ID) != 0)
-            version = g_strdup_printf ("%s: %s\n%s: %s\nFinance::Quote: %s", _("Version"), VERSION,
-                                       _("Build ID"), GNUCASH_BUILD_ID,
-                                       gnc_quote_source_fq_version () ? gnc_quote_source_fq_version () : "-");
-        else
-            version = g_strdup_printf ("%s: %s\n%s: %s%s (%s)\nFinance::Quote: %s", _("Version"), VERSION,
-                                       _("Build ID"), vcs, GNC_VCS_REV, GNC_VCS_REV_DATE,
-                                       gnc_quote_source_fq_version () ? gnc_quote_source_fq_version () : "-");
+        gchar *version = g_strdup_printf ("%s: %s\n%s: %s\nFinance::Quote: %s",
+                                          _("Version"), gnc_version(),
+                                          _("Build ID"), gnc_build_id(),
+                                          gnc_quote_source_fq_version ()
+                                           ? gnc_quote_source_fq_version ()
+                                           : "-");
         priv->about_dialog = gtk_about_dialog_new ();
         g_object_set (priv->about_dialog,
                   "authors", authors,
diff --git a/gnucash/gnome-utils/gnc-splash.c b/gnucash/gnome-utils/gnc-splash.c
index 661bf4876..9ea7b20e1 100644
--- a/gnucash/gnome-utils/gnc-splash.c
+++ b/gnucash/gnome-utils/gnc-splash.c
@@ -60,7 +60,7 @@ gnc_show_splash_screen (void)
     GtkWidget *hbox;
     GtkWidget *version;
     GtkWidget *separator;
-    gchar *ver_string, *markup, *vcs;
+    gchar *ver_string, *markup;
 
     if (splash) return;
     if (!gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SHOW_SPLASH)) return;
@@ -94,22 +94,8 @@ gnc_show_splash_screen (void)
     hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
     gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
 
-#ifdef GNC_VCS
-    vcs = GNC_VCS " ";
-#else
-    vcs = "";
-#endif
-
-    /* Allow builder to override the build id (eg distributions may want to
-     * print an package source version number (rpm, dpkg,...) instead of our git ref */
-    if (g_strcmp0("", GNUCASH_BUILD_ID) != 0)
-        ver_string = g_strdup_printf("%s: %s, %s: %s", _("Version"),
-                                     VERSION, _("Build ID"), GNUCASH_BUILD_ID);
-    else
-        ver_string = g_strdup_printf("%s: %s, %s: %s%s (%s)", _("Version"),
-                                     VERSION, _("Build ID"), vcs, GNC_VCS_REV,
-                                     GNC_VCS_REV_DATE);
-
+    ver_string = g_strdup_printf ("%s: %s, %s: %s", _("Version"),
+                                  gnc_version(), _("Build ID"), gnc_build_id());
     version = gtk_label_new(NULL);
     markup = g_markup_printf_escaped(MARKUP_STRING, ver_string);
     gtk_label_set_markup(GTK_LABEL(version), markup);
diff --git a/gnucash/gnucash-bin.c b/gnucash/gnucash-bin.c
index bfd135e3f..16cc3ef7d 100644
--- a/gnucash/gnucash-bin.c
+++ b/gnucash/gnucash-bin.c
@@ -445,27 +445,14 @@ gnc_parse_command_line(int *argc, char ***argv)
     g_option_context_free (context);
     if (gnucash_show_version)
     {
-        gchar *vcs;
-
+        const char *format_string;
         if (is_development_version)
-            g_print (_("GnuCash %s development version"), VERSION);
+            format_string = _("GnuCash %s development version");
         else
-            g_print (_("GnuCash %s"), VERSION);
-
-#ifdef GNC_VCS
-        vcs = GNC_VCS " ";
-#else
-        vcs = "";
-#endif
+            format_string = _("GnuCash %s");
 
-        /* Allow builder to override the build id (eg distributions may want to
-         * print an package source version number (rpm, dpkg,...) instead of our git ref */
-        if (g_strcmp0("", GNUCASH_BUILD_ID) != 0)
-            g_print ("\n%s: %s\n",
-                     _("Build ID"), GNUCASH_BUILD_ID);
-        else
-            g_print ("\n%s: %s%s (%s)\n",
-                     _("Build ID"), vcs, GNC_VCS_REV, GNC_VCS_REV_DATE);
+        g_print (format_string, gnc_version());
+        g_print ("\n%s: %s\n", _("Build ID"), gnc_build_id());
         exit(0);
     }
 
diff --git a/libgnucash/core-utils/CMakeLists.txt b/libgnucash/core-utils/CMakeLists.txt
index 6d02f4869..a84be486b 100644
--- a/libgnucash/core-utils/CMakeLists.txt
+++ b/libgnucash/core-utils/CMakeLists.txt
@@ -27,6 +27,7 @@ set (core_utils_SOURCES
   gnc-locale-utils.c
   gnc-locale-utils.cpp
   gnc-path.c
+  gnc-version.c
 )
 
 # Add dependency on config.h
@@ -40,20 +41,6 @@ set(sysconfdir ${CMAKE_INSTALL_FULL_SYSCONFDIR})
 set(localedir "${CMAKE_INSTALL_FULL_DATAROOTDIR}/locale")
 configure_file(gncla-dir.h.in gncla-dir.h)
 
-### Create gnc-version.h ###
-
-set (GNC_VERSION_H_IN
-"/* Autogenerated. Do not change. */
-#ifndef GNC_VERSION_H
-#define GNC_VERSION_H
-
-#include \"gnc-vcs-info.h\"
-#endif
-")
-
-string(CONFIGURE ${GNC_VERSION_H_IN} GNC_VERSION_H_CONTENT)
-file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/gnc-version.h ${GNC_VERSION_H_CONTENT})
-
 ### Create gnc-vcs-info.h
 # This can only be done when building from a vcs (git/svn/bzr/svk) working directory.
 # This file is shipped in the distribution tarball, so no need to generate it in that case anyway.
@@ -119,6 +106,7 @@ set(core_utils_noinst_HEADERS
   gnc-locale-utils.h
   gnc-locale-utils.hpp
   gnc-path.h
+  gnc-version.h
 )
 
 set(core_utils_ALL_SOURCES ${core_utils_SOURCES} ${core_utils_noinst_HEADERS})
@@ -152,6 +140,9 @@ target_include_directories(gnc-core-utils PUBLIC ${core_utils_ALL_INCLUDES})
 if (MAC_INTEGRATION)
   target_compile_options(gnc-core-utils PRIVATE ${OSX_EXTRA_COMPILE_FLAGS})
 endif(MAC_INTEGRATION)
+if (BUILDING_FROM_VCS)
+  target_compile_definitions(gnc-core-utils PRIVATE -DGNC_VCS=\"git\")
+endif (BUILDING_FROM_VCS)
 
 install(TARGETS gnc-core-utils
   LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
diff --git a/libgnucash/core-utils/core-utils.i b/libgnucash/core-utils/core-utils.i
index d8fd67df4..63a108a09 100644
--- a/libgnucash/core-utils/core-utils.i
+++ b/libgnucash/core-utils/core-utils.i
@@ -28,7 +28,7 @@
 #include <gnc-filepath-utils.h>
 #include <gnc-locale-utils.h>
 #include <glib.h>
-const gchar *gnc_version(void);
+#include <gnc-version.h>
 %}
 #if defined(SWIGGUILE)
 %{
@@ -51,10 +51,7 @@ void
 
 %include <gnc-environment.h>
 %include <gnc-prefs.h>
-%inline %{
-const gchar *gnc_version(void)
-{ return VERSION; }
-%}
+%include <gnc-version.h>
 
 %newobject gnc_path_get_bindir;
 gchar * gnc_path_get_bindir(void);
diff --git a/libgnucash/core-utils/gnc-version.c b/libgnucash/core-utils/gnc-version.c
new file mode 100644
index 000000000..eaa93c5b3
--- /dev/null
+++ b/libgnucash/core-utils/gnc-version.c
@@ -0,0 +1,68 @@
+/********************************************************************\
+ * gnc-version.cpp -- functions to query the build-time version info  *
+ *                                                                  *
+ * Copyright (C) 2019 Geert Janssens <geert at kobaltwit.be>           *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+ ********************************************************************/
+
+#include "gnc-version.h"
+#include <config.h>
+
+#ifdef GNC_VCS
+    #define vcs GNC_VCS " "
+#else
+    #define vcs ""
+#endif
+#define dflt_build_id vcs GNC_VCS_REV "(" GNC_VCS_REV_DATE ")"
+
+const char *gnc_version(void)
+{
+    return VERSION;
+}
+
+const char *gnc_build_id(void)
+{
+    /* GNUCASH_BUILD_ID can be set by the builder prior to compiling to anything
+     * the builder sees fit (eg distributions may want to print a package source
+     * version number (rpm, dpkg,...)
+     * If not set by a builder it will be set by default to our
+     * git revision ("git706a3b (<commit-date>)"
+     */
+    if (GNUCASH_BUILD_ID[0] != '\0')
+        return GNUCASH_BUILD_ID;
+    else
+        return dflt_build_id;
+
+}
+
+const char *gnc_vcs_rev(void)
+{
+    return GNC_VCS_REV;
+}
+
+const char *gnc_vcs_rev_date(void)
+{
+    return GNC_VCS_REV_DATE;
+}
+
+const int gnc_gnucash_major_version(void)
+{
+    return GNUCASH_MAJOR_VERSION;
+}
diff --git a/libgnucash/core-utils/gnc-version.h b/libgnucash/core-utils/gnc-version.h
new file mode 100644
index 000000000..f3d6fee90
--- /dev/null
+++ b/libgnucash/core-utils/gnc-version.h
@@ -0,0 +1,56 @@
+/********************************************************************\
+ * gnc-version.h -- functions to query the build-time version info  *
+ *                                                                  *
+ * Copyright (C) 2019 Geert Janssens <geert at kobaltwit.be>           *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+ ********************************************************************/
+
+/** @addtogroup Utils
+    @{ */
+/** @addtogroup GncVersion Version Information
+
+    The functions in this file allow you to query various version related
+    strings that were set at build time..
+
+    @{ */
+/** @file gnc-version.h
+ *  @brief functions to query various version related strings that were set at build time.
+ *  @author Copyright (C) 2018 Geert Janssens <geert at kobaltwit.be>
+ */
+
+#ifndef GNC_VERSION_H
+#define GNC_VERSION_H
+#include "gnc-vcs-info.h"
+
+/** Parse <prefix>/etc/gnucash/environment and set environment variables
+ *  based on the contents of that file. Read the comments in
+ *  <prefix>/etc/gnucash/environment for more details.
+ */
+
+const char *gnc_version(void);
+const char *gnc_build_id(void);
+const char *gnc_vcs_rev(void);
+const char *gnc_vcs_rev_date(void);
+const int gnc_gnucash_major_version(void);
+
+#endif /* GNC_VERSION_H */
+
+/** @} */
+/** @} */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e8c56acf3..674b75b6f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -509,7 +509,6 @@ libgnucash/app-utils/business-prefs.scm
 libgnucash/app-utils/calculation/expression_parser.c
 libgnucash/app-utils/calculation/fin.c
 libgnucash/app-utils/c-interface.scm
-libgnucash/app-utils/config-var.scm
 libgnucash/app-utils/date-utilities.scm
 libgnucash/app-utils/file-utils.c
 libgnucash/app-utils/fin.scm
@@ -616,6 +615,7 @@ libgnucash/core-utils/gnc-locale-utils.c
 libgnucash/core-utils/gnc-locale-utils.cpp
 libgnucash/core-utils/gnc-path.c
 libgnucash/core-utils/gnc-prefs.c
+libgnucash/core-utils/gnc-version.c
 libgnucash/doc/doxygen_main_page.c
 libgnucash/engine/Account.cpp
 libgnucash/engine/business-core.scm



Summary of changes:
 .gitignore                                         |  1 -
 gnucash/gnome-utils/gnc-main-window.c              | 25 ++-------
 gnucash/gnome-utils/gnc-splash.c                   | 20 +------
 gnucash/gnucash-bin.c                              | 23 ++------
 libgnucash/core-utils/CMakeLists.txt               | 19 ++-----
 libgnucash/core-utils/core-utils.i                 |  7 +--
 .../io-gncxml-gen.cpp => core-utils/gnc-version.c} | 65 ++++++++++++----------
 .../{gnc-environment.h => gnc-version.h}           | 40 +++++++------
 po/POTFILES.in                                     |  2 +-
 9 files changed, 77 insertions(+), 125 deletions(-)
 copy libgnucash/{backend/xml/io-gncxml-gen.cpp => core-utils/gnc-version.c} (57%)
 copy libgnucash/core-utils/{gnc-environment.h => gnc-version.h} (61%)



More information about the gnucash-changes mailing list