[gnome-software: 1/3] Add git commit to version in non-release builds
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 1/3] Add git commit to version in non-release builds
- Date: Fri, 26 Feb 2021 18:40:45 +0000 (UTC)
commit 77749ce84310d43a11c221a16d9ffca65f991eb3
Author: Phaedrus Leeds <mwleeds endlessos org>
Date: Wed Feb 24 16:42:29 2021 -0800
Add git commit to version in non-release builds
This is based on similar functionality in GNOME Builder. Having the git
commit in the version in the About dialog is useful for debugging.
lib/gs-build-ident.h.in | 32 ++++++++++++++++++++++++++++++++
lib/meson.build | 8 +++++++-
meson.build | 1 +
src/gs-application.c | 14 ++++++++++++--
4 files changed, 52 insertions(+), 3 deletions(-)
---
diff --git a/lib/gs-build-ident.h.in b/lib/gs-build-ident.h.in
new file mode 100644
index 000000000..f75627437
--- /dev/null
+++ b/lib/gs-build-ident.h.in
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2021 Matthew Leeds <mwleeds endlessos org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#pragma once
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION:gs-build-ident
+ * @title: Build Identifier
+ * @short_description: Identify a build by unique build identifier
+ *
+ * Since: 41
+ */
+
+/**
+ * GS_BUILD_IDENTIFIER:
+ *
+ * A string containing a tag that defines the version of Software that
+ * was built. Generally, this will be a small version tag plus some
+ * information to identify the git commit hash when applicable.
+ */
+#define GS_BUILD_IDENTIFIER "@VCS_TAG@"
+
+G_END_DECLS
diff --git a/lib/meson.build b/lib/meson.build
index 2c318dfbf..5f203eb82 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -49,6 +49,12 @@ if get_option('polkit')
librarydeps += polkit
endif
+gs_build_ident_h = vcs_tag(
+ fallback: meson.project_version(),
+ input: 'gs-build-ident.h.in',
+ output: 'gs-build-ident.h',
+)
+
libgnomesoftware_enums = gnome.mkenums_simple('gs-enums',
sources : libgnomesoftware_public_headers,
install_header : true,
@@ -79,7 +85,7 @@ libgnomesoftware = static_library(
'gs-plugin-loader-sync.c',
'gs-test.c',
'gs-utils.c',
- ] + libgnomesoftware_enums,
+ ] + libgnomesoftware_enums + [gs_build_ident_h],
include_directories : libgnomesoftware_include_directories,
dependencies : librarydeps,
c_args : cargs,
diff --git a/meson.build b/meson.build
index 2ff2f2575..57afa29af 100644
--- a/meson.build
+++ b/meson.build
@@ -9,6 +9,7 @@ conf = configuration_data()
conf.set_quoted('VERSION', meson.project_version())
conf.set_quoted('PACKAGE_NAME', meson.project_name())
conf.set_quoted('PACKAGE_VERSION', meson.project_version())
+conf.set_quoted('BUILD_TYPE', get_option('buildtype'))
# this refers to the gnome-software plugin API version
# this is not in any way related to a package or soname version
diff --git a/src/gs-application.c b/src/gs-application.c
index a1939ae8b..d2af97f13 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -30,6 +30,7 @@
#include "gs-dbus-helper.h"
#endif
+#include "gs-build-ident.h"
#include "gs-debug.h"
#include "gs-first-run-dialog.h"
#include "gs-shell.h"
@@ -72,6 +73,15 @@ enum {
static guint signals[LAST_SIGNAL];
+static const char *
+get_version (void)
+{
+ if (g_strcmp0 (BUILD_TYPE, "release") == 0)
+ return VERSION;
+ else
+ return GS_BUILD_IDENTIFIER;
+}
+
typedef struct {
GsApplication *app;
GSimpleAction *action;
@@ -342,7 +352,7 @@ about_activated (GSimpleAction *action,
gtk_about_dialog_set_license_type (dialog, GTK_LICENSE_GPL_2_0);
gtk_about_dialog_set_logo_icon_name (dialog, "org.gnome.Software");
gtk_about_dialog_set_translator_credits (dialog, _("translator-credits"));
- gtk_about_dialog_set_version (dialog, VERSION);
+ gtk_about_dialog_set_version (dialog, get_version());
gtk_about_dialog_set_program_name (dialog, g_get_application_name ());
/* TRANSLATORS: this is the title of the about window */
@@ -1129,7 +1139,7 @@ gs_application_handle_local_options (GApplication *app, GVariantDict *options)
g_setenv ("GNOME_SOFTWARE_PREFER_LOCAL", "true", TRUE);
if (g_variant_dict_contains (options, "version")) {
- g_print ("gnome-software " VERSION "\n");
+ g_print ("gnome-software %s\n", get_version());
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]