[vala/staging] vala: Add consts/methods to retrieve and check library version
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Add consts/methods to retrieve and check library version
- Date: Thu, 9 Aug 2018 18:27:43 +0000 (UTC)
commit 99d1fd0a4846e755fae011822e2ced29630df997
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Jan 6 21:02:35 2018 +0100
vala: Add consts/methods to retrieve and check library version
https://gitlab.gnome.org/GNOME/vala/issues/304
configure.ac | 7 +++
vala/.gitignore | 1 +
vala/Makefile.am | 13 ++++-
vala/valaversion.vala.in | 123 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 142 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index cc02d2863..366f52d54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -13,6 +13,13 @@ AM_MAINTAINER_MODE([enable])
API_VERSION=0.42
PACKAGE_SUFFIX="-$API_VERSION"
+VALA_MAJOR_VERSION=`echo $PACKAGE_VERSION | cut -d. -f1 | sed s/[a-zA-Z\-].*//g`
+VALA_MINOR_VERSION=`echo $PACKAGE_VERSION | cut -d. -f2 | sed s/[a-zA-Z\-].*//g`
+VALA_MICRO_VERSION=`echo $PACKAGE_VERSION | cut -d. -f3 | sed s/[a-zA-Z\-].*//g`
+AC_SUBST(VALA_MAJOR_VERSION)
+AC_SUBST(VALA_MINOR_VERSION)
+AC_SUBST(VALA_MICRO_VERSION)
+
dnl http://people.gnome.org/~walters/docs/build-api.txt
dnl We don't support separate builddir when building from git
echo \#buildapi-variable-no-builddir >/dev/null
diff --git a/vala/.gitignore b/vala/.gitignore
index 597e971b0..cf1b93b32 100644
--- a/vala/.gitignore
+++ b/vala/.gitignore
@@ -1 +1,2 @@
vala.vapi
+valaversion.vala
diff --git a/vala/Makefile.am b/vala/Makefile.am
index 177290960..585f10426 100644
--- a/vala/Makefile.am
+++ b/vala/Makefile.am
@@ -10,7 +10,15 @@ AM_CPPFLAGS = \
-DPACKAGE_DATADIR=\"$(pkgdatadir)\" \
$(NULL)
-BUILT_SOURCES = vala.vala.stamp
+BUILT_SOURCES = vala.vala.stamp $(srcdir)/valaversion.vala
+
+$(srcdir)/valaversion.vala:
+ sed -e "s#\@VALA_MAJOR_VERSION\@#$(VALA_MAJOR_VERSION)#g" \
+ -e "s#\@VALA_MINOR_VERSION\@#$(VALA_MINOR_VERSION)#g" \
+ -e "s#\@VALA_MICRO_VERSION\@#$(VALA_MICRO_VERSION)#g" \
+ -e "s#\@API_VERSION\@#$(API_VERSION)#g" \
+ -e "s#\@PACKAGE_VERSION\@#$(PACKAGE_VERSION)#g" \
+ < $@.in > $@
lib_LTLIBRARIES = \
libvala@PACKAGE_SUFFIX@.la \
@@ -163,6 +171,7 @@ libvala_la_VALASOURCES = \
valausingdirective.vala \
valavaluetype.vala \
valavariable.vala \
+ valaversion.vala \
valaversionattribute.vala \
valavoidtype.vala \
valawhilestatement.vala \
@@ -211,7 +220,7 @@ dist_vapi_DATA = libvala@PACKAGE_SUFFIX@.vapi
libvala@PACKAGE_SUFFIX@.vapi: $(top_srcdir)/gee/gee.vapi $(top_srcdir)/vala/vala.vapi
cat $^ > $@
-EXTRA_DIST = $(libvala_la_VALASOURCES) vala.vapi vala.vala.stamp vala.h
+EXTRA_DIST = $(libvala_la_VALASOURCES) vala.vapi vala.vala.stamp vala.h valaversion.vala.in
MAINTAINERCLEANFILES = \
vala.vapi \
diff --git a/vala/valaversion.vala.in b/vala/valaversion.vala.in
new file mode 100644
index 000000000..6a3289d40
--- /dev/null
+++ b/vala/valaversion.vala.in
@@ -0,0 +1,123 @@
+/* valaversion.vala
+ *
+ * Copyright (C) 2018 Rico Tzschichholz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Rico Tzschichholz <ricotz ubuntu com>
+ */
+
+namespace Vala {
+ /**
+ * Like get_major_version, but from the headers used at application compile time,
+ * rather than from the library linked against at application run time
+ */
+ public const int MAJOR_VERSION = @VALA_MAJOR_VERSION@;
+ /**
+ * Like get_minor_version, but from the headers used at application compile time,
+ * rather than from the library linked against at application run time
+ */
+ public const int MINOR_VERSION = @VALA_MINOR_VERSION@;
+ /**
+ * Like get_micro_version, but from the headers used at application compile time,
+ * rather than from the library linked against at application run time
+ */
+ public const int MICRO_VERSION = @VALA_MICRO_VERSION@;
+
+ /**
+ * The API version string
+ */
+ public const string API_VERSION = "@API_VERSION@";
+
+ /**
+ * The full build-version string generated by the build-system
+ */
+ public const string BUILD_VERSION = "@PACKAGE_VERSION@";
+
+ /**
+ * Returns the major version number of the vala library.
+ *
+ * This function is in the library, so it represents the GTK+
+ * library your code is running against.
+ *
+ * @return the major version number of the vala library
+ */
+ public uint get_major_version () {
+ return MAJOR_VERSION;
+ }
+
+ /**
+ * Returns the minor version number of the vala library.
+ *
+ * This function is in the library, so it represents the vala
+ * library your code is are running against.
+ *
+ * @return the minor version number of the vala library
+ */
+ public uint get_minor_version () {
+ return MINOR_VERSION;
+ }
+
+ /**
+ * Returns the micro version number of the vala library.
+ *
+ * This function is in the library, so it represents the vala
+ * library your code is running against.
+ *
+ * @return the micro version number of the vala library
+ */
+ public uint get_micro_version () {
+ return MICRO_VERSION;
+ }
+
+ /**
+ * Returns the full build-version string of the vala library.
+ *
+ * This function is in the library, so it represents the vala
+ * library your code is running against.
+ *
+ * @return the full build-version string of the vala library
+ */
+ public unowned string get_build_version () {
+ return BUILD_VERSION;
+ }
+
+ /**
+ * Checks that the vala library in use is compatible with the given version.
+ *
+ * This function is in the library, so it represents the vala
+ * library your code is running against.
+ *
+ * @param required_major the required major version
+ * @param required_minor the required minor version
+ * @param required_micro the required micro version
+ * @return null if the vala library is compatible with the given version,
+ * or a string describing the version mismatch.
+ */
+ public unowned string? check_version (uint required_major, uint required_minor, uint required_micro)
+ {
+ uint effective_micro = 100 * MINOR_VERSION + MICRO_VERSION;
+ uint required_effective_micro = 100 * required_minor + required_micro;
+
+ if (required_major > MAJOR_VERSION)
+ return "vala version too old (major mismatch)";
+
+ if (required_effective_micro > effective_micro)
+ return "vala version too old (micro mismatch)";
+
+ return null;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]