From 6ce2be8d454f95c508d9f547d13487f9de863bdd Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 3 Mar 2024 11:53:11 -0800 Subject: _validate_deps: Discard configdict["pkg"]["USE"] Since configdict["pkg"]["USE"] may contain package.use settings from config.setcpv, it is inappropriate to use here (bug 675748), so discard it. This is only an issue because configdict["pkg"] is a sub-optimal place to extract metadata from. This issue does not necessarily indicate a flaw in the Package constructor, since passing in precalculated USE can be valid for things like autounmask USE changes. Bug: https://bugs.gentoo.org/675748 Signed-off-by: Zac Medico --- lib/portage/package/ebuild/doebuild.py | 12 ++++++++++++ lib/portage/tests/ebuild/test_doebuild_fd_pipes.py | 19 ++++++++++++++++++- lib/portage/tests/resolver/ResolverPlayground.py | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/portage/package/ebuild/doebuild.py b/lib/portage/package/ebuild/doebuild.py index 942fa9010..6691db4e9 100644 --- a/lib/portage/package/ebuild/doebuild.py +++ b/lib/portage/package/ebuild/doebuild.py @@ -1813,6 +1813,14 @@ def _validate_deps(mysettings, myroot, mydo, mydbapi): invalid_dep_exempt_phases = {"clean", "cleanrm", "help", "prerm", "postrm"} all_keys = set(Package.metadata_keys) all_keys.add("SRC_URI") + # Since configdict["pkg"]["USE"] may contain package.use settings + # from config.setcpv, it is inappropriate to use here (bug 675748), + # so discard it. This is only an issue because configdict["pkg"] is + # a sub-optimal place to extract metadata from. This issue does not + # necessarily indicate a flaw in the Package constructor, since + # passing in precalculated USE can be valid for things like + # autounmask USE changes. + all_keys.discard("USE") all_keys = tuple(all_keys) metadata = mysettings.configdict["pkg"] if all(k in metadata for k in ("PORTAGE_REPO_NAME", "SRC_URI")): @@ -1838,6 +1846,10 @@ def _validate_deps(mysettings, myroot, mydo, mydbapi): root_config = RootConfig(mysettings, {"porttree": FakeTree(mydbapi)}, None) + # A USE calculation from setcpv should always be available here because + # mysettings.mycpv is not None, so use it to prevent redundant setcpv calls. + metadata["USE"] = mysettings["PORTAGE_USE"] + pkg = Package( built=False, cpv=mysettings.mycpv, diff --git a/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py b/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py index b38605bb9..445fcf6c4 100644 --- a/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py +++ b/lib/portage/tests/ebuild/test_doebuild_fd_pipes.py @@ -51,10 +51,23 @@ class DoebuildFdPipesTestCase(TestCase): ebuilds = { "app-misct/foo-1": { "EAPI": "8", + "IUSE": "+foo +bar", + "REQUIRED_USE": "|| ( foo bar )", "MISC_CONTENT": ebuild_body, } } + # Populate configdict["pkg"]["USE"] with something arbitrary in order + # to try and trigger bug 675748 in doebuild _validate_deps. + arbitrary_package_use = "baz" + + user_config = { + # In order to trigger bug 675748, package.env must be non-empty, + # but the referenced env file can be empty. + "package.env": (f"app-misct/foo {os.devnull}",), + "package.use": (f"app-misct/foo {arbitrary_package_use}",), + } + # Override things that may be unavailable, or may have portability # issues when running tests in exotic environments. # prepstrip - bug #447810 (bash read builtin EINTR problem) @@ -63,7 +76,7 @@ class DoebuildFdPipesTestCase(TestCase): self.assertEqual(true_binary is None, False, "true command not found") dev_null = open(os.devnull, "wb") - playground = ResolverPlayground(ebuilds=ebuilds) + playground = ResolverPlayground(ebuilds=ebuilds, user_config=user_config) try: QueryCommand._db = playground.trees root_config = playground.trees[playground.eroot]["root_config"] @@ -106,6 +119,10 @@ class DoebuildFdPipesTestCase(TestCase): ) settings.setcpv(pkg) + # Demonstrate that settings.configdict["pkg"]["USE"] contains our arbitrary + # package.use setting in order to trigger bug 675748. + self.assertEqual(settings.configdict["pkg"]["USE"], arbitrary_package_use) + # Try to trigger the config.environ() split_LC_ALL assertion for bug 925863. settings["LC_ALL"] = "C" diff --git a/lib/portage/tests/resolver/ResolverPlayground.py b/lib/portage/tests/resolver/ResolverPlayground.py index c0455415a..f52a98f8d 100644 --- a/lib/portage/tests/resolver/ResolverPlayground.py +++ b/lib/portage/tests/resolver/ResolverPlayground.py @@ -54,6 +54,7 @@ class ResolverPlayground: "make.conf", "modules", "package.accept_keywords", + "package.env", "package.keywords", "package.license", "package.mask", -- cgit v1.2.3-65-gdbad