commit:     3a9f2c09eb75f47cf3ae15fa4ebe671548a66870
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jun  3 01:18:44 2024 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jun  3 01:55:08 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3a9f2c09

Add binpkgs info to mtimedb resume data

In order to fix emerge --resume and --keep-going to make
appropriate binary package selections, store a list of
binpkgs in the resume data. By adding the data as a new
key which older versions of portage will ignore, the
extension is backward compatible.

Without this fix, emerge --resume and --keep-going make
poor package selection choices which do not account for
the --binpkg-respect-use option.

Bug: https://bugs.gentoo.org/933442
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/_emerge/Scheduler.py               | 13 +++++++++++++
 lib/_emerge/actions.py                 |  7 +++++++
 lib/_emerge/depgraph.py                | 21 +++++++++++++++++++++
 lib/portage/tests/util/test_mtimedb.py | 30 +++++++++++++++++++++++++-----
 4 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/lib/_emerge/Scheduler.py b/lib/_emerge/Scheduler.py
index d913cd2dc6..614df9e783 100644
--- a/lib/_emerge/Scheduler.py
+++ b/lib/_emerge/Scheduler.py
@@ -2116,6 +2116,19 @@ class Scheduler(PollScheduler):
             for x in self._mergelist
             if isinstance(x, Package) and x.operation == "merge"
         ]
+        # Store binpkgs using the same keys as $PKGDIR/Packages plus EROOT.
+        mtimedb["resume"]["binpkgs"] = [
+            {
+                "CPV": str(x.cpv),
+                "BUILD_ID": x.cpv.build_id,
+                "BUILD_TIME": x.cpv.build_time,
+                "MTIME": x.cpv.mtime,
+                "SIZE": x.cpv.file_size,
+                "EROOT": x.root,
+            }
+            for x in self._mergelist
+            if isinstance(x, Package) and x.type_name == "binary"
+        ]
 
         mtimedb.commit()
 

diff --git a/lib/_emerge/actions.py b/lib/_emerge/actions.py
index 512e470ad6..43d936fd14 100644
--- a/lib/_emerge/actions.py
+++ b/lib/_emerge/actions.py
@@ -216,6 +216,13 @@ def action_build(
         if not isinstance(favorites, list):
             del mtimedb[k]
             continue
+        binpkgs = resume_data.get("binpkgs")
+        if binpkgs and (
+            not isinstance(binpkgs, list)
+            or any(not isinstance(x, dict) for x in binpkgs)
+        ):
+            del mtimedb[k]
+            continue
 
     resume = False
     if "--resume" in myopts and ("resume" in mtimedb or "resume_backup" in 
mtimedb):

diff --git a/lib/_emerge/depgraph.py b/lib/_emerge/depgraph.py
index 3adc04bcfb..a05404d9c2 100644
--- a/lib/_emerge/depgraph.py
+++ b/lib/_emerge/depgraph.py
@@ -11066,6 +11066,13 @@ class depgraph:
         else:
             args = []
 
+        binpkgs_map = {}
+        binpkgs = resume_data.get("binpkgs")
+        if binpkgs:
+            for x in binpkgs:
+                if isinstance(x, dict) and "EROOT" in x and "CPV" in x:
+                    binpkgs_map[(x["EROOT"], x["CPV"])] = x
+
         serialized_tasks = []
         masked_tasks = []
         for x in mergelist:
@@ -11096,8 +11103,22 @@ class depgraph:
             except InvalidAtom:
                 continue
 
+            if pkg_type == "binary":
+                binpkg_info = binpkgs_map.get((myroot, pkg_key))
+            else:
+                binpkg_info = False
+
             pkg = None
             for pkg in self._iter_match_pkgs(root_config, pkg_type, atom):
+                if binpkg_info:
+                    if not (
+                        pkg.cpv.build_id == binpkg_info.get("BUILD_ID")
+                        and pkg.cpv.build_time == binpkg_info.get("BUILD_TIME")
+                        and pkg.cpv.mtime == binpkg_info.get("MTIME")
+                        and pkg.cpv.file_size == binpkg_info.get("SIZE")
+                    ):
+                        continue
+
                 if not self._pkg_visibility_check(
                     pkg
                 ) or self._frozen_config.excluded_pkgs.findAtomForPackage(

diff --git a/lib/portage/tests/util/test_mtimedb.py 
b/lib/portage/tests/util/test_mtimedb.py
index d80b4f1daf..6e3c2bee76 100644
--- a/lib/portage/tests/util/test_mtimedb.py
+++ b/lib/portage/tests/util/test_mtimedb.py
@@ -1,4 +1,4 @@
-# Copyright 2022 Gentoo Foundation
+# Copyright 2022-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 from unittest.mock import patch, mock_open
@@ -30,6 +30,16 @@ _ONE_RESUME_LIST_JSON = b"""{
                "/usr/local/lib64": 1711784303
        },
        "resume": {
+               "binpkgs": [
+                       {
+                               "CPV": "another-cat/another-package-4.3.2-r1",
+                               "BUILD_ID": 1,
+                               "BUILD_TIME": 1710959527,
+                               "MTIME": 1710966082,
+                               "SIZE": 20480,
+                               "EROOT": "/"
+                       }
+               ],
                "favorites": [
                        "@world"
                ],
@@ -41,7 +51,7 @@ _ONE_RESUME_LIST_JSON = b"""{
                                "merge"
                        ],
                        [
-                               "ebuild",
+                               "binary",
                                "/",
                                "another-cat/another-package-4.3.2-r1",
                                "merge"
@@ -66,7 +76,7 @@ _ONE_RESUME_LIST_JSON = b"""{
                "/var/db/repos/gentoo/profiles/updates/2Q-2022": 1752846209,
                "/var/db/repos/gentoo/profiles/updates/4Q-2021": 1742787797
        },
-       "version": "3.0.30"
+       "version": "3.0.65"
 }
 """
 
@@ -259,10 +269,20 @@ class MtimeDBTestCase(TestCase):
         self.assertEqual(
             mtimedb["resume"],
             {
+                "binpkgs": [
+                    {
+                        "CPV": "another-cat/another-package-4.3.2-r1",
+                        "BUILD_ID": 1,
+                        "BUILD_TIME": 1710959527,
+                        "MTIME": 1710966082,
+                        "SIZE": 20480,
+                        "EROOT": "/",
+                    }
+                ],
                 "favorites": ["@world"],
                 "mergelist": [
                     ["ebuild", "/", "some-cat/some-package-1.2.3-r4", "merge"],
-                    ["ebuild", "/", "another-cat/another-package-4.3.2-r1", 
"merge"],
+                    ["binary", "/", "another-cat/another-package-4.3.2-r1", 
"merge"],
                 ],
                 "myopts": {
                     "--buildpkg": True,
@@ -287,7 +307,7 @@ class MtimeDBTestCase(TestCase):
                 "/var/db/repos/gentoo/profiles/updates/4Q-2021": 1742787797,
             },
         )
-        self.assertEqual(mtimedb["version"], "3.0.30")
+        self.assertEqual(mtimedb["version"], "3.0.65")
 
     @patch("portage.util.mtimedb.MtimeDB._MtimeDB__write_to_disk")
     def test_commit_writes_to_disk_if_needed_and_possible(self, pwrite2disk):

Reply via email to