Skip to contentSkip to conversation

add basic b4 config file

PATCH In review Quentin Schulz 2 participants 4 messages Feb 5, 2025

lore
Share & tools
lore
#0 lore raw

v4 cover add basic b4 config file

This adds very basic support for using b4 in OE-Core. This essentially just automatically adds the proper mailing list when running b4 prep --auto-to-cc.

This also adds the b4 wrapper script that poky will need to use in order to identify which mailing list a patch needs to be sent to and do some additional per-patch checks that aren't necessary when running from vanilla OE-Core.

Once this is merged, poky will need to merge OE-Core into itself and override with its own .b4-config that makes use of that script.

---
Changes in v4:
- replace subprocess.call calling "which lsdiff" with shutil.which("lsdiff") so it is supported by more systems,
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- populate To recipient list instead of Cc to follow what's asked in our READMEs,
- put yocto-docs ML in Cc if there's a patch to bitbake/doc directory,
- the wrapper script needed to be adapted to handle both Cc and To recipient lists,
- explicit that an address can only appear once and the recipient list it'll make it to is the one appropriate for the first patch that needs to be sent to it,
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- add mention to first patch that running patchtest for b4 prep --check
is what we're eventually aiming for,
- add poky b4 wrapper script (it used to be in the patch series for
poky, c.f. https://lore.kernel.org/poky/[email protected]/T/#m95d6aa25cc42352416da477cf07d7b3cbd671231
- poky b4 wrapper script properly identifies patches with files modified
in both OE-Core and other repos part of poky,
- poky b4 wrapper script pretty prints when there's more than one
project modified by a script, instead of lazily printing a Python
list,
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Quentin Schulz (2):
add basic b4 config file
scripts: add b4-wrapper for poky

 .b4-config                 |   3 +
 scripts/b4-wrapper-poky.py | 178 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 181 insertions(+)

---
base-commit: 7e2d743e4809d6cbaa8e441dc42624eb65daad63
change-id: 20250117-b4-support-10de313f53b7

Best regards,

Signature · 1 line
Quentin Schulz <[email protected]>
#1 lore raw

PATCH v4 1/2 add basic b4 config file

From: Quentin Schulz <[email protected]>

b4[1] is a very nice tool for mail-based contribution. A config[2] file exists to set up a few defaults. We can use it to set the Cc recipients to always add, in our case the mailing list.

Because we do not have anything to check for now, disable needs-checking so patches can be sent without running b4 prep --check. The mid-term/long-term plan is to use patchtest locally.

Because we do not have any auto-to-cc support (and the implicit one using scripts/get_maintainer.pl cannot work for us), also disable needs-auto-to-cc so patches can be sent without running b4 prep --auto-to-cc.

[1] https://pypi.org/project/b4/
[2] https://b4.docs.kernel.org/en/latest/config.html

---
 .b4-config | 3 +++
 1 file changed, 3 insertions(+)
.b4-config new file +3 -0
new file mode 100644
index 0000000000000000000000000000000000000000..41094218531d638457a265721fb928697d0ee9de
@@ -0,0 +1,3 @@
+[b4]
+  send-series-to = [email protected]
+  prep-pre-flight-checks = disable-needs-auto-to-cc, disable-needs-checking
Signature · 1 line
2.48.1
#2 lore raw

Patchtest results for [PATCH v4 1/2] add basic b4 config file

Thank you for your submission. Patchtest identified one or more issues with the patch. Please see the log below for more information:

---
Testing patch /home/patchtest/share/mboxes/v4-1-2-add-basic-b4-config-file.patch

FAIL: test shortlog format: Commit shortlog (first line of commit message) should follow the format "<target>: <summary>" (test_mbox.TestMbox.test_shortlog_format)

PASS: test Signed-off-by presence (test_mbox.TestMbox.test_signed_off_by_presence)
PASS: test author valid (test_mbox.TestMbox.test_author_valid)
PASS: test commit message presence (test_mbox.TestMbox.test_commit_message_presence)
PASS: test commit message user tags (test_mbox.TestMbox.test_commit_message_user_tags)
PASS: test max line length (test_metadata.TestMetadata.test_max_line_length)
PASS: test mbox format (test_mbox.TestMbox.test_mbox_format)
PASS: test non-AUH upgrade (test_mbox.TestMbox.test_non_auh_upgrade)
PASS: test shortlog length (test_mbox.TestMbox.test_shortlog_length)
PASS: test target mailing list (test_mbox.TestMbox.test_target_mailing_list)

SKIP: pretest pylint: No python related patches, skipping test (test_python_pylint.PyLint.pretest_pylint)
SKIP: pretest src uri left files: No modified recipes, skipping pretest (test_metadata.TestMetadata.pretest_src_uri_left_files)
SKIP: test CVE check ignore: No modified recipes or older target branch, skipping test (test_metadata.TestMetadata.test_cve_check_ignore)
SKIP: test CVE tag format: No new CVE patches introduced (test_patch.TestPatch.test_cve_tag_format)
SKIP: test Signed-off-by presence: No new CVE patches introduced (test_patch.TestPatch.test_signed_off_by_presence)
SKIP: test Upstream-Status presence: No new CVE patches introduced (test_patch.TestPatch.test_upstream_status_presence_format)
SKIP: test bugzilla entry format: No bug ID found (test_mbox.TestMbox.test_bugzilla_entry_format)
SKIP: test lic files chksum modified not mentioned: No modified recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_modified_not_mentioned)
SKIP: test lic files chksum presence: No added recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_presence)
SKIP: test license presence: No added recipes, skipping test (test_metadata.TestMetadata.test_license_presence)
SKIP: test pylint: No python related patches, skipping test (test_python_pylint.PyLint.test_pylint)
SKIP: test series merge on head: Merge test is disabled for now (test_mbox.TestMbox.test_series_merge_on_head)
SKIP: test src uri left files: No modified recipes, skipping pretest (test_metadata.TestMetadata.test_src_uri_left_files)
SKIP: test summary presence: No added recipes, skipping test (test_metadata.TestMetadata.test_summary_presence)

---

Please address the issues identified and
submit a new revision of the patch, or alternatively, reply to this email with an explanation of why the patch should be accepted. If you believe these results are due to an error in patchtest, please submit a bug at https://bugzilla.yoctoproject.org/ (use the 'Patchtest' category under 'Yocto Project Subprojects'). For more information on specific failures, see: https://wiki.yoctoproject.org/wiki/Patchtest. Thank you!

#3 lore raw

PATCH v4 2/2 scripts: add b4-wrapper for poky

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

poky is a combo-layer containing BitBake, OpenEmbedded-Core and Yocto Documentation source code into one big repo. It is not uncommon to have people develop patches for either of those projects from a poky git repo.
However, it is unlikely those patches are to be sent to the poky mailing list as very few files contained in the poky git repo actually are poky-specific. So we need a way to identify to which mailing list a patch is destined to be sent.
Additionally, because the source code in openembedded-core is merged/imported at the root of the git repo of poky, its .b4-config introduced in the previous commit will be used if not overridden (which will be done in a separate commit specific to the poky git repo). We need to provide a different .b4-config in poky.

Therefore, this wrapper is used to identify automatically which mailing list a patch series needs to be sent to (via b4 prep --auto-to-cc) and does some additional checks (via b4 prep --check) such as making sure a patch doesn't modify two different projects at the same time or that multiple projects are modified by different patches in the same patch series.

This wrapper script is meant to be used by poky's .b4-config. Ideally the b4 prep --check part could be offloaded to patchtest once it supports running on source different from OE-Core.

Note that b4 makes sure that an address doesn't appear twice in the recipient list. There's also no priority in the type of recipient list, so if the address appears first in Cc and then in To, only the Cc will be added. The opposite is true as well.

---
 scripts/b4-wrapper-poky.py | 178 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 178 insertions(+)
scripts/b4-wrapper-poky.py new file +178 -0
new file mode 100755
index 0000000000000000000000000000000000000000..30a7b95ff3acda5e56cab8ad15a2713f11e2feec
@@ -0,0 +1,178 @@
+#!/usr/bin/env python3
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+# This script is to be called by b4:
+# - through the b4.prep-perpatch-check-cmd with "prep-perpatch-check-cmd" as
+#   first argument,
+# - through b4.send-auto-cc-cmd with "send-auto-cc-cmd" as first argument,
+# - through b4.send-auto-to-cmd with "send-auto-to-cmd" as first argument,
+#
+# When prep-perpatch-check-cmd is passsed:
+#
+#  This checks that a patch makes changes to at most one project in the poky
+#  combo repo (that is, out of yocto-docs, bitbake, openembedded-core combined
+#  into poky and the poky-specific files).
+#
+#  Printing something to stdout in this file will result in b4 prep --check fail
+#  for the currently parsed patch.
+#
+#  It checks that all patches in the series make changes to at most one project.
+#
+# When send-auto-cc-cmd is passed:
+#
+#  This returns the list of Cc recipients for a patch.
+#
+# When send-auto-to-cmd is passed:
+#
+#  This returns the list of To recipients for a patch.
+#
+# This script takes as stdin a patch.
+
+import pathlib
+import re
+import shutil
+import subprocess
+import sys
+
+cmd = sys.argv[1]
+
+patch = sys.stdin.readlines()
+
+# Subject field is used to identify the last patch as this script is called for
+# each patch. We edit the same file in a series by using the References field
+# unique identifier to check which projects are modified by earlier patches in
+# the series. To avoid cluttering the disk, the last patch in the list removes
+# that shared file.
+re_subject = re.compile(r'^Subject:.*\[.*PATCH.*\s(\d+)/\1')
+re_ref = re.compile(r'^References: <(.*)>$')
+
+subject = None
+ref = None
+
+if not shutil.which("lsdiff"):
+    print("lsdiff missing from host, please install patchutils")
+    sys.exit(-1)
+
+try:
+    one_patch_series = False
+    for line in patch:
+        subject = re_subject.match(line)
+        if subject:
+            # Handle [PATCH 1/1]
+            if subject.group(1) == 1:
+                one_patch_series = True
+            break
+        if re.match(r'^Subject: .*\[.*PATCH[^/]*\]', line):
+            # Single patch is named [PATCH] but if there are prefix, it could be
+            # [PATCH prefix], so handle everything that doesn't have a /
+            # character which is used as separator between current patch number
+            # and total patch number
+            one_patch_series = True
+            break
+
+    if cmd == "prep-perpatch-check-cmd" and not one_patch_series:
+        for line in patch:
+            ref = re_ref.match(line)
+            if ref:
+                break
+
+        if not ref:
+            print("Failed to find ref to cover letter (References:)...")
+            sys.exit(-2)
+
+        ref = ref.group(1)
+        series_check = pathlib.Path(f".tmp-{ref}")
+
+    patch = "".join(patch)
+
+    if cmd == "send-auto-cc-cmd":
+        # Patches to BitBake documentation should also go to yocto-docs mailing list
+        project_paths = {
+                "yocto-docs": ["bitbake/doc/*"],
+        }
+    else:
+        project_paths = {
+                "bitbake": ["bitbake/*"],
+                "yocto-docs": ["documentation/*"],
+                "poky": [
+                    "meta-poky/*",
+                    "meta-yocto-bsp/*",
+                    "README.hardware.md",
+                    "README.poky.md",
+                    ],
+        }
+
+    # List of projects touched by this patch
+    projs = []
+
+    # Any file not matched by any path in project_paths means it is from
+    # OE-Core.
+    # When matching some path in project_paths, remove the matched files from
+    # that list.
+    files_left = subprocess.check_output(["lsdiff", "--strip-match=1", "--strip=1"],
+                                         input=patch, text=True)
+    files_left = set(files_left)
+
+    for proj, proj_paths in project_paths.items():
+        lsdiff_args = [f"--include={path}" for path in proj_paths]
+        files = subprocess.check_output(["lsdiff", "--strip-match=1", "--strip=1"] + lsdiff_args,
+                                        input=patch, text=True)
+        if len(files):
+            files_left = files_left - set(files)
+            projs.append(proj)
+            continue
+
+        # Handle patches made with --no-prefix
+        files = subprocess.check_output(["lsdiff"] + lsdiff_args,
+                                        input=patch, text=True)
+        if len(files):
+            files_left = files_left - set(files)
+            projs.append(proj)
+
+    # Catch-all for everything not poky-specific or in bitbake/yocto-docs
+    if len(files_left) and cmd != "send-auto-cc-cmd":
+        projs.append("openembedded-core")
+
+    if cmd == "prep-perpatch-check-cmd":
+        if len(projs) > 1:
+            print(f"Diff spans more than one project ({', '.join(sorted(projs))}), split into multiple commits...")
+            sys.exit(-3)
+
+        # No need to check other patches in the series as there aren't any
+        if one_patch_series:
+            sys.exit(0)
+
+        # This should be replaced once b4 supports prep-perseries-check-cmd (or something similar)
+
+        if series_check.exists():
+            # NOT race-free if b4 decides to parallelize prep-perpatch-check-cmd
+            series_projs = series_check.read_text().split('\n')
+        else:
+            series_projs = []
+
+        series_projs += projs
+        uniq_series_projs = set(series_projs)
+        # NOT race-free, if b4 decides to parallelize prep-perpatch-check-cmd
+        series_check.write_text('\n'.join(uniq_series_projs))
+
+        if len(uniq_series_projs) > 1:
+            print(f"Series spans more than one project ({', '.join(sorted(uniq_series_projs))}), split into multiple series...")
+            sys.exit(-4)
+    else:  # send-auto-cc-cmd / send-auto-to-cmd
+        ml_projs = {
+            "bitbake": "[email protected]",
+            "yocto-docs": "[email protected]",
+            "poky": "[email protected]",
+            "openembedded-core": "[email protected]",
+        }
+
+        print("\n".join([ml_projs[ml] for ml in projs]))
+
+    sys.exit(0)
+finally:
+    # Last patch in the series, cleanup tmp file
+    if subject and ref and series_check.exists():
+        series_check.unlink()
Signature · 1 line
2.48.1