summaryrefslogtreecommitdiff
path: root/vala/valaversion.vala.in
blob: 6a3289d405dd9d8254a1b2cdc3e4f7e0d5696dfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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;
	}
}