blob: ddf70851cb775e646a2811087371e35d9dd5941c [file] [log] [blame]
Andrew Geissler9aee5002022-03-30 16:27:02 +00001#!/usr/bin/env python3
2#
3# Add version information to poky.yaml based upon current git branch/tags
Patrick Williamsdb4c27e2022-08-05 08:10:29 -05004# Also generate the list of available manuals (releases.rst file)
Andrew Geissler9aee5002022-03-30 16:27:02 +00005#
6# Copyright Linux Foundation
7# Author: Richard Purdie <richard.purdie@linuxfoundation.org>
Patrick Williamsdb4c27e2022-08-05 08:10:29 -05008# Author: Quentin Schulz <foss@0leil.net>
Andrew Geissler9aee5002022-03-30 16:27:02 +00009#
10# SPDX-License-Identifier: MIT
11#
12
13
14import subprocess
15import collections
16import sys
17import os
18import itertools
Patrick Williamsdb4c27e2022-08-05 08:10:29 -050019import re
Andrew Geissler9aee5002022-03-30 16:27:02 +000020
21ourversion = None
22if len(sys.argv) == 2:
23 ourversion = sys.argv[1]
24
25ourversion = None
26if len(sys.argv) == 2:
27 ourversion = sys.argv[1]
28
Andrew Geissler78b72792022-06-14 06:47:25 -050029activereleases = ["kirkstone", "dunfell"]
Patrick Williams03907ee2022-05-01 06:28:52 -050030devbranch = "langdale"
Andrew Geissler9aee5002022-03-30 16:27:02 +000031ltsseries = ["kirkstone", "dunfell"]
32
Patrick Williams03907ee2022-05-01 06:28:52 -050033# used by run-docs-builds to get the default page
34if ourversion == "getlatest":
35 print(activereleases[0])
36 sys.exit(0)
37
Andrew Geissler9aee5002022-03-30 16:27:02 +000038release_series = collections.OrderedDict()
Patrick Williams03907ee2022-05-01 06:28:52 -050039release_series["langdale"] = "4.1"
Andrew Geissler9aee5002022-03-30 16:27:02 +000040release_series["kirkstone"] = "4.0"
41release_series["honister"] = "3.4"
42release_series["hardknott"] = "3.3"
43release_series["gatesgarth"] = "3.2"
44release_series["dunfell"] = "3.1"
45release_series["zeus"] = "3.0"
46release_series["warrior"] = "2.7"
47release_series["thud"] = "2.6"
48release_series["sumo"] = "2.5"
49release_series["rocko"] = "2.4"
50release_series["pyro"] = "2.3"
51release_series["morty"] = "2.2"
52release_series["krogoth"] = "2.1"
53release_series["jethro"] = "2.0"
54release_series["jethro-pre"] = "1.9"
55release_series["fido"] = "1.8"
56release_series["dizzy"] = "1.7"
57release_series["daisy"] = "1.6"
58release_series["dora"] = "1.5"
59release_series["dylan"] = "1.4"
60release_series["danny"] = "1.3"
61release_series["denzil"] = "1.2"
62release_series["edison"] = "1.1"
63release_series["bernard"] = "1.0"
64release_series["laverne"] = "0.9"
65
66
Andrew Geissler9aee5002022-03-30 16:27:02 +000067bitbake_mapping = {
Patrick Williams03907ee2022-05-01 06:28:52 -050068 "langdale" : "2.2",
Andrew Geissler9aee5002022-03-30 16:27:02 +000069 "kirkstone" : "2.0",
70 "honister" : "1.52",
71 "hardknott" : "1.50",
72 "gatesgarth" : "1.48",
73 "dunfell" : "1.46",
74}
75
76# 3.4 onwards doesn't have poky version
77# Early 3.4 release docs do reference it though
78poky_mapping = {
79 "3.4" : "26.0",
80 "3.3" : "25.0",
81 "3.2" : "24.0",
82 "3.1" : "23.0",
83}
84
85ourseries = None
86ourbranch = None
87bitbakeversion = None
88docconfver = None
89
90# Test tags exist and inform the user to fetch if not
91try:
Andrew Geissler78b72792022-06-14 06:47:25 -050092 subprocess.run(["git", "show", "yocto-%s" % release_series[activereleases[0]]], capture_output=True, check=True)
Andrew Geissler9aee5002022-03-30 16:27:02 +000093except subprocess.CalledProcessError:
94 sys.exit("Please run 'git fetch --tags' before building the documentation")
95
96# Try and figure out what we are
97tags = subprocess.run(["git", "tag", "--points-at", "HEAD"], capture_output=True, text=True).stdout
98for t in tags.split():
99 if t.startswith("yocto-"):
100 ourversion = t[6:]
101
102if ourversion:
103 # We're a tagged release
104 components = ourversion.split(".")
105 baseversion = components[0] + "." + components[1]
106 docconfver = ourversion
107 for i in release_series:
108 if release_series[i] == baseversion:
109 ourseries = i
110 ourbranch = i
111 if i in bitbake_mapping:
112 bitbakeversion = bitbake_mapping[i]
113else:
114 # We're floating on a branch
115 branch = subprocess.run(["git", "branch", "--show-current"], capture_output=True, text=True).stdout.strip()
116 ourbranch = branch
117 if branch != "master" and branch not in release_series:
118 # We're not on a known release branch so we have to guess. Compare the numbers of commits
119 # from each release branch and assume the smallest number of commits is the one we're based off
120 possible_branch = None
121 branch_count = 0
122 for b in itertools.chain(release_series.keys(), ["master"]):
123 result = subprocess.run(["git", "log", "--format=oneline", "HEAD..origin/" + b], capture_output=True, text=True)
124 if result.returncode == 0:
125 count = result.stdout.count('\n')
126 if not possible_branch or count < branch_count:
127 print("Branch %s has count %s" % (b, count))
128 possible_branch = b
129 branch_count = count
130 if possible_branch:
131 branch = possible_branch
132 else:
133 branch = "master"
134 print("Nearest release branch estimated to be %s" % branch)
135 if branch == "master":
136 ourseries = devbranch
137 docconfver = "dev"
Patrick Williams03907ee2022-05-01 06:28:52 -0500138 bitbakeversion = "dev"
Andrew Geissler9aee5002022-03-30 16:27:02 +0000139 elif branch in release_series:
140 ourseries = branch
141 if branch in bitbake_mapping:
142 bitbakeversion = bitbake_mapping[branch]
143 else:
144 sys.exit("Unknown series for branch %s" % branch)
145
146 previoustags = subprocess.run(["git", "tag", "--merged", "HEAD"], capture_output=True, text=True).stdout
147 previoustags = [t[6:] for t in previoustags.split() if t.startswith("yocto-" + release_series[ourseries])]
148 futuretags = subprocess.run(["git", "tag", "--merged", ourbranch], capture_output=True, text=True).stdout
149 futuretags = [t[6:] for t in futuretags.split() if t.startswith("yocto-" + release_series[ourseries])]
150
151 # Append .999 against the last known version
152 if len(previoustags) != len(futuretags):
153 ourversion = previoustags[-1] + ".999"
154 else:
155 ourversion = release_series[ourseries] + ".999"
156 if not docconfver:
157 docconfver = ourversion
158
159series = [k for k in release_series]
160previousseries = series[series.index(ourseries)+1:] or [""]
161lastlts = [k for k in previousseries if k in ltsseries] or "dunfell"
162
163print("Version calculated to be %s" % ourversion)
164print("Release series calculated to be %s" % ourseries)
165
166replacements = {
167 "DISTRO" : ourversion,
168 "DISTRO_NAME_NO_CAP" : ourseries,
169 "DISTRO_NAME" : ourseries.capitalize(),
170 "DISTRO_NAME_NO_CAP_MINUS_ONE" : previousseries[0],
171 "DISTRO_NAME_NO_CAP_LTS" : lastlts[0],
172 "YOCTO_DOC_VERSION" : ourversion,
173 "DISTRO_REL_TAG" : "yocto-" + ourversion,
174 "DOCCONF_VERSION" : docconfver,
175 "BITBAKE_SERIES" : bitbakeversion,
176}
177
178if release_series[ourseries] in poky_mapping:
179 pokyversion = poky_mapping[release_series[ourseries]]
180 if ourversion != release_series[ourseries]:
181 pokyversion = pokyversion + "." + ourversion.rsplit(".", 1)[1]
182 else:
183 pokyversion = pokyversion + ".0"
184 replacements["POKYVERSION"] = pokyversion
185
186if os.path.exists("poky.yaml.in"):
187 with open("poky.yaml.in", "r") as r, open("poky.yaml", "w") as w:
188 lines = r.readlines()
189 for line in lines:
190 data = line.split(":")
191 k = data[0].strip()
192 if k in replacements:
193 w.write("%s : \"%s\"\n" % (k, replacements[k]))
194 else:
195 w.write(line)
196
197 print("poky.yaml generated from poky.yaml.in")
198
199
200# In the switcher list of versions we display:
201# - latest dev
202# - latest stable release
203# - latest LTS
204# - latest for each releases listed as active
205# - latest doc version in current series
206# - current doc version
207# (with duplicates removed)
208
Andrew Geissler9aee5002022-03-30 16:27:02 +0000209versions = []
210with open("sphinx-static/switchers.js.in", "r") as r, open("sphinx-static/switchers.js", "w") as w:
211 lines = r.readlines()
212 for line in lines:
Patrick Williams03907ee2022-05-01 06:28:52 -0500213 if "ALL_RELEASES_PLACEHOLDER" in line:
214 w.write(str(list(release_series.keys())))
215 continue
Andrew Geissler9aee5002022-03-30 16:27:02 +0000216 if "VERSIONS_PLACEHOLDER" in line:
Andrew Geisslerd5838332022-05-27 11:33:10 -0500217 w.write(" 'dev': { 'title': 'Unstable (dev)', 'obsolete': false,},\n")
Patrick Williams03907ee2022-05-01 06:28:52 -0500218 for branch in activereleases + ([ourseries] if ourseries not in activereleases else []):
Andrew Geissler9aee5002022-03-30 16:27:02 +0000219 if branch == devbranch:
220 continue
Patrick Williams03907ee2022-05-01 06:28:52 -0500221 branch_versions = subprocess.run('git tag --list yocto-%s*' % (release_series[branch]), shell=True, capture_output=True, text=True).stdout.split()
222 branch_versions = sorted([v.replace("yocto-" + release_series[branch] + ".", "").replace("yocto-" + release_series[branch], "0") for v in branch_versions], key=int)
223 if not branch_versions:
Andrew Geissler9aee5002022-03-30 16:27:02 +0000224 continue
225 version = release_series[branch]
Patrick Williams03907ee2022-05-01 06:28:52 -0500226 if branch_versions[-1] != "0":
227 version = version + "." + branch_versions[-1]
Andrew Geissler9aee5002022-03-30 16:27:02 +0000228 versions.append(version)
Andrew Geisslerd5838332022-05-27 11:33:10 -0500229 w.write(" '%s': {'title': '%s (%s)', 'obsolete': %s,},\n" % (version, branch.capitalize(), version, str(branch not in activereleases).lower()))
Andrew Geissler9aee5002022-03-30 16:27:02 +0000230 if ourversion not in versions and ourseries != devbranch:
Andrew Geisslerd5838332022-05-27 11:33:10 -0500231 w.write(" '%s': {'title': '%s (%s)', 'obsolete': %s,},\n" % (ourversion, ourseries.capitalize(), ourversion, str(ourseries not in activereleases).lower()))
Andrew Geissler9aee5002022-03-30 16:27:02 +0000232 else:
233 w.write(line)
234
235print("switchers.js generated from switchers.js.in")
236
Patrick Williamsdb4c27e2022-08-05 08:10:29 -0500237# generate releases.rst
238
239# list missing tags in yocto-docs
240missing_tags = [
241 'yocto-0.9',
242 'yocto-1.0', 'yocto-1.0.1',
243 'yocto-1.1', 'yocto-1.1.1',
244 'yocto-1.2',
245 'yocto-1.4.4', 'yocto-1.4.5',
246 'yocto-1.5', 'yocto-1.5.2', 'yocto-1.5.3', 'yocto-1.5.4',
247 'yocto-1.6', 'yocto-1.6.1', 'yocto-1.6.2',
248 'yocto-1.7', 'yocto-1.7.1',
249 'yocto-1.9',
250 'yocto-2.5.3',
251 'yocto-3.1', 'yocto-3.1.1', 'yocto-3.1.2', 'yocto-3.1.3',
252 ]
253
254semver = re.compile(r'yocto-(\d+)\.(\d+)(?:\.)?(\d*)')
255
256# git is able to properly order semver versions but not python
257# instead of adding a dependency on semver module, let's convert the version
258# into a decimal number, e.g. 11.23.1 will be 112301 and 1.5 will be 010500 so
259# it can be used as a key for the sorting algorithm.
260# This can be removed once all the old tags are re-created.
261def tag_to_semver_like(v):
262 v_semver = semver.search(v)
263 v_maj, v_min, v_patch = v_semver.groups('0')
264 return int("{:0>2}{:0>2}{:0>2}".format(v_maj, v_min, v_patch), 10)
265
266yocto_tags = subprocess.run(["git", "tag", "--list", "--sort=version:refname", "yocto-*"], capture_output=True, text=True).stdout
267yocto_tags = sorted(yocto_tags.split() + missing_tags, key=tag_to_semver_like)
268tags = [tag[6:] for tag in yocto_tags]
269
270with open('releases.rst', 'w') as f:
271 f.write('===========================\n')
272 f.write(' Supported Release Manuals\n')
273 f.write('===========================\n')
274 f.write('\n')
275
276 for activerelease in activereleases:
277 title = "Release Series %s (%s)" % (release_series[activerelease], activerelease)
278 f.write('*' * len(title) + '\n')
279 f.write(title + '\n')
280 f.write('*' * len(title) + '\n')
281 f.write('\n')
282
283 for tag in tags:
284 if tag == release_series[activerelease] or tag.startswith('%s.' % release_series[activerelease]):
285 f.write('- :yocto_docs:`%s Documentation </%s>`\n' % (tag, tag))
286 f.write('\n')
287
288 f.write('==========================\n')
289 f.write(' Outdated Release Manuals\n')
290 f.write('==========================\n')
291 f.write('\n')
292
293 for series in release_series:
294 if series == devbranch or series in activereleases:
295 continue
296
297 if series == "jethro-pre":
298 continue
299
300 title = "Release Series %s (%s)" % (release_series[series], series)
301 f.write('*' * len(title) + '\n')
302 f.write(title + '\n')
303 f.write('*' * len(title) + '\n')
304 f.write('\n')
305 if series == "jethro":
306 f.write('- :yocto_docs:`1.9 Documentation </1.9>`\n')
307 for tag in tags:
308 if tag == release_series[series] or tag.startswith('%s.' % release_series[series]):
309 f.write('- :yocto_docs:`%s Documentation </%s>`\n' % (tag, tag))
310 f.write('\n')