From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1601488-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 2A8CB15808B
	for <garchives@archives.gentoo.org>; Sun, 18 Feb 2024 02:19:45 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 31B83E29D3;
	Sun, 18 Feb 2024 02:19:44 +0000 (UTC)
Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 0B14EE29D3
	for <gentoo-commits@lists.gentoo.org>; Sun, 18 Feb 2024 02:19:44 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id EAAA7340943
	for <gentoo-commits@lists.gentoo.org>; Sun, 18 Feb 2024 02:19:42 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 5292D13DB
	for <gentoo-commits@lists.gentoo.org>; Sun, 18 Feb 2024 02:19:41 +0000 (UTC)
From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" <dolsen@gentoo.org>
Message-ID: <1708222563.70cb55fa5fd2af7c7e46c94dc423a96bbedd83a5.dolsen@gentoo>
Subject: [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/eclean/
X-VCS-Repository: proj/gentoolkit
X-VCS-Files: pym/gentoolkit/eclean/search.py
X-VCS-Directories: pym/gentoolkit/eclean/
X-VCS-Committer: dolsen
X-VCS-Committer-Name: Brian Dolbec
X-VCS-Revision: 70cb55fa5fd2af7c7e46c94dc423a96bbedd83a5
X-VCS-Branch: master
Date: Sun, 18 Feb 2024 02:19:41 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 7ba74e3c-28c2-4998-8e2d-70d76b348790
X-Archives-Hash: be71f365d75c6dd7ed1a13e97475fe7a

commit:     70cb55fa5fd2af7c7e46c94dc423a96bbedd83a5
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Feb  4 21:00:49 2024 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sun Feb 18 02:16:03 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=70cb55fa

eclean: Handle InvalidDepstring info in _deps_equal

Add try/except pair to _deps_equal() to output relavent details
causing the exception in order to aid the user to fix the issue.
Mark binpkg dep failures as a non match for possible deletion.
Make the ebuild dep failure a warning only, return True to save
the binpkg.
Add parameter docstring info

Bug: https://bugs.gentoo.org/923439
Signed-off-by: Brian Dolbec <dolsen <AT> gentoo.org>

 pym/gentoolkit/eclean/search.py | 54 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 48 insertions(+), 6 deletions(-)

diff --git a/pym/gentoolkit/eclean/search.py b/pym/gentoolkit/eclean/search.py
index 2eebcfd..47df3a1 100644
--- a/pym/gentoolkit/eclean/search.py
+++ b/pym/gentoolkit/eclean/search.py
@@ -17,6 +17,7 @@ import portage
 from portage.dep import Atom, use_reduce
 from portage.dep._slot_operator import strip_slots
 from portage.dep.libc import find_libc_deps, strip_libc_deps
+from portage.exception import InvalidDependString
 
 import gentoolkit.pprinter as pp
 from gentoolkit.eclean.exclude import (
@@ -526,13 +527,51 @@ class DistfilesSearch:
         return clean_me, saved
 
 
-def _deps_equal(deps_a, eapi_a, deps_b, eapi_b, libc_deps, uselist=None):
-    """Compare two dependency lists given a set of USE flags"""
+def _deps_equal(deps_a, eapi_a, deps_b, eapi_b, libc_deps, uselist=None, cpv=None):
+    """Compare two dependency lists given a set of USE flags
+
+    @param deps_a: binpkg DEPEND string (for InvalidDependString errors)
+    @rtype: string
+    @param eapi_a: EAPI
+    @rtype: string
+    @param deps_b: ebuild DEPEND string (for InvalidDependString errors)
+    @rtype: string
+    @param eapi_b: EAPI
+    @rtype: string
+    @param libc_deps: List of libc packages (or atoms if realized is passed).
+    @rtype: list
+    @param uselist: use flag list
+    @rtype: frozenset
+    @param cpv: Cat/Pkg-version
+    @rtype: string
+    """
     if deps_a == deps_b:
         return True
+    try:
+        deps_a = use_reduce(deps_a, uselist=uselist, eapi=eapi_a, token_class=Atom)
+    except InvalidDependString:  # the binpkg depend string is bad
+        print(
+            pp.warn(
+                "Warning: Invalid binpkg DEPEND string found for: %s, %s"
+                " | tagging for removal" % (cpv, deps_a)
+            ),
+            file=sys.stderr,
+        )
+        return False
+    try:
+        deps_b = use_reduce(deps_b, uselist=uselist, eapi=eapi_b, token_class=Atom)
+    except InvalidDependString as er:  # the ebuild depend string is bad
+        print(
+            pp.warn("Warning: Invalid ebuild DEPEND String found for: %s" % cpv),
+            file=sys.stderr,
+        )
+        print(
+            pp.warn("Warning: DEPEND string for ebuild: %s" % deps_b),
+            file=sys.stderr,
+        )
+        print(er, file=sys.stderr)
+        return True
 
-    deps_a = use_reduce(deps_a, uselist=uselist, eapi=eapi_a, token_class=Atom)
-    deps_b = use_reduce(deps_b, uselist=uselist, eapi=eapi_b, token_class=Atom)
     strip_libc_deps(deps_a, libc_deps)
     strip_libc_deps(deps_b, libc_deps)
     strip_slots(deps_a)
@@ -656,13 +695,16 @@ def findPackages(
             binpkg_metadata = dict(zip(keys, bin_dbapi.aux_get(cpv, keys)))
             ebuild_metadata = dict(zip(keys, port_dbapi.aux_get(cpv, keys)))
 
+            deps_binpkg = " ".join(binpkg_metadata[key] for key in dep_keys)
+            deps_ebuild = " ".join(ebuild_metadata[key] for key in dep_keys)
             if _deps_equal(
-                " ".join(binpkg_metadata[key] for key in dep_keys),
+                deps_binpkg,
                 binpkg_metadata["EAPI"],
-                " ".join(ebuild_metadata[key] for key in dep_keys),
+                deps_ebuild,
                 ebuild_metadata["EAPI"],
                 libc_deps,
                 frozenset(binpkg_metadata["USE"].split()),
+                cpv,
             ):
                 continue