Skip to contentSkip to conversation

steps: refactor _get_changelog to update pkg_ctx

PATCH In review [email protected] 2 participants 4 messages Oct 26 – Oct 27

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 steps: refactor _get_changelog to update pkg_ctx

From: Daniel Turull <[email protected]>

Keep the handling of devtool's changelog output in one place instead of splitting it between _get_changelog() and its caller.

No functional change.

Assisted-by kiro:claude-sonnet-5.5

---
Changes in v3:
- New patch: refactor split out of "steps: skip changelog in commit message when devtool flags it"

---
 modules/steps.py | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
modules/steps.py +11 -10
index e678a4b..0dc365c 100644
@@ -80,20 +80,23 @@ def _make_commit_msg(group):
     versions = list(dict.fromkeys(_get_version(p) for p in group['pkgs']))
     return "{}: upgrade {}".format(pn, ",".join(versions))
 
-def _get_changelog(pn, workdir):
-    """Read the changelog generated by devtool upgrade and copy it to workdir.
-    Returns the changelog text or None."""
-    changelog_path = os.path.join(os.environ.get('BUILDDIR', ''),
-                                  'workspace', 'changelogs', '{}.txt'.format(pn))
+def _get_changelog(pkg_ctx, workdir):
+    """Copy the changelog generated by devtool upgrade to workdir and
+    store the changelog data in pkg_ctx."""
+    pn = pkg_ctx['PN']
+    base_path = os.path.join(os.environ.get('BUILDDIR', ''),
+                             'workspace', 'changelogs', pn)
+    changelog_path = base_path + '.txt'
     if os.path.isfile(changelog_path):
         try:
             with open(changelog_path, 'r', encoding='utf-8', errors='replace') as f:
                 text = f.read()
             shutil.copy2(changelog_path, os.path.join(workdir, '{}-changelog.txt'.format(pn)))
-            return text
         except OSError as e:
             W('Failed to copy changelog for {}: {}'.format(pn, e))
-    return None
+            return
+        if text:
+            pkg_ctx['changelog_text'] = text
 
 
 def _append_changelog_to_commit_msg(group, opts):
@@ -119,9 +122,7 @@ def _devtool_upgrade(devtool, bb, git, opts, pkg_ctx, workdir):
         devtool_output = devtool.upgrade(pkg_ctx['PN'], pkg_ctx['NPV'], pkg_ctx['NSRCREV'])
         D(" 'devtool upgrade' printed:\n%s" %(devtool_output))
         # Copy changelog before checking for conflicts — it's useful even on failure
-        changelog_text = _get_changelog(pkg_ctx['PN'], workdir)
-        if changelog_text:
-            pkg_ctx['changelog_text'] = changelog_text
+        _get_changelog(pkg_ctx, workdir)
         # If devtool failed to rebase patches, it does not fail, but we should
         if 'conflict' in devtool_output:
             raise DevtoolError("Running 'devtool upgrade' for recipe %s failed." %(pkg_ctx['PN']), devtool_output)
#1 lore raw

PATCH v3 2/2 steps: skip changelog in commit message when devtool flags it

From: Daniel Turull <[email protected]>

Some upstream changelogs are badly formed for a commit message (e.g. mesa, gstreamer release notes, raw git log dumps) and make the upgrade commits hard to read. 'devtool upgrade' now flags these, driven by RECIPE_UPGRADE_CHANGELOG_SKIP in OE-Core, so honour that and leave them out of the commit message. The changelog is still attached to the AUH email, so the information is not lost.

Older devtool does not write the flag, and treating it as absent keeps the current behaviour there.

This depends on the OE-Core patch "devtool: upgrade: flag badly formed changelogs in metadata".

Assisted-by kiro:claude-sonnet-5.5

---
Changes in v3:
- Parse the devtool metadata JSON once and keep it in pkg_ctx['changelog_metadata'] instead of reading it in a separate _changelog_skip() helper (Alexander)
- Split the _get_changelog() refactor into a separate patch

---
 modules/steps.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
modules/steps.py +16 -0
index 0dc365c..4ab9272 100644
@@ -19,6 +19,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 
+import json
 import os
 import shutil
 import re
@@ -80,6 +81,16 @@ def _make_commit_msg(group):
     versions = list(dict.fromkeys(_get_version(p) for p in group['pkgs']))
     return "{}: upgrade {}".format(pn, ",".join(versions))
 
+def _get_changelog_metadata(metadata_path):
+    """Return the metadata devtool wrote next to the changelog, or an
+    empty dict if it is missing or unreadable (e.g. older devtool)."""
+    try:
+        with open(metadata_path, 'r', encoding='utf-8') as f:
+            return json.load(f)
+    except (OSError, ValueError):
+        return {}
+
+
 def _get_changelog(pkg_ctx, workdir):
     """Copy the changelog generated by devtool upgrade to workdir and
     store the changelog data in pkg_ctx."""
@@ -97,6 +108,7 @@ def _get_changelog(pkg_ctx, workdir):
             return
         if text:
             pkg_ctx['changelog_text'] = text
+            pkg_ctx['changelog_metadata'] = _get_changelog_metadata(base_path + '.json')
 
 
 def _append_changelog_to_commit_msg(group, opts):
@@ -105,6 +117,10 @@ def _append_changelog_to_commit_msg(group, opts):
     for p in group['pkgs']:
         if 'changelog_text' not in p:
             continue
+        # Changelog stays attached to the email, only the commit message skips it
+        if p['changelog_metadata'].get('changelog_skip'):
+            I(" %s: changelog not added to commit message (RECIPE_UPGRADE_CHANGELOG_SKIP)" % p['PN'])
+            continue
         text = p['changelog_text'].strip()
         # Group recipes may share a source and produce identical changelogs
         # (e.g. mesa, mesa-native); skip proven duplicates, keep the rest.
#2 lore raw
In reply to [email protected]
Quoted 16 lines
modules/steps.py +7 -0
+def _get_changelog(pkg_ctx, workdir):
+    """Copy the changelog generated by devtool upgrade to workdir and
+    store the changelog data in pkg_ctx."""
+    pn = pkg_ctx['PN']
+    base_path = os.path.join(os.environ.get('BUILDDIR', ''),
+                             'workspace', 'changelogs', pn)
+    changelog_path = base_path + '.txt'
     if os.path.isfile(changelog_path):
         try:
             with open(changelog_path, 'r', encoding='utf-8',

errors='replace') as f:

                 text = f.read()
             shutil.copy2(changelog_path, os.path.join(workdir,

'{}-changelog.txt'.format(pn)))

modules/steps.py def _make_commit_msg(group): · line 99

Quoted 7 lines
modules/steps.py +3 -2
-            return text
         except OSError as e:
             W('Failed to copy changelog for {}: {}'.format(pn, e))
-    return None
+            return
+        if text:
+            pkg_ctx['changelog_text'] = text

Apologies, that's not quite what I had in mind. The intended suggestion was to read the json once, and assign all of its fields as a property of pkg_ctx. Then when the actual changelog content is needed, it would be obtained through fields of that property, since it already contains the filename of the actual text.

Alex

#3 lore raw
Quoted 23 lines · Alexander Kanavin
Quoted 11 lines

+def _get_changelog(pkg_ctx, workdir):
+    """Copy the changelog generated by devtool upgrade to workdir and +    store the changelog data in pkg_ctx."""
+    pn = pkg_ctx['PN']
+    base_path = os.path.join(os.environ.get('BUILDDIR', ''),
+                             'workspace', 'changelogs', pn)
+    changelog_path = base_path + '.txt'
     if os.path.isfile(changelog_path):
         try:
             with open(changelog_path, 'r', encoding='utf-8', errors='replace') as f:
                 text = f.read()

Quoted 10 lines

             shutil.copy2(changelog_path, os.path.join(workdir, '{}-changelog.txt'.format(pn))) -            return text
         except OSError as e:
             W('Failed to copy changelog for {}: {}'.format(pn, e))
-    return None
+            return
+        if text:
+            pkg_ctx['changelog_text'] = text

Quoted 2 lines

Apologies, that's not quite what I had in mind. The intended suggestion was to read the json once, and assign all of its fields as a property of pkg_ctx. Then when the actual changelog content is needed, it would be obtained through fields of that property, since it already contains the filename of the actual text.

No worries. I'll send a v4 reading the json at the begining of processing the recipe.

Daniel