All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: docs@lists.yoctoproject.org
Subject: [PATCH 1/5] Makefile/set_versions: Allow poky.yaml to be autogenerated
Date: Mon, 21 Mar 2022 17:44:51 +0000	[thread overview]
Message-ID: <20220321174455.1189669-2-richard.purdie@linuxfoundation.org> (raw)
In-Reply-To: <20220321174455.1189669-1-richard.purdie@linuxfoundation.org>

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.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 documentation/.gitignore                  |   1 +
 documentation/Makefile                    |   1 +
 documentation/{poky.yaml => poky.yaml.in} |   0
 documentation/set_versions.py             | 115 ++++++++++++++++++++++
 4 files changed, 117 insertions(+)
 rename documentation/{poky.yaml => poky.yaml.in} (100%)
 create mode 100755 documentation/set_versions.py

diff --git a/documentation/.gitignore b/documentation/.gitignore
index 35ead8af6..e5e2c1708 100644
--- a/documentation/.gitignore
+++ b/documentation/.gitignore
@@ -1,5 +1,6 @@
 _build/
 Pipfile.lock
+poky.yaml
 .vscode/
 */svg/*.png
 */svg/*.pdf
diff --git a/documentation/Makefile b/documentation/Makefile
index f04f381bd..bec53399c 100644
--- a/documentation/Makefile
+++ b/documentation/Makefile
@@ -57,4 +57,5 @@ all: html epub latexpdf
 # Catch-all target: route all unknown targets to Sphinx using the new
 # "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
 %:
+	$(SOURCEDIR)/set_versions.py
 	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/documentation/poky.yaml b/documentation/poky.yaml.in
similarity index 100%
rename from documentation/poky.yaml
rename to documentation/poky.yaml.in
diff --git a/documentation/set_versions.py b/documentation/set_versions.py
new file mode 100755
index 000000000..266ccf464
--- /dev/null
+++ b/documentation/set_versions.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env python3
+#
+# Add version information to poky.yaml based upon current git branch/tags
+#
+# Copyright Linux Foundation
+# Author: Richard Purdie <richard.purdie@linuxfoundation.org>
+#
+# SPDX-License-Identifier: MIT
+#
+
+
+import subprocess
+import collections
+import sys
+
+devbranch = "kirkstone"
+#devbranch = "langdale"
+ltsseries = ["kirkstone", "dunfell"]
+
+release_series = collections.OrderedDict()
+#release_series["langdale"] = "4.1"
+release_series["kirkstone"] = "4.0"
+release_series["honister"] = "3.4"
+release_series["hardknott"] = "3.3"
+release_series["gatesgarth"] = "3.2"
+release_series["dunfell"] = "3.1"
+
+ourversion = None
+ourseries = None
+ourbranch = None
+
+# Test tags exist and inform the user to fetch if not
+try:
+    subprocess.run(["git", "show", "yocto-3.4.2"], capture_output=True, check=True)
+except subprocess.CalledProcessError:
+    sys.exit("Please run 'git fetch --tags' before building the documentation")
+
+# Try and figure out what we are
+tags = subprocess.run(["git", "tag", "--points-at", "HEAD"], capture_output=True, text=True).stdout
+for t in tags.split():
+    if t.startswith("yocto-"):
+        ourversion = t[6:]
+
+if ourversion:
+    # We're a tagged release
+    components = ourversion.split(".")
+    baseversion = components[0] + "." + components[1]
+    for i in release_series:
+        if release_series[i] == baseversion:
+            ourseries = i
+            ourbranch = i
+else:
+    # We're floating on a branch
+    branch = subprocess.run(["git", "branch", "--show-current"], capture_output=True, text=True).stdout.strip()
+    ourbranch = branch
+    if branch != "master" and branch not in release_series:
+        possible_branches = []
+        for b in release_series.keys():
+            result = subprocess.run(["git", "show-ref", "heads/" + b], capture_output=True, text=True)
+            if result.returncode == 0:
+                possible_branches.append(b)
+                continue
+            result = subprocess.run(["git", "show-ref", "origin/" + b], capture_output=True, text=True)
+            if result.returncode == 0:
+                possible_branches.append("origin/" + b)
+        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
+        branch = nearestbranch.split('[')[1].split('~')[0]
+        print("Nearest release branch esimtated to be %s" % branch)
+    if branch == "master":
+        ourseries = devbranch
+    elif branch in release_series:
+        ourseries = branch
+    else:
+        sys.exit("Unknown series for branch %s" % branch)
+
+    previoustags = subprocess.run(["git", "tag", "--merged", "HEAD"], capture_output=True, text=True).stdout
+    previoustags = [t[6:] for t in previoustags.split() if t.startswith("yocto-" + release_series[ourseries])]
+    futuretags = subprocess.run(["git", "tag", "--merged", ourbranch], capture_output=True, text=True).stdout
+    futuretags = [t[6:] for t in futuretags.split() if t.startswith("yocto-" + release_series[ourseries])]
+
+    # Append .999 against the last known version
+    if len(previoustags) != len(futuretags):
+        ourversion = previoustags[-1] + ".999"
+    else:
+        ourversion = release_series[ourseries] + ".999"
+
+series = [k for k in release_series]
+previousseries = series[series.index(ourseries)+1:]
+lastlts = [k for k in previousseries if k in ltsseries]
+
+print("Version calculated to be %s" % ourversion)
+print("Release series calculated to be %s" % ourseries)
+
+replacements = {
+    "DISTRO" : ourversion,
+    "DISTRO_NAME_NO_CAP" : ourseries,
+    "DISTRO_NAME" : ourseries.capitalize(),
+    "DISTRO_NAME_NO_CAP_MINUS_ONE" : previousseries[0],
+    "DISTRO_NAME_NO_CAP_LTS" : lastlts[0],
+    "YOCTO_DOC_VERSION" : ourversion,
+    "DISTRO_REL_TAG" : "yocto-" + ourversion,
+}
+
+with open("poky.yaml.in", "r") as r, open("poky.yaml", "w") as w:
+    lines = r.readlines()
+    for line in lines:
+        data = line.split(":")
+        k = data[0].strip()
+        if k in replacements:
+            w.write("%s : \"%s\"\n" % (k, replacements[k]))
+        else:
+            w.write(line)
+
+print("poky.yaml generated from poky.yaml.in")
+
-- 
2.32.0



  reply	other threads:[~2022-03-21 17:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21 17:44 [PATCH 0/5 v2] Proposed docs version changes Richard Purdie
2022-03-21 17:44 ` Richard Purdie [this message]
     [not found]   ` <86e1ecf9-09da-9cd7-347f-637628cbbba4@bootlin.com>
2022-03-23  9:59     ` [docs] [PATCH 1/5] Makefile/set_versions: Allow poky.yaml to be autogenerated Quentin Schulz
2022-03-21 17:44 ` [PATCH 2/5] conf.py/set_versions/poky.yaml: Set version in conf.py from poky.yaml Richard Purdie
2022-03-21 17:44 ` [PATCH 3/5] set_versions: Add support for setting POKYVERSION found in older releases Richard Purdie
2022-03-21 17:44 ` [PATCH 4/5] set_versions/switchers.js: Allow switchers.js version information to be autogenerated Richard Purdie
2022-03-21 17:44 ` [PATCH 5/5] set_versions: Various improvements Richard Purdie
2022-03-21 21:56 ` [docs] [PATCH 0/5 v2] Proposed docs version changes Nicolas Dechesne
     [not found]   ` <ea41470f551f80509c947bf074eee5b29777953e.camel@linuxfoundation.org>
2022-03-22 13:58     ` Quentin Schulz
2022-03-22 14:25       ` Richard Purdie
2022-03-22 14:33         ` Quentin Schulz
     [not found]           ` <5bdb0cfb67587ad347f17bb59b0ea1b3a3e110b4.camel@linuxfoundation.org>
2022-03-22 14:59             ` Quentin Schulz
     [not found]           ` <16DEBBB55476AD52.11857@lists.yoctoproject.org>
     [not found]             ` <7b263ab8905bc5fe6d2fe6c8cf65bf2583f9ac49.camel@linuxfoundation.org>
2022-03-23  0:47               ` Michael Halstead
2022-03-23 10:15                 ` Richard Purdie
2022-03-23 10:19 [PATCH 1/5] Makefile/set_versions: Allow poky.yaml to be autogenerated Richard Purdie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220321174455.1189669-2-richard.purdie@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=docs@lists.yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.