From patchwork Wed Mar 23 10:19:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 5740 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2285C433EF for ; Wed, 23 Mar 2022 10:20:01 +0000 (UTC) Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by mx.groups.io with SMTP id smtpd.web11.7449.1648030800636819219 for ; Wed, 23 Mar 2022 03:20:01 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=MAQB73Ih; spf=pass (domain: linuxfoundation.org, ip: 209.85.128.43, mailfrom: richard.purdie@linuxfoundation.org) Received: by mail-wm1-f43.google.com with SMTP id j13-20020a05600c1c0d00b0038c8f94aac2so4976519wms.3 for ; Wed, 23 Mar 2022 03:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=S0GFiPOOC0QPwfjVdx0apVoxxDvhS0pBVlBL74AnDAw=; b=MAQB73IhoULYdgdD6K/oUL+RpR83zSp00rFNnXQYWhd/od8B0c7RP/8J9wSAqImeqQ +7wP9UpsYi3IoR+7/pKG6JMR52UqaBW3vqJY8lBPAjmbihXv6PYa7jA/s5dkQnXWrSr8 5ql26lvLvc2RJdXLuR+DAm1uzKzY1xHNPwWAs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=S0GFiPOOC0QPwfjVdx0apVoxxDvhS0pBVlBL74AnDAw=; b=CEsQhGa0thgAkFv8j1xaJgWdcJ0DQYqzBJy9C1+DYaZy62Np1aK1R8nR0L9Zh7rIZY hhChVWCJlQbYKwdQZABU3LIjdB0tSGCSAUmzqsB6nXk77XV1yr8B4Hwe86zSh8XuE2EU bFFKtmZV/3Z0FNpYU4b7PTW22hbqrdjPpNE4wz+dXXqNM6cB8ZYcI2kvQUbQ5vR3avPZ UaSDpdrHQBTQggV7vFGhbzQlTppJwYO3q2L9Q5uriSPvrLMaVW2d7meVYsYN25qXLeL0 tUZzJbR8j8xAoO+4oxmPtKI2s6usRsOewT6y3JeBnhpdoa659Yx6vGjmX/rPhCpsYzKb KS+Q== X-Gm-Message-State: AOAM5311Fap/0OCgouThIddcgXuTZzmyGdOICAAw7nOlpXpAQTD+BKux md5Wpsl/enysiP9XYd+q4tevZL3xxChd9FC0 X-Google-Smtp-Source: ABdhPJxrxC66u+EXYlNFpisyeeKf+z476w0vE5VaEMvWyqpmW93Z1EzDf7klHKHfwKyMzJYflkr5GQ== X-Received: by 2002:a05:600c:600a:b0:38c:6c9e:f9c7 with SMTP id az10-20020a05600c600a00b0038c6c9ef9c7mr8287668wmb.26.1648030798401; Wed, 23 Mar 2022 03:19:58 -0700 (PDT) Received: from hex.int.rpsys.net ([2001:8b0:aba:5f3c:aaba:716e:9c38:ad87]) by smtp.gmail.com with ESMTPSA id x3-20020a5d6b43000000b001e317fb86ecsm18171336wrw.57.2022.03.23.03.19.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 03:19:57 -0700 (PDT) From: Richard Purdie To: docs@lists.yoctoproject.org Subject: [PATCH 1/5] Makefile/set_versions: Allow poky.yaml to be autogenerated Date: Wed, 23 Mar 2022 10:19:53 +0000 Message-Id: <20220323101957.1263785-1-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 23 Mar 2022 10:20:01 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/docs/message/2696 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 --- documentation/.gitignore | 1 + documentation/Makefile | 1 + documentation/{poky.yaml => poky.yaml.in} | 0 documentation/set_versions.py | 120 ++++++++++++++++++++++ 4 files changed, 122 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..d48b8b74c --- /dev/null +++ b/documentation/set_versions.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3 +# +# Add version information to poky.yaml based upon current git branch/tags +# +# Copyright Linux Foundation +# Author: Richard Purdie +# +# SPDX-License-Identifier: MIT +# + + +import subprocess +import collections +import sys + +ourversion = None +if len(sys.argv) == 2: + ourversion = sys.argv[1] + +activereleases = ["honister", "hardknott", "gatesgarth", "dunfell", "zeus", "warrior"] +#devbranch = "langdale" +devbranch = "kirkstone" +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") +