forked from GNOME/gtk
-
Notifications
You must be signed in to change notification settings - Fork 3
/
check-version.py
executable file
·200 lines (182 loc) · 4.18 KB
/
check-version.py
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python3
import re
import sys
try:
configure_ac = sys.argv[1]
except Exception:
configure_ac = 'configure.ac'
try:
meson_build = sys.argv[2]
except Exception:
meson_build = 'meson.build'
CONFIGURE_MAJOR_VERSION_RE = re.compile(
r'''
^
\s*
m4_define\(
\s*
\[gtk_major_version\]
\s*
,
\s*
\[
(?P<version>[0-9]+)
\]
\s*
\)
$
''',
re.UNICODE | re.VERBOSE
)
CONFIGURE_MINOR_VERSION_RE = re.compile(
r'''
^
\s*
m4_define\(
\s*
\[gtk_minor_version\]
\s*
,
\s*
\[
(?P<version>[0-9]+)
\]
\s*
\)
$
''',
re.UNICODE | re.VERBOSE
)
CONFIGURE_MICRO_VERSION_RE = re.compile(
r'''
^
\s*
m4_define\(
\s*
\[gtk_micro_version\]
\s*
,
\s*
\[
(?P<version>[0-9]+)
\]
\s*
\)
$
''',
re.UNICODE | re.VERBOSE
)
CONFIGURE_INTERFACE_AGE_RE = re.compile(
r'''
^
\s*
m4_define\(
\s*
\[gtk_interface_age\]
\s*
,
\s*
\[
(?P<age>[0-9]+)
\]
\s*
\)
$
''',
re.UNICODE | re.VERBOSE
)
MESON_VERSION_RE = re.compile(
r'''
^
\s*
version
\s*
:{1}
\s*
\'{1}
(?P<major>[0-9]+)
\.{1}
(?P<minor>[0-9]+)
\.{1}
(?P<micro>[0-9]+)
\'{1}
\s*
,?
$
''',
re.UNICODE | re.VERBOSE
)
MESON_INTERFACE_AGE_RE = re.compile(
r'''
^\s*gtk_interface_age\s*={1}\s*(?P<age>[0-9]+)\s*$
''',
re.UNICODE | re.VERBOSE
)
version = {}
with open(configure_ac, 'r') as f:
line = f.readline()
while line:
res = CONFIGURE_MAJOR_VERSION_RE.match(line)
if res:
if 'major' in version:
print(f'Redefinition of major version; version is already set to {version["major"]}')
sys.exit(1)
version['major'] = res.group('version')
line = f.readline()
continue
res = CONFIGURE_MINOR_VERSION_RE.match(line)
if res:
if 'minor' in version:
print(f'Redefinition of minor version; version is already set to {version["minor"]}')
sys.exit(1)
version['minor'] = res.group('version')
line = f.readline()
continue
res = CONFIGURE_MICRO_VERSION_RE.match(line)
if res:
if 'micro' in version:
print(f'Redefinition of micro version; version is already set to {version["micro"]}')
sys.exit(1)
version['micro'] = res.group('version')
line = f.readline()
continue
res = CONFIGURE_INTERFACE_AGE_RE.match(line)
if res:
if 'age' in version:
print(f'Redefinition of interface age; age is already set to {version["age"]}')
sys.exit(1)
version['age'] = res.group('age')
line = f.readline()
continue
if ('major', 'minor', 'micro', 'age') in version:
break
line = f.readline()
print(f'GTK version defined in {configure_ac}: {version["major"]}.{version["minor"]}.{version["micro"]} (age: {version["age"]})')
configure_version = version
version = {}
with open(meson_build, 'r') as f:
line = f.readline()
inside_project = False
while line:
if line.startswith('project('):
inside_project = True
if inside_project:
res = MESON_VERSION_RE.match(line)
if res:
version['major'] = res.group('major')
version['minor'] = res.group('minor')
version['micro'] = res.group('micro')
if inside_project and line.endswith(')'):
inside_project = False
res = MESON_INTERFACE_AGE_RE.match(line)
if res:
version['age'] = res.group('age')
if ('major', 'minor', 'micro', 'age') in version:
break
line = f.readline()
print(f'GTK version defined in {meson_build}: {version["major"]}.{version["minor"]}.{version["micro"]} (age: {version["age"]})')
meson_version = version
if configure_version != meson_version:
print('Version mismatch between Autotools and Meson builds')
sys.exit(1)
sys.exit(0)