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 | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 29 | activereleases = ["kirkstone", "dunfell"] |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 30 | devbranch = "langdale" |
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() |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 39 | release_series["langdale"] = "4.1" |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 40 | release_series["kirkstone"] = "4.0" |
| 41 | release_series["honister"] = "3.4" |
| 42 | release_series["hardknott"] = "3.3" |
| 43 | release_series["gatesgarth"] = "3.2" |
| 44 | release_series["dunfell"] = "3.1" |
| 45 | release_series["zeus"] = "3.0" |
| 46 | release_series["warrior"] = "2.7" |
| 47 | release_series["thud"] = "2.6" |
| 48 | release_series["sumo"] = "2.5" |
| 49 | release_series["rocko"] = "2.4" |
| 50 | release_series["pyro"] = "2.3" |
| 51 | release_series["morty"] = "2.2" |
| 52 | release_series["krogoth"] = "2.1" |
| 53 | release_series["jethro"] = "2.0" |
| 54 | release_series["jethro-pre"] = "1.9" |
| 55 | release_series["fido"] = "1.8" |
| 56 | release_series["dizzy"] = "1.7" |
| 57 | release_series["daisy"] = "1.6" |
| 58 | release_series["dora"] = "1.5" |
| 59 | release_series["dylan"] = "1.4" |
| 60 | release_series["danny"] = "1.3" |
| 61 | release_series["denzil"] = "1.2" |
| 62 | release_series["edison"] = "1.1" |
| 63 | release_series["bernard"] = "1.0" |
| 64 | release_series["laverne"] = "0.9" |
| 65 | |
| 66 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 67 | bitbake_mapping = { |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 68 | "langdale" : "2.2", |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 69 | "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 |
| 78 | poky_mapping = { |
| 79 | "3.4" : "26.0", |
| 80 | "3.3" : "25.0", |
| 81 | "3.2" : "24.0", |
| 82 | "3.1" : "23.0", |
| 83 | } |
| 84 | |
| 85 | ourseries = None |
| 86 | ourbranch = None |
| 87 | bitbakeversion = None |
| 88 | docconfver = None |
| 89 | |
| 90 | # Test tags exist and inform the user to fetch if not |
| 91 | try: |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 92 | 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] | 93 | except subprocess.CalledProcessError: |
| 94 | sys.exit("Please run 'git fetch --tags' before building the documentation") |
| 95 | |
| 96 | # Try and figure out what we are |
| 97 | tags = subprocess.run(["git", "tag", "--points-at", "HEAD"], capture_output=True, text=True).stdout |
| 98 | for t in tags.split(): |
| 99 | if t.startswith("yocto-"): |
| 100 | ourversion = t[6:] |
| 101 | |
| 102 | if 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] |
| 113 | else: |
| 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 Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 138 | bitbakeversion = "dev" |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 139 | 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 | |
| 159 | series = [k for k in release_series] |
| 160 | previousseries = series[series.index(ourseries)+1:] or [""] |
| 161 | lastlts = [k for k in previousseries if k in ltsseries] or "dunfell" |
| 162 | |
| 163 | print("Version calculated to be %s" % ourversion) |
| 164 | print("Release series calculated to be %s" % ourseries) |
| 165 | |
| 166 | replacements = { |
| 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 | |
| 178 | if 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 | |
| 186 | if 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 Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 209 | versions = [] |
| 210 | with 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 Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 213 | if "ALL_RELEASES_PLACEHOLDER" in line: |
| 214 | w.write(str(list(release_series.keys()))) |
| 215 | continue |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 216 | if "VERSIONS_PLACEHOLDER" in line: |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 217 | w.write(" 'dev': { 'title': 'Unstable (dev)', 'obsolete': false,},\n") |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 218 | for branch in activereleases + ([ourseries] if ourseries not in activereleases else []): |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 219 | if branch == devbranch: |
| 220 | continue |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 221 | 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 Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 224 | continue |
| 225 | version = release_series[branch] |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 226 | if branch_versions[-1] != "0": |
| 227 | version = version + "." + branch_versions[-1] |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 228 | versions.append(version) |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 229 | 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] | 230 | if ourversion not in versions and ourseries != devbranch: |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 231 | 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] | 232 | else: |
| 233 | w.write(line) |
| 234 | |
| 235 | print("switchers.js generated from switchers.js.in") |
| 236 | |
Patrick Williams | db4c27e | 2022-08-05 08:10:29 -0500 | [diff] [blame^] | 237 | # generate releases.rst |
| 238 | |
| 239 | # list missing tags in yocto-docs |
| 240 | missing_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 | |
| 254 | semver = 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. |
| 261 | def 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 | |
| 266 | yocto_tags = subprocess.run(["git", "tag", "--list", "--sort=version:refname", "yocto-*"], capture_output=True, text=True).stdout |
| 267 | yocto_tags = sorted(yocto_tags.split() + missing_tags, key=tag_to_semver_like) |
| 268 | tags = [tag[6:] for tag in yocto_tags] |
| 269 | |
| 270 | with 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') |