blob: a7ceb3455ae9b0d841f70aea3b91a602f39a79a5 [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
4#
5# Copyright Linux Foundation
6# Author: Richard Purdie <richard.purdie@linuxfoundation.org>
7#
8# SPDX-License-Identifier: MIT
9#
10
11
12import subprocess
13import collections
14import sys
15import os
16import itertools
17
18ourversion = None
19if len(sys.argv) == 2:
20 ourversion = sys.argv[1]
21
22ourversion = None
23if len(sys.argv) == 2:
24 ourversion = sys.argv[1]
25
Andrew Geissler78b72792022-06-14 06:47:25 -050026activereleases = ["kirkstone", "dunfell"]
Patrick Williams03907ee2022-05-01 06:28:52 -050027devbranch = "langdale"
Andrew Geissler9aee5002022-03-30 16:27:02 +000028ltsseries = ["kirkstone", "dunfell"]
29
Patrick Williams03907ee2022-05-01 06:28:52 -050030# used by run-docs-builds to get the default page
31if ourversion == "getlatest":
32 print(activereleases[0])
33 sys.exit(0)
34
Andrew Geissler9aee5002022-03-30 16:27:02 +000035release_series = collections.OrderedDict()
Patrick Williams03907ee2022-05-01 06:28:52 -050036release_series["langdale"] = "4.1"
Andrew Geissler9aee5002022-03-30 16:27:02 +000037release_series["kirkstone"] = "4.0"
38release_series["honister"] = "3.4"
39release_series["hardknott"] = "3.3"
40release_series["gatesgarth"] = "3.2"
41release_series["dunfell"] = "3.1"
42release_series["zeus"] = "3.0"
43release_series["warrior"] = "2.7"
44release_series["thud"] = "2.6"
45release_series["sumo"] = "2.5"
46release_series["rocko"] = "2.4"
47release_series["pyro"] = "2.3"
48release_series["morty"] = "2.2"
49release_series["krogoth"] = "2.1"
50release_series["jethro"] = "2.0"
51release_series["jethro-pre"] = "1.9"
52release_series["fido"] = "1.8"
53release_series["dizzy"] = "1.7"
54release_series["daisy"] = "1.6"
55release_series["dora"] = "1.5"
56release_series["dylan"] = "1.4"
57release_series["danny"] = "1.3"
58release_series["denzil"] = "1.2"
59release_series["edison"] = "1.1"
60release_series["bernard"] = "1.0"
61release_series["laverne"] = "0.9"
62
63
Andrew Geissler9aee5002022-03-30 16:27:02 +000064bitbake_mapping = {
Patrick Williams03907ee2022-05-01 06:28:52 -050065 "langdale" : "2.2",
Andrew Geissler9aee5002022-03-30 16:27:02 +000066 "kirkstone" : "2.0",
67 "honister" : "1.52",
68 "hardknott" : "1.50",
69 "gatesgarth" : "1.48",
70 "dunfell" : "1.46",
71}
72
73# 3.4 onwards doesn't have poky version
74# Early 3.4 release docs do reference it though
75poky_mapping = {
76 "3.4" : "26.0",
77 "3.3" : "25.0",
78 "3.2" : "24.0",
79 "3.1" : "23.0",
80}
81
82ourseries = None
83ourbranch = None
84bitbakeversion = None
85docconfver = None
86
87# Test tags exist and inform the user to fetch if not
88try:
Andrew Geissler78b72792022-06-14 06:47:25 -050089 subprocess.run(["git", "show", "yocto-%s" % release_series[activereleases[0]]], capture_output=True, check=True)
Andrew Geissler9aee5002022-03-30 16:27:02 +000090except subprocess.CalledProcessError:
91 sys.exit("Please run 'git fetch --tags' before building the documentation")
92
93# Try and figure out what we are
94tags = subprocess.run(["git", "tag", "--points-at", "HEAD"], capture_output=True, text=True).stdout
95for t in tags.split():
96 if t.startswith("yocto-"):
97 ourversion = t[6:]
98
99if ourversion:
100 # We're a tagged release
101 components = ourversion.split(".")
102 baseversion = components[0] + "." + components[1]
103 docconfver = ourversion
104 for i in release_series:
105 if release_series[i] == baseversion:
106 ourseries = i
107 ourbranch = i
108 if i in bitbake_mapping:
109 bitbakeversion = bitbake_mapping[i]
110else:
111 # We're floating on a branch
112 branch = subprocess.run(["git", "branch", "--show-current"], capture_output=True, text=True).stdout.strip()
113 ourbranch = branch
114 if branch != "master" and branch not in release_series:
115 # We're not on a known release branch so we have to guess. Compare the numbers of commits
116 # from each release branch and assume the smallest number of commits is the one we're based off
117 possible_branch = None
118 branch_count = 0
119 for b in itertools.chain(release_series.keys(), ["master"]):
120 result = subprocess.run(["git", "log", "--format=oneline", "HEAD..origin/" + b], capture_output=True, text=True)
121 if result.returncode == 0:
122 count = result.stdout.count('\n')
123 if not possible_branch or count < branch_count:
124 print("Branch %s has count %s" % (b, count))
125 possible_branch = b
126 branch_count = count
127 if possible_branch:
128 branch = possible_branch
129 else:
130 branch = "master"
131 print("Nearest release branch estimated to be %s" % branch)
132 if branch == "master":
133 ourseries = devbranch
134 docconfver = "dev"
Patrick Williams03907ee2022-05-01 06:28:52 -0500135 bitbakeversion = "dev"
Andrew Geissler9aee5002022-03-30 16:27:02 +0000136 elif branch in release_series:
137 ourseries = branch
138 if branch in bitbake_mapping:
139 bitbakeversion = bitbake_mapping[branch]
140 else:
141 sys.exit("Unknown series for branch %s" % branch)
142
143 previoustags = subprocess.run(["git", "tag", "--merged", "HEAD"], capture_output=True, text=True).stdout
144 previoustags = [t[6:] for t in previoustags.split() if t.startswith("yocto-" + release_series[ourseries])]
145 futuretags = subprocess.run(["git", "tag", "--merged", ourbranch], capture_output=True, text=True).stdout
146 futuretags = [t[6:] for t in futuretags.split() if t.startswith("yocto-" + release_series[ourseries])]
147
148 # Append .999 against the last known version
149 if len(previoustags) != len(futuretags):
150 ourversion = previoustags[-1] + ".999"
151 else:
152 ourversion = release_series[ourseries] + ".999"
153 if not docconfver:
154 docconfver = ourversion
155
156series = [k for k in release_series]
157previousseries = series[series.index(ourseries)+1:] or [""]
158lastlts = [k for k in previousseries if k in ltsseries] or "dunfell"
159
160print("Version calculated to be %s" % ourversion)
161print("Release series calculated to be %s" % ourseries)
162
163replacements = {
164 "DISTRO" : ourversion,
165 "DISTRO_NAME_NO_CAP" : ourseries,
166 "DISTRO_NAME" : ourseries.capitalize(),
167 "DISTRO_NAME_NO_CAP_MINUS_ONE" : previousseries[0],
168 "DISTRO_NAME_NO_CAP_LTS" : lastlts[0],
169 "YOCTO_DOC_VERSION" : ourversion,
170 "DISTRO_REL_TAG" : "yocto-" + ourversion,
171 "DOCCONF_VERSION" : docconfver,
172 "BITBAKE_SERIES" : bitbakeversion,
173}
174
175if release_series[ourseries] in poky_mapping:
176 pokyversion = poky_mapping[release_series[ourseries]]
177 if ourversion != release_series[ourseries]:
178 pokyversion = pokyversion + "." + ourversion.rsplit(".", 1)[1]
179 else:
180 pokyversion = pokyversion + ".0"
181 replacements["POKYVERSION"] = pokyversion
182
183if os.path.exists("poky.yaml.in"):
184 with open("poky.yaml.in", "r") as r, open("poky.yaml", "w") as w:
185 lines = r.readlines()
186 for line in lines:
187 data = line.split(":")
188 k = data[0].strip()
189 if k in replacements:
190 w.write("%s : \"%s\"\n" % (k, replacements[k]))
191 else:
192 w.write(line)
193
194 print("poky.yaml generated from poky.yaml.in")
195
196
197# In the switcher list of versions we display:
198# - latest dev
199# - latest stable release
200# - latest LTS
201# - latest for each releases listed as active
202# - latest doc version in current series
203# - current doc version
204# (with duplicates removed)
205
Andrew Geissler9aee5002022-03-30 16:27:02 +0000206versions = []
207with open("sphinx-static/switchers.js.in", "r") as r, open("sphinx-static/switchers.js", "w") as w:
208 lines = r.readlines()
209 for line in lines:
Patrick Williams03907ee2022-05-01 06:28:52 -0500210 if "ALL_RELEASES_PLACEHOLDER" in line:
211 w.write(str(list(release_series.keys())))
212 continue
Andrew Geissler9aee5002022-03-30 16:27:02 +0000213 if "VERSIONS_PLACEHOLDER" in line:
Andrew Geisslerd5838332022-05-27 11:33:10 -0500214 w.write(" 'dev': { 'title': 'Unstable (dev)', 'obsolete': false,},\n")
Patrick Williams03907ee2022-05-01 06:28:52 -0500215 for branch in activereleases + ([ourseries] if ourseries not in activereleases else []):
Andrew Geissler9aee5002022-03-30 16:27:02 +0000216 if branch == devbranch:
217 continue
Patrick Williams03907ee2022-05-01 06:28:52 -0500218 branch_versions = subprocess.run('git tag --list yocto-%s*' % (release_series[branch]), shell=True, capture_output=True, text=True).stdout.split()
219 branch_versions = sorted([v.replace("yocto-" + release_series[branch] + ".", "").replace("yocto-" + release_series[branch], "0") for v in branch_versions], key=int)
220 if not branch_versions:
Andrew Geissler9aee5002022-03-30 16:27:02 +0000221 continue
222 version = release_series[branch]
Patrick Williams03907ee2022-05-01 06:28:52 -0500223 if branch_versions[-1] != "0":
224 version = version + "." + branch_versions[-1]
Andrew Geissler9aee5002022-03-30 16:27:02 +0000225 versions.append(version)
Andrew Geisslerd5838332022-05-27 11:33:10 -0500226 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 +0000227 if ourversion not in versions and ourseries != devbranch:
Andrew Geisslerd5838332022-05-27 11:33:10 -0500228 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 +0000229 else:
230 w.write(line)
231
232print("switchers.js generated from switchers.js.in")
233