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 | |
| 26 | activereleases = ["honister", "hardknott", "gatesgarth", "dunfell", "zeus", "warrior"] |
| 27 | #devbranch = "langdale" |
| 28 | devbranch = "kirkstone" |
| 29 | ltsseries = ["kirkstone", "dunfell"] |
| 30 | |
| 31 | release_series = collections.OrderedDict() |
| 32 | #release_series["langdale"] = "4.1" |
| 33 | release_series["kirkstone"] = "4.0" |
| 34 | release_series["honister"] = "3.4" |
| 35 | release_series["hardknott"] = "3.3" |
| 36 | release_series["gatesgarth"] = "3.2" |
| 37 | release_series["dunfell"] = "3.1" |
| 38 | release_series["zeus"] = "3.0" |
| 39 | release_series["warrior"] = "2.7" |
| 40 | release_series["thud"] = "2.6" |
| 41 | release_series["sumo"] = "2.5" |
| 42 | release_series["rocko"] = "2.4" |
| 43 | release_series["pyro"] = "2.3" |
| 44 | release_series["morty"] = "2.2" |
| 45 | release_series["krogoth"] = "2.1" |
| 46 | release_series["jethro"] = "2.0" |
| 47 | release_series["jethro-pre"] = "1.9" |
| 48 | release_series["fido"] = "1.8" |
| 49 | release_series["dizzy"] = "1.7" |
| 50 | release_series["daisy"] = "1.6" |
| 51 | release_series["dora"] = "1.5" |
| 52 | release_series["dylan"] = "1.4" |
| 53 | release_series["danny"] = "1.3" |
| 54 | release_series["denzil"] = "1.2" |
| 55 | release_series["edison"] = "1.1" |
| 56 | release_series["bernard"] = "1.0" |
| 57 | release_series["laverne"] = "0.9" |
| 58 | |
| 59 | |
| 60 | # "langdale" : "2.2", |
| 61 | bitbake_mapping = { |
| 62 | "kirkstone" : "2.0", |
| 63 | "honister" : "1.52", |
| 64 | "hardknott" : "1.50", |
| 65 | "gatesgarth" : "1.48", |
| 66 | "dunfell" : "1.46", |
| 67 | } |
| 68 | |
| 69 | # 3.4 onwards doesn't have poky version |
| 70 | # Early 3.4 release docs do reference it though |
| 71 | poky_mapping = { |
| 72 | "3.4" : "26.0", |
| 73 | "3.3" : "25.0", |
| 74 | "3.2" : "24.0", |
| 75 | "3.1" : "23.0", |
| 76 | } |
| 77 | |
| 78 | ourseries = None |
| 79 | ourbranch = None |
| 80 | bitbakeversion = None |
| 81 | docconfver = None |
| 82 | |
| 83 | # Test tags exist and inform the user to fetch if not |
| 84 | try: |
| 85 | subprocess.run(["git", "show", "yocto-3.4.2"], capture_output=True, check=True) |
| 86 | except subprocess.CalledProcessError: |
| 87 | sys.exit("Please run 'git fetch --tags' before building the documentation") |
| 88 | |
| 89 | # Try and figure out what we are |
| 90 | tags = subprocess.run(["git", "tag", "--points-at", "HEAD"], capture_output=True, text=True).stdout |
| 91 | for t in tags.split(): |
| 92 | if t.startswith("yocto-"): |
| 93 | ourversion = t[6:] |
| 94 | |
| 95 | if ourversion: |
| 96 | # We're a tagged release |
| 97 | components = ourversion.split(".") |
| 98 | baseversion = components[0] + "." + components[1] |
| 99 | docconfver = ourversion |
| 100 | for i in release_series: |
| 101 | if release_series[i] == baseversion: |
| 102 | ourseries = i |
| 103 | ourbranch = i |
| 104 | if i in bitbake_mapping: |
| 105 | bitbakeversion = bitbake_mapping[i] |
| 106 | else: |
| 107 | # We're floating on a branch |
| 108 | branch = subprocess.run(["git", "branch", "--show-current"], capture_output=True, text=True).stdout.strip() |
| 109 | ourbranch = branch |
| 110 | if branch != "master" and branch not in release_series: |
| 111 | # We're not on a known release branch so we have to guess. Compare the numbers of commits |
| 112 | # from each release branch and assume the smallest number of commits is the one we're based off |
| 113 | possible_branch = None |
| 114 | branch_count = 0 |
| 115 | for b in itertools.chain(release_series.keys(), ["master"]): |
| 116 | result = subprocess.run(["git", "log", "--format=oneline", "HEAD..origin/" + b], capture_output=True, text=True) |
| 117 | if result.returncode == 0: |
| 118 | count = result.stdout.count('\n') |
| 119 | if not possible_branch or count < branch_count: |
| 120 | print("Branch %s has count %s" % (b, count)) |
| 121 | possible_branch = b |
| 122 | branch_count = count |
| 123 | if possible_branch: |
| 124 | branch = possible_branch |
| 125 | else: |
| 126 | branch = "master" |
| 127 | print("Nearest release branch estimated to be %s" % branch) |
| 128 | if branch == "master": |
| 129 | ourseries = devbranch |
| 130 | docconfver = "dev" |
| 131 | bitbakeversion = "" |
| 132 | elif branch in release_series: |
| 133 | ourseries = branch |
| 134 | if branch in bitbake_mapping: |
| 135 | bitbakeversion = bitbake_mapping[branch] |
| 136 | else: |
| 137 | sys.exit("Unknown series for branch %s" % branch) |
| 138 | |
| 139 | previoustags = subprocess.run(["git", "tag", "--merged", "HEAD"], capture_output=True, text=True).stdout |
| 140 | previoustags = [t[6:] for t in previoustags.split() if t.startswith("yocto-" + release_series[ourseries])] |
| 141 | futuretags = subprocess.run(["git", "tag", "--merged", ourbranch], capture_output=True, text=True).stdout |
| 142 | futuretags = [t[6:] for t in futuretags.split() if t.startswith("yocto-" + release_series[ourseries])] |
| 143 | |
| 144 | # Append .999 against the last known version |
| 145 | if len(previoustags) != len(futuretags): |
| 146 | ourversion = previoustags[-1] + ".999" |
| 147 | else: |
| 148 | ourversion = release_series[ourseries] + ".999" |
| 149 | if not docconfver: |
| 150 | docconfver = ourversion |
| 151 | |
| 152 | series = [k for k in release_series] |
| 153 | previousseries = series[series.index(ourseries)+1:] or [""] |
| 154 | lastlts = [k for k in previousseries if k in ltsseries] or "dunfell" |
| 155 | |
| 156 | print("Version calculated to be %s" % ourversion) |
| 157 | print("Release series calculated to be %s" % ourseries) |
| 158 | |
| 159 | replacements = { |
| 160 | "DISTRO" : ourversion, |
| 161 | "DISTRO_NAME_NO_CAP" : ourseries, |
| 162 | "DISTRO_NAME" : ourseries.capitalize(), |
| 163 | "DISTRO_NAME_NO_CAP_MINUS_ONE" : previousseries[0], |
| 164 | "DISTRO_NAME_NO_CAP_LTS" : lastlts[0], |
| 165 | "YOCTO_DOC_VERSION" : ourversion, |
| 166 | "DISTRO_REL_TAG" : "yocto-" + ourversion, |
| 167 | "DOCCONF_VERSION" : docconfver, |
| 168 | "BITBAKE_SERIES" : bitbakeversion, |
| 169 | } |
| 170 | |
| 171 | if release_series[ourseries] in poky_mapping: |
| 172 | pokyversion = poky_mapping[release_series[ourseries]] |
| 173 | if ourversion != release_series[ourseries]: |
| 174 | pokyversion = pokyversion + "." + ourversion.rsplit(".", 1)[1] |
| 175 | else: |
| 176 | pokyversion = pokyversion + ".0" |
| 177 | replacements["POKYVERSION"] = pokyversion |
| 178 | |
| 179 | if os.path.exists("poky.yaml.in"): |
| 180 | with open("poky.yaml.in", "r") as r, open("poky.yaml", "w") as w: |
| 181 | lines = r.readlines() |
| 182 | for line in lines: |
| 183 | data = line.split(":") |
| 184 | k = data[0].strip() |
| 185 | if k in replacements: |
| 186 | w.write("%s : \"%s\"\n" % (k, replacements[k])) |
| 187 | else: |
| 188 | w.write(line) |
| 189 | |
| 190 | print("poky.yaml generated from poky.yaml.in") |
| 191 | |
| 192 | |
| 193 | # In the switcher list of versions we display: |
| 194 | # - latest dev |
| 195 | # - latest stable release |
| 196 | # - latest LTS |
| 197 | # - latest for each releases listed as active |
| 198 | # - latest doc version in current series |
| 199 | # - current doc version |
| 200 | # (with duplicates removed) |
| 201 | |
| 202 | if ourseries not in activereleases: |
| 203 | activereleases.append(ourseries) |
| 204 | |
| 205 | versions = [] |
| 206 | with open("sphinx-static/switchers.js.in", "r") as r, open("sphinx-static/switchers.js", "w") as w: |
| 207 | lines = r.readlines() |
| 208 | for line in lines: |
| 209 | if "VERSIONS_PLACEHOLDER" in line: |
| 210 | w.write(" 'dev': 'dev (%s)',\n" % release_series[devbranch]) |
| 211 | for branch in activereleases: |
| 212 | if branch == devbranch: |
| 213 | continue |
| 214 | versions = subprocess.run('git tag --list yocto-%s*' % (release_series[branch]), shell=True, capture_output=True, text=True).stdout.split() |
| 215 | versions = sorted([v.replace("yocto-" + release_series[branch] + ".", "").replace("yocto-" + release_series[branch], "0") for v in versions], key=int) |
| 216 | if not versions: |
| 217 | continue |
| 218 | version = release_series[branch] |
| 219 | if versions[-1] != "0": |
| 220 | version = version + "." + versions[-1] |
| 221 | versions.append(version) |
| 222 | w.write(" '%s': '%s',\n" % (version, version)) |
| 223 | if ourversion not in versions and ourseries != devbranch: |
| 224 | w.write(" '%s': '%s',\n" % (ourversion, ourversion)) |
| 225 | else: |
| 226 | w.write(line) |
| 227 | |
| 228 | print("switchers.js generated from switchers.js.in") |
| 229 | |