[4/5] set_versions/switchers.js: Allow switchers.js version information to be autogenerated

Message ID 20220323101957.1263785-4-richard.purdie@linuxfoundation.org
State New
Headers show
Series [1/5] Makefile/set_versions: Allow poky.yaml to be autogenerated | expand

Commit Message

Richard Purdie March 23, 2022, 10:19 a.m. UTC
A horrible blunt hammer approach to updating the version information in
switchers.js based on the available tag information.

To merge and work correctly, this will need a change to the autobuilder-helper
docs generation code to pull the swicthers.js and script from master, then
to run the script. That should hopefully remove the need for other patching
even on old docs branches though.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 documentation/.gitignore                      |  1 +
 documentation/set_versions.py                 | 19 +++++++++++++++++++
 .../{switchers.js => switchers.js.in}         |  8 +-------
 3 files changed, 21 insertions(+), 7 deletions(-)
 rename documentation/sphinx-static/{switchers.js => switchers.js.in} (97%)

Patch

diff --git a/documentation/.gitignore b/documentation/.gitignore
index e5e2c1708..096b97ec2 100644
--- a/documentation/.gitignore
+++ b/documentation/.gitignore
@@ -1,6 +1,7 @@ 
 _build/
 Pipfile.lock
 poky.yaml
+sphinx-static/switchers.js
 .vscode/
 */svg/*.png
 */svg/*.pdf
diff --git a/documentation/set_versions.py b/documentation/set_versions.py
index 96e0d3469..94e2704a5 100755
--- a/documentation/set_versions.py
+++ b/documentation/set_versions.py
@@ -149,3 +149,22 @@  with open("poky.yaml.in", "r") as r, open("poky.yaml", "w") as w:
 
 print("poky.yaml generated from poky.yaml.in")
 
+with open("sphinx-static/switchers.js.in", "r") as r, open("sphinx-static/switchers.js", "w") as w:
+    lines = r.readlines()
+    for line in lines:
+        if "VERSIONS_PLACEHOLDER" in line:
+            w.write("    'dev': 'dev (%s)',\n" % release_series[devbranch])
+            for branch in activereleases:
+                if branch == devbranch:
+                    continue
+                versions = subprocess.run('git tag --list yocto-%s*' % (release_series[branch]), shell=True, capture_output=True, text=True).stdout.split()
+                versions = sorted([v.replace("yocto-" +  release_series[branch] + ".", "").replace("yocto-" +  release_series[branch], "0") for v in versions], key=int)
+                version = release_series[branch]
+                if versions[-1] != "0":
+                    version = version + "." + versions[-1]
+                w.write("    '%s': '%s',\n" % (version, version))
+        else:
+            w.write(line)
+
+print("switchers.js generated from switchers.js.in")
+
diff --git a/documentation/sphinx-static/switchers.js b/documentation/sphinx-static/switchers.js.in
similarity index 97%
rename from documentation/sphinx-static/switchers.js
rename to documentation/sphinx-static/switchers.js.in
index af7e33490..5d3a4d793 100644
--- a/documentation/sphinx-static/switchers.js
+++ b/documentation/sphinx-static/switchers.js.in
@@ -10,13 +10,7 @@  by https://git.yoctoproject.org/yocto-autobuilder-helper/tree/scripts/run-docs-b
   'use strict';
 
   var all_versions = {
-    'dev': 'dev (3.5)',
-    '3.4.2': '3.4.2',
-    '3.3.5': '3.3.5',
-    '3.2.4': '3.2.4',
-    '3.1.15': '3.1.15',
-    '3.0.4': '3.0.4',
-    '2.7.4': '2.7.4',
+    VERSIONS_PLACEHOLDER
   };
 
   var all_doctypes = {