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 |
| 4 | # |
| 5 | # Copyright Linux Foundation |
| 6 | # Author: Richard Purdie <richard.purdie@linuxfoundation.org> |
| 7 | # |
| 8 | # SPDX-License-Identifier: MIT |
| 9 | # |
| 10 | |
| 11 | |
| 12 | import subprocess |
| 13 | import collections |
| 14 | import sys |
| 15 | import os |
| 16 | import itertools |
| 17 | |
| 18 | ourversion = None |
| 19 | if len(sys.argv) == 2: |
| 20 | ourversion = sys.argv[1] |
| 21 | |
| 22 | ourversion = None |
| 23 | if len(sys.argv) == 2: |
| 24 | ourversion = sys.argv[1] |
| 25 | |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 26 | activereleases = ["kirkstone", "honister", "hardknott", "dunfell"] |
| 27 | devbranch = "langdale" |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 28 | ltsseries = ["kirkstone", "dunfell"] |
| 29 | |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 30 | # used by run-docs-builds to get the default page |
| 31 | if ourversion == "getlatest": |
| 32 | print(activereleases[0]) |
| 33 | sys.exit(0) |
| 34 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 35 | release_series = collections.OrderedDict() |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 36 | release_series["langdale"] = "4.1" |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 37 | release_series["kirkstone"] = "4.0" |
| 38 | release_series["honister"] = "3.4" |
| 39 | release_series["hardknott"] = "3.3" |
| 40 | release_series["gatesgarth"] = "3.2" |
| 41 | release_series["dunfell"] = "3.1" |
| 42 | release_series["zeus"] = "3.0" |
| 43 | release_series["warrior"] = "2.7" |
| 44 | release_series["thud"] = "2.6" |
| 45 | release_series["sumo"] = "2.5" |
| 46 | release_series["rocko"] = "2.4" |
| 47 | release_series["pyro"] = "2.3" |
| 48 | release_series["morty"] = "2.2" |
| 49 | release_series["krogoth"] = "2.1" |
| 50 | release_series["jethro"] = "2.0" |
| 51 | release_series["jethro-pre"] = "1.9" |
| 52 | release_series["fido"] = "1.8" |
| 53 | release_series["dizzy"] = "1.7" |
| 54 | release_series["daisy"] = "1.6" |
| 55 | release_series["dora"] = "1.5" |
| 56 | release_series["dylan"] = "1.4" |
| 57 | release_series["danny"] = "1.3" |
| 58 | release_series["denzil"] = "1.2" |
| 59 | release_series["edison"] = "1.1" |
| 60 | release_series["bernard"] = "1.0" |
| 61 | release_series["laverne"] = "0.9" |
| 62 | |
| 63 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 64 | bitbake_mapping = { |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 65 | "langdale" : "2.2", |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 66 | "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 |
| 75 | poky_mapping = { |
| 76 | "3.4" : "26.0", |
| 77 | "3.3" : "25.0", |
| 78 | "3.2" : "24.0", |
| 79 | "3.1" : "23.0", |
| 80 | } |
| 81 | |
| 82 | ourseries = None |
| 83 | ourbranch = None |
| 84 | bitbakeversion = None |
| 85 | docconfver = None |
| 86 | |
| 87 | # Test tags exist and inform the user to fetch if not |
| 88 | try: |
| 89 | subprocess.run(["git", "show", "yocto-3.4.2"], capture_output=True, check=True) |
| 90 | except subprocess.CalledProcessError: |
| 91 | sys.exit("Please run 'git fetch --tags' before building the documentation") |
| 92 | |
| 93 | # Try and figure out what we are |
| 94 | tags = subprocess.run(["git", "tag", "--points-at", "HEAD"], capture_output=True, text=True).stdout |
| 95 | for t in tags.split(): |
| 96 | if t.startswith("yocto-"): |
| 97 | ourversion = t[6:] |
| 98 | |
| 99 | if 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] |
| 110 | else: |
| 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 Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 135 | bitbakeversion = "dev" |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 136 | 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 | |
| 156 | series = [k for k in release_series] |
| 157 | previousseries = series[series.index(ourseries)+1:] or [""] |
| 158 | lastlts = [k for k in previousseries if k in ltsseries] or "dunfell" |
| 159 | |
| 160 | print("Version calculated to be %s" % ourversion) |
| 161 | print("Release series calculated to be %s" % ourseries) |
| 162 | |
| 163 | replacements = { |
| 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 | |
| 175 | if 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 | |
| 183 | if 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 Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 206 | versions = [] |
| 207 | with 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 Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 210 | if "ALL_RELEASES_PLACEHOLDER" in line: |
| 211 | w.write(str(list(release_series.keys()))) |
| 212 | continue |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 213 | if "VERSIONS_PLACEHOLDER" in line: |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 214 | w.write(" 'dev': { 'title': 'dev (%s)', 'obsolete': false,},\n" % release_series[devbranch]) |
| 215 | for branch in activereleases + ([ourseries] if ourseries not in activereleases else []): |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 216 | if branch == devbranch: |
| 217 | continue |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 218 | 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 Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 221 | continue |
| 222 | version = release_series[branch] |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 223 | if branch_versions[-1] != "0": |
| 224 | version = version + "." + branch_versions[-1] |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 225 | versions.append(version) |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 226 | w.write(" '%s': {'title': '%s', 'obsolete': %s,},\n" % (version, version, str(branch not in activereleases).lower())) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 227 | if ourversion not in versions and ourseries != devbranch: |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 228 | w.write(" '%s': {'title': '%s', 'obsolete': %s,},\n" % (ourversion, ourversion, str(ourseries not in activereleases).lower())) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 229 | else: |
| 230 | w.write(line) |
| 231 | |
| 232 | print("switchers.js generated from switchers.js.in") |
| 233 | |