diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-03-18 13:05:06 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-03-23 12:08:56 +0000 |
commit | 8d3e9aaede03f3615e5afb82df4d9b530a06a5f0 (patch) | |
tree | 15627829c6906f42a9002522606ffdb578ac2530 /documentation | |
parent | 93eb983e7936c7592588219e8a548da9b81bb5b2 (diff) | |
download | poky-8d3e9aaede03f3615e5afb82df4d9b530a06a5f0.tar.gz |
Makefile/set_versions: Allow poky.yaml to be autogenerated
Use a script to generate the branch/tag information inside poky.yaml.
If the branch isn't a known release branch, include git magic to find
the closest matching release branch we know about.
(From yocto-docs rev: 841e2df0e2e544b82fff9ddd0339a4e775148e3a)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'documentation')
-rw-r--r-- | documentation/.gitignore | 1 | ||||
-rw-r--r-- | documentation/Makefile | 1 | ||||
-rw-r--r-- | documentation/poky.yaml.in (renamed from documentation/poky.yaml) | 0 | ||||
-rwxr-xr-x | documentation/set_versions.py | 120 |
4 files changed, 122 insertions, 0 deletions
diff --git a/documentation/.gitignore b/documentation/.gitignore index 35ead8af66..e5e2c1708d 100644 --- a/documentation/.gitignore +++ b/documentation/.gitignore | |||
@@ -1,5 +1,6 @@ | |||
1 | _build/ | 1 | _build/ |
2 | Pipfile.lock | 2 | Pipfile.lock |
3 | poky.yaml | ||
3 | .vscode/ | 4 | .vscode/ |
4 | */svg/*.png | 5 | */svg/*.png |
5 | */svg/*.pdf | 6 | */svg/*.pdf |
diff --git a/documentation/Makefile b/documentation/Makefile index f04f381bd2..bec53399c0 100644 --- a/documentation/Makefile +++ b/documentation/Makefile | |||
@@ -57,4 +57,5 @@ all: html epub latexpdf | |||
57 | # Catch-all target: route all unknown targets to Sphinx using the new | 57 | # Catch-all target: route all unknown targets to Sphinx using the new |
58 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | 58 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). |
59 | %: | 59 | %: |
60 | $(SOURCEDIR)/set_versions.py | ||
60 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | 61 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
diff --git a/documentation/poky.yaml b/documentation/poky.yaml.in index 89a059ef1a..89a059ef1a 100644 --- a/documentation/poky.yaml +++ b/documentation/poky.yaml.in | |||
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 | |||