blob: c72e440495bfc55c46f78c8847942e771182dd16 [file] [log] [blame]
Dylan Baker86079442019-09-25 14:56:21 -07001#!/usr/bin/env python3
Dylan Baker0123b8f2020-03-05 14:04:04 -08002# Copyright © 2019-2020 Intel Corporation
Dylan Baker86079442019-09-25 14:56:21 -07003
4# Permission is hereby granted, free of charge, to any person obtaining a copy
5# of this software and associated documentation files (the "Software"), to deal
6# in the Software without restriction, including without limitation the rights
7# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8# copies of the Software, and to permit persons to whom the Software is
9# furnished to do so, subject to the following conditions:
10
11# The above copyright notice and this permission notice shall be included in
12# all copies or substantial portions of the Software.
13
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20# SOFTWARE.
21
22"""Generates release notes for a given version of mesa."""
23
24import asyncio
25import datetime
26import os
27import pathlib
Dylan Baker8a4541a2019-10-24 13:11:40 -070028import sys
Dylan Baker86079442019-09-25 14:56:21 -070029import textwrap
30import typing
31import urllib.parse
32
33import aiohttp
34from mako.template import Template
35from mako import exceptions
36
37
38CURRENT_GL_VERSION = '4.6'
Eric Engestrom2557d612020-03-06 19:12:26 +010039CURRENT_VK_VERSION = '1.2'
Dylan Baker86079442019-09-25 14:56:21 -070040
41TEMPLATE = Template(textwrap.dedent("""\
Eric Engestrom8bc055f2020-04-29 02:02:28 +020042 ${header}
43 ${header_underline}
Dylan Baker86079442019-09-25 14:56:21 -070044
Dylan Baker69f540c2019-10-09 10:27:13 -070045 %if not bugfix:
Eric Engestrom8bc055f2020-04-29 02:02:28 +020046 Mesa ${this_version} is a new development release. People who are concerned
47 with stability and reliability should stick with a previous release or
48 wait for Mesa ${this_version[:-1]}1.
Dylan Baker86079442019-09-25 14:56:21 -070049 %else:
Eric Engestrom8bc055f2020-04-29 02:02:28 +020050 Mesa ${this_version} is a bug fix release which fixes bugs found since the ${previous_version} release.
Dylan Baker86079442019-09-25 14:56:21 -070051 %endif
Eric Engestrom8bc055f2020-04-29 02:02:28 +020052
Eric Engestrom3aa83d82020-03-09 12:58:05 +010053 Mesa ${this_version} implements the OpenGL ${gl_version} API, but the version reported by
Dylan Baker86079442019-09-25 14:56:21 -070054 glGetString(GL_VERSION) or glGetIntegerv(GL_MAJOR_VERSION) /
55 glGetIntegerv(GL_MINOR_VERSION) depends on the particular driver being used.
56 Some drivers don't support all the features required in OpenGL ${gl_version}. OpenGL
Eric Engestrom8bc055f2020-04-29 02:02:28 +020057 ${gl_version} is **only** available if requested at context creation.
Dylan Baker86079442019-09-25 14:56:21 -070058 Compatibility contexts may report a lower version depending on each driver.
Eric Engestrom8bc055f2020-04-29 02:02:28 +020059
Eric Engestrom3aa83d82020-03-09 12:58:05 +010060 Mesa ${this_version} implements the Vulkan ${vk_version} API, but the version reported by
Dylan Baker86079442019-09-25 14:56:21 -070061 the apiVersion property of the VkPhysicalDeviceProperties struct
62 depends on the particular driver being used.
Dylan Baker86079442019-09-25 14:56:21 -070063
Eric Engestrom8bc055f2020-04-29 02:02:28 +020064 SHA256 checksum
65 ---------------
66
67 ::
68
69 TBD.
Dylan Baker86079442019-09-25 14:56:21 -070070
71
Eric Engestrom8bc055f2020-04-29 02:02:28 +020072 New features
73 ------------
Dylan Baker86079442019-09-25 14:56:21 -070074
Dylan Baker86079442019-09-25 14:56:21 -070075 %for f in features:
Eric Engestrom8bc055f2020-04-29 02:02:28 +020076 - ${f}
Dylan Baker86079442019-09-25 14:56:21 -070077 %endfor
Dylan Baker86079442019-09-25 14:56:21 -070078
Dylan Baker86079442019-09-25 14:56:21 -070079
Eric Engestrom8bc055f2020-04-29 02:02:28 +020080 Bug fixes
81 ---------
82
Dylan Baker86079442019-09-25 14:56:21 -070083 %for b in bugs:
Eric Engestrom8bc055f2020-04-29 02:02:28 +020084 - ${b}
Dylan Baker86079442019-09-25 14:56:21 -070085 %endfor
Dylan Baker86079442019-09-25 14:56:21 -070086
Dylan Baker86079442019-09-25 14:56:21 -070087
Eric Engestrom8bc055f2020-04-29 02:02:28 +020088 Changes
89 -------
90 %for c, author_line in changes:
91 %if author_line:
92
93 ${c}
94
Dylan Baker86079442019-09-25 14:56:21 -070095 %else:
Eric Engestrom8bc055f2020-04-29 02:02:28 +020096 - ${c}
Dylan Baker86079442019-09-25 14:56:21 -070097 %endif
98 %endfor
Dylan Baker86079442019-09-25 14:56:21 -070099 """))
100
101
102async def gather_commits(version: str) -> str:
103 p = await asyncio.create_subprocess_exec(
Eric Engestromd7a70fb2020-03-05 23:09:45 +0100104 'git', 'log', '--oneline', f'mesa-{version}..', '--grep', r'Closes: \(https\|#\).*',
Dylan Baker86079442019-09-25 14:56:21 -0700105 stdout=asyncio.subprocess.PIPE)
106 out, _ = await p.communicate()
107 assert p.returncode == 0, f"git log didn't work: {version}"
108 return out.decode().strip()
109
110
111async def gather_bugs(version: str) -> typing.List[str]:
112 commits = await gather_commits(version)
113
114 issues: typing.List[str] = []
115 for commit in commits.split('\n'):
116 sha, message = commit.split(maxsplit=1)
117 p = await asyncio.create_subprocess_exec(
118 'git', 'log', '--max-count', '1', r'--format=%b', sha,
119 stdout=asyncio.subprocess.PIPE)
120 _out, _ = await p.communicate()
121 out = _out.decode().split('\n')
122 for line in reversed(out):
123 if line.startswith('Closes:'):
124 bug = line.lstrip('Closes:').strip()
125 break
126 else:
127 raise Exception('No closes found?')
128 if bug.startswith('h'):
129 # This means we have a bug in the form "Closes: https://..."
130 issues.append(os.path.basename(urllib.parse.urlparse(bug).path))
131 else:
Dylan Bakerdf3d4ad2019-10-09 10:29:41 -0700132 issues.append(bug.lstrip('#'))
Dylan Baker86079442019-09-25 14:56:21 -0700133
134 loop = asyncio.get_event_loop()
135 async with aiohttp.ClientSession(loop=loop) as session:
136 results = await asyncio.gather(*[get_bug(session, i) for i in issues])
137 typing.cast(typing.Tuple[str, ...], results)
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200138 bugs = list(results)
139 if not bugs:
140 bugs = ['None']
141 return bugs
Dylan Baker86079442019-09-25 14:56:21 -0700142
143
144async def get_bug(session: aiohttp.ClientSession, bug_id: str) -> str:
145 """Query gitlab to get the name of the issue that was closed."""
146 # Mesa's gitlab id is 176,
147 url = 'https://gitlab.freedesktop.org/api/v4/projects/176/issues'
148 params = {'iids[]': bug_id}
149 async with session.get(url, params=params) as response:
150 content = await response.json()
151 return content[0]['title']
152
153
154async def get_shortlog(version: str) -> str:
155 """Call git shortlog."""
156 p = await asyncio.create_subprocess_exec('git', 'shortlog', f'mesa-{version}..',
157 stdout=asyncio.subprocess.PIPE)
158 out, _ = await p.communicate()
159 assert p.returncode == 0, 'error getting shortlog'
160 assert out is not None, 'just for mypy'
161 return out.decode()
162
163
164def walk_shortlog(log: str) -> typing.Generator[typing.Tuple[str, bool], None, None]:
165 for l in log.split('\n'):
166 if l.startswith(' '): # this means we have a patch description
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200167 yield l.lstrip(), False
168 elif l.strip():
Dylan Baker86079442019-09-25 14:56:21 -0700169 yield l, True
170
171
172def calculate_next_version(version: str, is_point: bool) -> str:
173 """Calculate the version about to be released."""
174 if '-' in version:
175 version = version.split('-')[0]
176 if is_point:
177 base = version.split('.')
178 base[2] = str(int(base[2]) + 1)
179 return '.'.join(base)
180 return version
181
182
183def calculate_previous_version(version: str, is_point: bool) -> str:
184 """Calculate the previous version to compare to.
185
186 In the case of -rc to final that verison is the previous .0 release,
187 (19.3.0 in the case of 20.0.0, for example). for point releases that is
188 the last point release. This value will be the same as the input value
189 for a point release, but different for a major release.
190 """
191 if '-' in version:
192 version = version.split('-')[0]
193 if is_point:
194 return version
195 base = version.split('.')
196 if base[1] == '0':
197 base[0] = str(int(base[0]) - 1)
198 base[1] = '3'
199 else:
200 base[1] = str(int(base[1]) - 1)
201 return '.'.join(base)
202
203
Dylan Baker8a4541a2019-10-24 13:11:40 -0700204def get_features(is_point_release: bool) -> typing.Generator[str, None, None]:
Dylan Baker86079442019-09-25 14:56:21 -0700205 p = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes' / 'new_features.txt'
206 if p.exists():
Dylan Baker8a4541a2019-10-24 13:11:40 -0700207 if is_point_release:
208 print("WARNING: new features being introduced in a point release", file=sys.stderr)
Dylan Baker86079442019-09-25 14:56:21 -0700209 with p.open('rt') as f:
210 for line in f:
211 yield line
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200212 else:
213 yield "None"
Eric Engestromc905e482020-06-10 19:50:31 +0200214 p.unlink()
Dylan Bakerc6d41e72019-10-09 10:30:17 -0700215 else:
216 yield "None"
Dylan Baker86079442019-09-25 14:56:21 -0700217
218
219async def main() -> None:
220 v = pathlib.Path(__file__).parent.parent / 'VERSION'
221 with v.open('rt') as f:
222 raw_version = f.read().strip()
223 is_point_release = '-rc' not in raw_version
224 assert '-devel' not in raw_version, 'Do not run this script on -devel'
225 version = raw_version.split('-')[0]
226 previous_version = calculate_previous_version(version, is_point_release)
Eric Engestrom3aa83d82020-03-09 12:58:05 +0100227 this_version = calculate_next_version(version, is_point_release)
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200228 today = datetime.date.today()
229 header = f'Mesa {this_version} Release Notes / {today}'
230 header_underline = '=' * len(header)
Dylan Baker86079442019-09-25 14:56:21 -0700231
232 shortlog, bugs = await asyncio.gather(
233 get_shortlog(previous_version),
234 gather_bugs(previous_version),
235 )
236
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200237 final = pathlib.Path(__file__).parent.parent / 'docs' / 'relnotes' / f'{this_version}.rst'
Dylan Baker86079442019-09-25 14:56:21 -0700238 with final.open('wt') as f:
239 try:
240 f.write(TEMPLATE.render(
241 bugfix=is_point_release,
242 bugs=bugs,
243 changes=walk_shortlog(shortlog),
Dylan Baker8a4541a2019-10-24 13:11:40 -0700244 features=get_features(is_point_release),
Dylan Baker86079442019-09-25 14:56:21 -0700245 gl_version=CURRENT_GL_VERSION,
Eric Engestrom3aa83d82020-03-09 12:58:05 +0100246 this_version=this_version,
Eric Engestrom8bc055f2020-04-29 02:02:28 +0200247 header=header,
248 header_underline=header_underline,
Eric Engestrom3aa83d82020-03-09 12:58:05 +0100249 previous_version=previous_version,
Dylan Baker86079442019-09-25 14:56:21 -0700250 vk_version=CURRENT_VK_VERSION,
251 ))
252 except:
253 print(exceptions.text_error_template().render())
254
255
256if __name__ == "__main__":
257 loop = asyncio.get_event_loop()
258 loop.run_until_complete(main())