From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B53F4158020 for ; Mon, 26 Dec 2022 17:28:09 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6B692E0963; Mon, 26 Dec 2022 17:28:08 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.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)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5654BE0964 for ; Mon, 26 Dec 2022 17:28:08 +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)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6590F341104 for ; Mon, 26 Dec 2022 17:28:07 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 79F9C7F9 for ; Mon, 26 Dec 2022 17:28:04 +0000 (UTC) From: "Arthur Zamarin" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arthur Zamarin" Message-ID: <1672075644.5a51817e29ee8a9879876be1576eaa38b357ffa3.arthurzam@gentoo> Subject: [gentoo-commits] proj/pkgcore/pkgcore:master commit in: tests/ebuild/, src/pkgcore/ebuild/ X-VCS-Repository: proj/pkgcore/pkgcore X-VCS-Files: src/pkgcore/ebuild/domain.py tests/ebuild/test_domain.py X-VCS-Directories: tests/ebuild/ src/pkgcore/ebuild/ X-VCS-Committer: arthurzam X-VCS-Committer-Name: Arthur Zamarin X-VCS-Revision: 5a51817e29ee8a9879876be1576eaa38b357ffa3 X-VCS-Branch: master Date: Mon, 26 Dec 2022 17:28:04 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 84f46b70-8726-4461-8f18-e47fa5bcf2c4 X-Archives-Hash: 3277c657f3e3d3561242599790bc9a7a commit: 5a51817e29ee8a9879876be1576eaa38b357ffa3 Author: Brian Harring gmail com> AuthorDate: Mon Dec 26 01:31:02 2022 +0000 Commit: Arthur Zamarin gentoo org> CommitDate: Mon Dec 26 17:27:24 2022 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=5a51817e Add use flag validation for /etc/portage/package.use/* content. Had this been in place, it would've detected pkgcore/pkgcore#384 long ago. Signed-off-by: Brian Harring gmail.com> Signed-off-by: Arthur Zamarin gentoo.org> src/pkgcore/ebuild/domain.py | 8 ++++++++ tests/ebuild/test_domain.py | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/pkgcore/ebuild/domain.py b/src/pkgcore/ebuild/domain.py index 6f86f7d14..9fef5f843 100644 --- a/src/pkgcore/ebuild/domain.py +++ b/src/pkgcore/ebuild/domain.py @@ -44,6 +44,7 @@ from ..util.parserestrict import ParseError, parse_match from . import const from . import repository as ebuild_repo from .atom import atom as _atom +from .eapi import get_latest_PMS_eapi from .misc import ( ChunkedDataDict, chunked_data, @@ -86,7 +87,10 @@ def package_use_splitter(iterable): USE_EXPAND target and should be expanded into their normalized/long form. """ + eapi_obj = get_latest_PMS_eapi() + def f(tokens: list[str]): + i = iter(tokens) for idx, x in enumerate(i): if x.endswith(":"): @@ -99,8 +103,12 @@ def package_use_splitter(iterable): flag = f"-{x}_{flag[1:]}" else: flag = f"{x}_{flag}" + if not eapi_obj.is_valid_use_flag(flag.lstrip("-")): + raise ParseError(f"token {flag} is not a valid use flag") l.append(flag) return l + elif not eapi_obj.is_valid_use_flag(x.lstrip("-")): + raise ParseError(f"token {flag} is not a valid use flag") # if we made it here, there's no USE_EXPAND; thus just return the original sequence return tokens diff --git a/tests/ebuild/test_domain.py b/tests/ebuild/test_domain.py index 87c3d489f..90594b9d6 100644 --- a/tests/ebuild/test_domain.py +++ b/tests/ebuild/test_domain.py @@ -20,6 +20,8 @@ class TestDomain: self.profile_base = tmp_path_factory.mktemp("profiles") self.profile1 = self.profile_base / "profile1" self.pmixin.mk_profile(self.profile_base, str(self.profile1)) + self.pusedir = self.confdir / "package.use" + self.pusedir.mkdir() def mk_domain(self): return domain_mod.domain( @@ -32,14 +34,11 @@ class TestDomain: def test_sorting(self): """assert that configuration files are read in alphanum ordering""" - cdir = self.confdir / "package.use" - cdir.mkdir() - # assert the base state; no files, no content. assert () == self.mk_domain().pkg_use - open(cdir / "00", "w").write("*/* X") - open(cdir / "01", "w").write("*/* -X Y") + open(self.pusedir / "00", "w").write("*/* X") + open(self.pusedir / "01", "w").write("*/* -X Y") # Force the returned ordering to be reversed; this is to assert that # the domain forces a sort. @@ -57,9 +56,7 @@ class TestDomain: ) == self.mk_domain().pkg_use def test_use_expand_syntax(self): - puse = self.confdir / "package.use" - puse.mkdir() - open(puse / "a", "w").write( + open(self.pusedir / "a", "w").write( textwrap.dedent( """ */* x_y1 @@ -82,3 +79,9 @@ class TestDomain: ), ), ) == self.mk_domain().pkg_use + + def test_use_flag_parsing_enforcement(self): + open(self.pusedir / "a", "w").write("*/* X:") + # TODO: need to catch the warning here, but I'm not sure how. + # Meanwhile, ensure that the failed token is ignored. + assert ((packages.AlwaysTrue, ((), ())),) == self.mk_domain().pkg_use