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