commit: 0ff49114cec79edce723da1190087a41699f6b2f Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Thu Jan 4 05:12:24 2024 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Thu Jan 4 06:13:25 2024 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=0ff49114
binarytree: Handle inject failures Capture stdout and stderr for logging purposes during binarytree inject calls, and use the inject return value to report success or failure. For failures prior to pkg_pretend, use an eerror/elog message to indicate that the binary package is not usable. Move corresponding elog_process call to a finally block so that it is called for all pkg_pretend failures. Bug: https://bugs.gentoo.org/921327 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> lib/_emerge/Binpkg.py | 34 ++++++++++++++++++++++++++++++---- lib/_emerge/BinpkgPrefetcher.py | 36 +++++++++++++++++++++++++++++------- lib/_emerge/Scheduler.py | 36 +++++++++++++++++++++++------------- 3 files changed, 82 insertions(+), 24 deletions(-) diff --git a/lib/_emerge/Binpkg.py b/lib/_emerge/Binpkg.py index 9b1036538a..299ae7fbc9 100644 --- a/lib/_emerge/Binpkg.py +++ b/lib/_emerge/Binpkg.py @@ -1,6 +1,8 @@ -# Copyright 1999-2023 Gentoo Authors +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 +import io +import sys import functools import _emerge.emergelog from _emerge.EbuildPhase import EbuildPhase @@ -244,12 +246,36 @@ class Binpkg(CompositeTask): pkg_count = self.pkg_count if self._fetched_pkg: - pkg_path = self._bintree.getname( - self._bintree.inject( + stdout_orig = sys.stdout + stderr_orig = sys.stderr + out = io.StringIO() + try: + sys.stdout = out + sys.stderr = out + + injected_pkg = self._bintree.inject( pkg.cpv, current_pkg_path=self._fetched_pkg, allocated_pkg_path=self._pkg_allocated_path, - ), + ) + finally: + sys.stdout = stdout_orig + sys.stderr = stderr_orig + + output_value = out.getvalue() + if output_value: + self.scheduler.output( + output_value, + log_path=self.settings.get("PORTAGE_LOG_FILE"), + background=self.background, + ) + + if injected_pkg is None: + self._async_unlock_builddir(returncode=1) + return + + pkg_path = self._bintree.getname( + injected_pkg, allocate_new=False, ) else: diff --git a/lib/_emerge/BinpkgPrefetcher.py b/lib/_emerge/BinpkgPrefetcher.py index 37dbe0a40f..ed68d2852c 100644 --- a/lib/_emerge/BinpkgPrefetcher.py +++ b/lib/_emerge/BinpkgPrefetcher.py @@ -1,6 +1,9 @@ -# Copyright 1999-2009 Gentoo Foundation +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 +import io +import sys + from _emerge.BinpkgFetcher import BinpkgFetcher from _emerge.CompositeTask import CompositeTask from _emerge.BinpkgVerifier import BinpkgVerifier @@ -45,12 +48,31 @@ class BinpkgPrefetcher(CompositeTask): self.wait() return - self._bintree.inject( - self.pkg.cpv, - current_pkg_path=self.pkg_path, - allocated_pkg_path=self.pkg_allocated_path, - ) + stdout_orig = sys.stdout + stderr_orig = sys.stderr + out = io.StringIO() + try: + sys.stdout = out + sys.stderr = out + + injected_pkg = self._bintree.inject( + self.pkg.cpv, + current_pkg_path=self.pkg_path, + allocated_pkg_path=self.pkg_allocated_path, + ) + + finally: + sys.stdout = stdout_orig + sys.stderr = stderr_orig + + output_value = out.getvalue() + if output_value: + self.scheduler.output( + output_value, + log_path=self.scheduler.fetch.log_file, + background=self.background, + ) self._current_task = None - self.returncode = os.EX_OK + self.returncode = 1 if injected_pkg is None else os.EX_OK self.wait() diff --git a/lib/_emerge/Scheduler.py b/lib/_emerge/Scheduler.py index 620d513511..ae01214d32 100644 --- a/lib/_emerge/Scheduler.py +++ b/lib/_emerge/Scheduler.py @@ -1,4 +1,4 @@ -# Copyright 1999-2023 Gentoo Authors +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 from collections import deque @@ -984,11 +984,19 @@ class Scheduler(PollScheduler): current_task = None if fetched: - bintree.inject( + if not bintree.inject( x.cpv, current_pkg_path=fetched, allocated_pkg_path=fetcher.pkg_allocated_path, - ) + ): + eerror( + "Binary package is not usable", + phase="pretend", + key=x.cpv, + ) + failures += 1 + self._record_pkg_failure(x, settings, 1) + continue infloc = os.path.join(build_dir_path, "build-info") ensure_dirs(infloc) @@ -1046,20 +1054,22 @@ class Scheduler(PollScheduler): if ret != os.EX_OK: failures += 1 self._record_pkg_failure(x, settings, ret) - portage.elog.elog_process(x.cpv, settings) finally: if current_task is not None: if current_task.isAlive(): current_task.cancel() - if current_task.returncode == os.EX_OK: - clean_phase = EbuildPhase( - background=False, - phase="clean", - scheduler=sched_iface, - settings=settings, - ) - clean_phase.start() - await clean_phase.async_wait() + + portage.elog.elog_process(x.cpv, settings) + + if current_task is not None and current_task.returncode == os.EX_OK: + clean_phase = EbuildPhase( + background=False, + phase="clean", + scheduler=sched_iface, + settings=settings, + ) + clean_phase.start() + await clean_phase.async_wait() await build_dir.async_unlock() self._deallocate_config(settings)
