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

And use it in several location in the code for consistent behaviour
This commit is contained in:
Geert Janssens 2019-02-21 17:00:15 +01:00
parent b53d5c65e0
commit fce75ea748
9 changed files with 146 additions and 75 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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,

View File

@ -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);

View File

@ -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);
format_string = _("GnuCash %s");
#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)
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);
}

View File

@ -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}

View File

@ -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);

View File

@ -0,0 +1,68 @@
/********************************************************************\
* gnc-version.cpp -- functions to query the build-time version info *
* *
* Copyright (C) 2019 Geert Janssens <geert@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@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;
}

View File

@ -0,0 +1,56 @@
/********************************************************************\
* gnc-version.h -- functions to query the build-time version info *
* *
* Copyright (C) 2019 Geert Janssens <geert@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@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@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 */
/** @} */
/** @} */

View File

@ -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