diff options
Diffstat (limited to 'documentation/set_versions.py')
| -rwxr-xr-x | documentation/set_versions.py | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/documentation/set_versions.py b/documentation/set_versions.py new file mode 100755 index 0000000000..d48b8b74c7 --- /dev/null +++ b/documentation/set_versions.py | |||
| @@ -0,0 +1,120 @@ | |||
| 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 | |||
| 16 | ourversion = None | ||
| 17 | if len(sys.argv) == 2: | ||
| 18 | ourversion = sys.argv[1] | ||
| 19 | |||
| 20 | activereleases = ["honister", "hardknott", "gatesgarth", "dunfell", "zeus", "warrior"] | ||
| 21 | #devbranch = "langdale" | ||
| 22 | devbranch = "kirkstone" | ||
| 23 | ltsseries = ["kirkstone", "dunfell"] | ||
| 24 | |||
| 25 | release_series = collections.OrderedDict() | ||
| 26 | #release_series["langdale"] = "4.1" | ||
| 27 | release_series["kirkstone"] = "4.0" | ||
| 28 | release_series["honister"] = "3.4" | ||
| 29 | release_series["hardknott"] = "3.3" | ||
| 30 | release_series["gatesgarth"] = "3.2" | ||
| 31 | release_series["dunfell"] = "3.1" | ||
| 32 | |||
| 33 | ourversion = None | ||
| 34 | ourseries = None | ||
| 35 | ourbranch = None | ||
| 36 | |||
| 37 | # Test tags exist and inform the user to fetch if not | ||
| 38 | try: | ||
| 39 | subprocess.run(["git", "show", "yocto-3.4.2"], capture_output=True, check=True) | ||
| 40 | except subprocess.CalledProcessError: | ||
| 41 | sys.exit("Please run 'git fetch --tags' before building the documentation") | ||
| 42 | |||
| 43 | # Try and figure out what we are | ||
| 44 | tags = subprocess.run(["git", "tag", "--points-at", "HEAD"], capture_output=True, text=True).stdout | ||
| 45 | for t in tags.split(): | ||
| 46 | if t.startswith("yocto-"): | ||
| 47 | ourversion = t[6:] | ||
| 48 | |||
| 49 | if ourversion: | ||
| 50 | # We're a tagged release | ||
| 51 | components = ourversion.split(".") | ||
| 52 | baseversion = components[0] + "." + components[1] | ||
| 53 | for i in release_series: | ||
| 54 | if release_series[i] == baseversion: | ||
| 55 | ourseries = i | ||
| 56 | ourbranch = i | ||
| 57 | else: | ||
| 58 | # We're floating on a branch | ||
| 59 | branch = subprocess.run(["git", "branch", "--show-current"], capture_output=True, text=True).stdout.strip() | ||
| 60 | ourbranch = branch | ||
| 61 | if branch != "master" and branch not in release_series: | ||
| 62 | possible_branches = [] | ||
| 63 | for b in release_series.keys(): | ||
| 64 | result = subprocess.run(["git", "show-ref", "heads/" + b], capture_output=True, text=True) | ||
| 65 | if result.returncode == 0: | ||
| 66 | possible_branches.append(b) | ||
| 67 | continue | ||
| 68 | result = subprocess.run(["git", "show-ref", "origin/" + b], capture_output=True, text=True) | ||
| 69 | if result.returncode == 0: | ||
| 70 | possible_branches.append("origin/" + b) | ||
| 71 | nearestbranch = subprocess.run('git show-branch master ' + ' '.join(possible_branches) + ' | grep "*" | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -n1', shell=True, capture_output=True, text=True).stdout | ||
| 72 | branch = nearestbranch.split('[')[1].split('~')[0] | ||
| 73 | print("Nearest release branch esimtated to be %s" % branch) | ||
| 74 | if branch == "master": | ||
| 75 | ourseries = devbranch | ||
| 76 | elif branch in release_series: | ||
| 77 | ourseries = branch | ||
| 78 | else: | ||
| 79 | sys.exit("Unknown series for branch %s" % branch) | ||
| 80 | |||
| 81 | previoustags = subprocess.run(["git", "tag", "--merged", "HEAD"], capture_output=True, text=True).stdout | ||
| 82 | previoustags = [t[6:] for t in previoustags.split() if t.startswith("yocto-" + release_series[ourseries])] | ||
| 83 | futuretags = subprocess.run(["git", "tag", "--merged", ourbranch], capture_output=True, text=True).stdout | ||
| 84 | futuretags = [t[6:] for t in futuretags.split() if t.startswith("yocto-" + release_series[ourseries])] | ||
| 85 | |||
| 86 | # Append .999 against the last known version | ||
| 87 | if len(previoustags) != len(futuretags): | ||
| 88 | ourversion = previoustags[-1] + ".999" | ||
| 89 | else: | ||
| 90 | ourversion = release_series[ourseries] + ".999" | ||
| 91 | |||
| 92 | series = [k for k in release_series] | ||
| 93 | previousseries = series[series.index(ourseries)+1:] | ||
| 94 | lastlts = [k for k in previousseries if k in ltsseries] | ||
| 95 | |||
| 96 | print("Version calculated to be %s" % ourversion) | ||
| 97 | print("Release series calculated to be %s" % ourseries) | ||
| 98 | |||
| 99 | replacements = { | ||
| 100 | "DISTRO" : ourversion, | ||
| 101 | "DISTRO_NAME_NO_CAP" : ourseries, | ||
| 102 | "DISTRO_NAME" : ourseries.capitalize(), | ||
| 103 | "DISTRO_NAME_NO_CAP_MINUS_ONE" : previousseries[0], | ||
| 104 | "DISTRO_NAME_NO_CAP_LTS" : lastlts[0], | ||
| 105 | "YOCTO_DOC_VERSION" : ourversion, | ||
| 106 | "DISTRO_REL_TAG" : "yocto-" + ourversion, | ||
| 107 | } | ||
| 108 | |||
| 109 | with open("poky.yaml.in", "r") as r, open("poky.yaml", "w") as w: | ||
| 110 | lines = r.readlines() | ||
| 111 | for line in lines: | ||
| 112 | data = line.split(":") | ||
| 113 | k = data[0].strip() | ||
| 114 | if k in replacements: | ||
| 115 | w.write("%s : \"%s\"\n" % (k, replacements[k])) | ||
| 116 | else: | ||
| 117 | w.write(line) | ||
| 118 | |||
| 119 | print("poky.yaml generated from poky.yaml.in") | ||
| 120 | |||
