aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Bier <felix.bier@rohde-schwarz.com>2021-03-17 23:42:27 +0100
committerZac Medico <zmedico@gentoo.org>2021-03-28 01:59:19 -0700
commit9bfff6f0788761e2debd1e158a03970d4057cfcf (patch)
tree5b6a81c93b30f7262d3377f235ecf50b68339993
parentemerge: add -W option short for --deselect (diff)
downloadportage-9bfff6f0788761e2debd1e158a03970d4057cfcf.tar.gz
portage-9bfff6f0788761e2debd1e158a03970d4057cfcf.tar.bz2
portage-9bfff6f0788761e2debd1e158a03970d4057cfcf.zip
Atom: Decouple eapi and allow_repo
This commit changes the Atom constructor such that allow_repo is only overwritten with the eapi default if allow_repo is None. If allow_repo is not None, its value is preserved. There are currently two deprecated EAPIs which allowed for repo atoms ("4-python" and "5-progress"). The current consensus seems to be that repo atoms are not wanted in other eapis, and should instead be implemented via a profile format extension [1]. As a prerequisite, the allow_repo parameter has to be decoupled from the eapi parameter as done by this commit, since otherwise if an eapi other than "4-python" and "5-progress" is passed, this would force allow_repo to be False. This would prevent implementing a profile format extension that passes allow_repo=True. A helper function allow_profile_repo_deps has been added to initialize allow_repo based on the eapi of a repo before calling the Atom constructor. This helper function can be extended later to also take a profile format extension into account. All calls to the Atom constructor that pass both allow_repo and eapi have been adapted to use this helper function, with the following exceptions: update.py, vartree.py, bintree.py call isvalidatom to validate the rhs of a "move" command in profile/update [2]. Before this commit, when using eapi "4-python" or "5-progress", this check permitted the rhs to be a repo atom. However, this use case seems to be unsupported even for those eapis: The code substitutes the lhs with the rhs in the target atom, so if the target atom contains further modifiers such as slots or use flags, the the substitution would place the ::repo before these modifiers, resulting in an invalid atom that is rejected by other parts of the code. For this reason, these calls have not been adapted. [1]: https://bugs.gentoo.org/651208 [2]: https://dev.gentoo.org/~ulm/pms/head/pms.html#x1-360004.4.4 Signed-off-by: Felix Bier <felix.bier@rohde-schwarz.com> Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--lib/portage/_sets/ProfilePackageSet.py9
-rw-r--r--lib/portage/_sets/profiles.py10
-rw-r--r--lib/portage/dep/__init__.py7
-rw-r--r--lib/portage/package/ebuild/_config/KeywordsManager.py7
-rw-r--r--lib/portage/package/ebuild/_config/LocationsManager.py11
-rw-r--r--lib/portage/package/ebuild/_config/MaskManager.py7
-rw-r--r--lib/portage/package/ebuild/_config/UseManager.py12
-rw-r--r--lib/portage/package/ebuild/config.py11
-rw-r--r--lib/portage/repository/config.py29
-rw-r--r--lib/portage/tests/dep/test_isvalidatom.py26
-rw-r--r--repoman/lib/repoman/repos.py8
11 files changed, 102 insertions, 35 deletions
diff --git a/lib/portage/_sets/ProfilePackageSet.py b/lib/portage/_sets/ProfilePackageSet.py
index fec937391..7a304c578 100644
--- a/lib/portage/_sets/ProfilePackageSet.py
+++ b/lib/portage/_sets/ProfilePackageSet.py
@@ -1,7 +1,8 @@
-# Copyright 2014 Gentoo Foundation
+# Copyright 2014-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
from portage import os
+from portage.repository.config import allow_profile_repo_deps
from portage.util import grabfile_package, stack_lists
from portage._sets.base import PackageSet
@@ -9,7 +10,9 @@ class ProfilePackageSet(PackageSet):
_operations = ["merge"]
def __init__(self, profiles, debug=False):
- super(ProfilePackageSet, self).__init__()
+ super(ProfilePackageSet, self).__init__(
+ allow_repo=any(allow_profile_repo_deps(y) for y in profiles)
+ )
self._profiles = profiles
if profiles:
desc_profile = profiles[-1]
@@ -24,7 +27,7 @@ class ProfilePackageSet(PackageSet):
self._setAtoms(x for x in stack_lists(
[grabfile_package(os.path.join(y.location, "packages"),
verify_eapi=True, eapi=y.eapi, eapi_default=None,
- allow_build_id=y.allow_build_id)
+ allow_build_id=y.allow_build_id, allow_repo=allow_profile_repo_deps(y))
for y in self._profiles
if "profile-set" in y.profile_formats],
incremental=1) if x[:1] != "*")
diff --git a/lib/portage/_sets/profiles.py b/lib/portage/_sets/profiles.py
index bccc02e7c..95831f705 100644
--- a/lib/portage/_sets/profiles.py
+++ b/lib/portage/_sets/profiles.py
@@ -1,9 +1,10 @@
-# Copyright 2007-2014 Gentoo Foundation
+# Copyright 2007-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import logging
from portage import os
+from portage.repository.config import allow_profile_repo_deps
from portage.util import grabfile_package, stack_lists
from portage._sets.base import PackageSet
from portage._sets import get_boolean
@@ -15,7 +16,9 @@ class PackagesSystemSet(PackageSet):
_operations = ["merge"]
def __init__(self, profiles, debug=False):
- super(PackagesSystemSet, self).__init__()
+ super(PackagesSystemSet, self).__init__(
+ allow_repo=any(allow_profile_repo_deps(x) for x in profiles)
+ )
self._profiles = profiles
self._debug = debug
if profiles:
@@ -35,7 +38,8 @@ class PackagesSystemSet(PackageSet):
mylist = [grabfile_package(os.path.join(x.location, "packages"),
verify_eapi=True, eapi=x.eapi, eapi_default=None,
- allow_build_id=x.allow_build_id)
+ allow_build_id=x.allow_build_id,
+ allow_repo=allow_profile_repo_deps(x))
for x in self._profiles]
if debug:
diff --git a/lib/portage/dep/__init__.py b/lib/portage/dep/__init__.py
index 3f0ef7ece..e32f01fc0 100644
--- a/lib/portage/dep/__init__.py
+++ b/lib/portage/dep/__init__.py
@@ -1,5 +1,5 @@
# deps.py -- Portage dependency resolution functions
-# Copyright 2003-2020 Gentoo Authors
+# Copyright 2003-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
__all__ = [
@@ -1259,8 +1259,9 @@ class Atom(str):
self.__dict__['eapi'] = eapi
if eapi is not None:
- # Ignore allow_repo when eapi is specified.
- allow_repo = eapi_attrs.repo_deps
+ # If allow_repo is not set, use default from eapi
+ if allow_repo is None:
+ allow_repo = eapi_attrs.repo_deps
else:
# These parameters have "smart" defaults that are only
# applied when the caller does not explicitly pass in a
diff --git a/lib/portage/package/ebuild/_config/KeywordsManager.py b/lib/portage/package/ebuild/_config/KeywordsManager.py
index bf68a88ac..8dcaee0d9 100644
--- a/lib/portage/package/ebuild/_config/KeywordsManager.py
+++ b/lib/portage/package/ebuild/_config/KeywordsManager.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2020 Gentoo Authors
+# Copyright 2010-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
__all__ = (
@@ -12,6 +12,7 @@ from portage import os
from portage.dep import ExtendedAtomDict
from portage.localization import _
from portage.package.ebuild._config.helper import ordered_by_atom_specificity
+from portage.repository.config import allow_profile_repo_deps
from portage.util import grabdict_package, stack_lists
from portage.versions import _pkg_str
@@ -25,6 +26,7 @@ class KeywordsManager:
os.path.join(x.location, "package.keywords"),
recursive=x.portage1_directories,
verify_eapi=True, eapi=x.eapi, eapi_default=None,
+ allow_repo=allow_profile_repo_deps(x),
allow_build_id=x.allow_build_id)
for x in profiles]
for pkeyworddict in rawpkeywords:
@@ -41,7 +43,8 @@ class KeywordsManager:
raw_p_accept_keywords = [grabdict_package(
os.path.join(x.location, "package.accept_keywords"),
recursive=x.portage1_directories,
- verify_eapi=True, eapi=x.eapi, eapi_default=None)
+ verify_eapi=True, eapi=x.eapi, eapi_default=None,
+ allow_repo=allow_profile_repo_deps(x))
for x in profiles]
for d in raw_p_accept_keywords:
if not d:
diff --git a/lib/portage/package/ebuild/_config/LocationsManager.py b/lib/portage/package/ebuild/_config/LocationsManager.py
index 327400ad6..433232a7a 100644
--- a/lib/portage/package/ebuild/_config/LocationsManager.py
+++ b/lib/portage/package/ebuild/_config/LocationsManager.py
@@ -1,11 +1,10 @@
-# Copyright 2010-2018 Gentoo Foundation
+# Copyright 2010-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
__all__ = (
'LocationsManager',
)
-import collections
import io
import warnings
@@ -20,7 +19,7 @@ from portage.util import ensure_dirs, grabfile, \
normalize_path, read_corresponding_eapi_file, shlex_split, writemsg
from portage.util._path import exists_raise_eaccess, isdir_raise_eaccess
from portage.repository.config import parse_layout_conf, \
- _portage1_profiles_allow_directories
+ _portage1_profiles_allow_directories, _profile_node
_PORTAGE1_DIRECTORIES = frozenset([
@@ -28,12 +27,6 @@ _PORTAGE1_DIRECTORIES = frozenset([
'package.use', 'package.use.mask', 'package.use.force',
'use.mask', 'use.force'])
-_profile_node = collections.namedtuple('_profile_node',
- ('location', 'portage1_directories', 'user_config',
- 'profile_formats', 'eapi', 'allow_build_id',
- 'show_deprecated_warning',
-))
-
_allow_parent_colon = frozenset(
["portage-2"])
diff --git a/lib/portage/package/ebuild/_config/MaskManager.py b/lib/portage/package/ebuild/_config/MaskManager.py
index 7714456e1..b0c2b55da 100644
--- a/lib/portage/package/ebuild/_config/MaskManager.py
+++ b/lib/portage/package/ebuild/_config/MaskManager.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2018 Gentoo Foundation
+# Copyright 2010-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
__all__ = (
@@ -10,6 +10,7 @@ import warnings
from portage import os
from portage.dep import ExtendedAtomDict, match_from_list
from portage.localization import _
+from portage.repository.config import allow_profile_repo_deps
from portage.util import append_repo, grabfile_package, stack_lists, writemsg
from portage.versions import _pkg_str
@@ -41,6 +42,7 @@ class MaskManager:
recursive=repo_config.portage1_profiles,
remember_source_file=True, verify_eapi=True,
eapi_default=repo_config.eapi,
+ allow_repo=allow_profile_repo_deps(repo_config),
allow_build_id=("build-id"
in repo_config.profile_formats))
if repo_config.portage1_profiles_compat and os.path.isdir(path):
@@ -110,6 +112,7 @@ class MaskManager:
repo_lines = grabfile_package(os.path.join(repo.location, "profiles", "package.unmask"), \
recursive=1, remember_source_file=True,
verify_eapi=True, eapi_default=repo.eapi,
+ allow_repo=allow_profile_repo_deps(repo),
allow_build_id=("build-id" in repo.profile_formats))
lines = stack_lists([repo_lines], incremental=1, \
remember_source_file=True, warn_for_unmatched_removal=True,
@@ -126,6 +129,7 @@ class MaskManager:
recursive=x.portage1_directories,
remember_source_file=True, verify_eapi=True,
eapi=x.eapi, eapi_default=None,
+ allow_repo=allow_profile_repo_deps(x),
allow_build_id=x.allow_build_id))
if x.portage1_directories:
profile_pkgunmasklines.append(grabfile_package(
@@ -133,6 +137,7 @@ class MaskManager:
recursive=x.portage1_directories,
remember_source_file=True, verify_eapi=True,
eapi=x.eapi, eapi_default=None,
+ allow_repo=allow_profile_repo_deps(x),
allow_build_id=x.allow_build_id))
profile_pkgmasklines = stack_lists(profile_pkgmasklines, incremental=1, \
remember_source_file=True, warn_for_unmatched_removal=True,
diff --git a/lib/portage/package/ebuild/_config/UseManager.py b/lib/portage/package/ebuild/_config/UseManager.py
index 882b0efa9..656c6199b 100644
--- a/lib/portage/package/ebuild/_config/UseManager.py
+++ b/lib/portage/package/ebuild/_config/UseManager.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2014 Gentoo Foundation
+# Copyright 2010-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
__all__ = (
@@ -11,6 +11,7 @@ from portage.dep import Atom, dep_getrepo, dep_getslot, ExtendedAtomDict, remove
from portage.eapi import eapi_has_use_aliases, eapi_supports_stable_use_forcing_and_masking
from portage.exception import InvalidAtom
from portage.localization import _
+from portage.repository.config import allow_profile_repo_deps
from portage.util import grabfile, grabdict, grabdict_package, read_corresponding_eapi_file, stack_lists, writemsg
from portage.versions import _pkg_str
@@ -154,7 +155,7 @@ class UseManager:
def _parse_file_to_dict(self, file_name, juststrings=False, recursive=True,
eapi_filter=None, user_config=False, eapi=None, eapi_default="0",
- allow_build_id=False):
+ allow_repo=False, allow_build_id=False):
"""
@param file_name: input file name
@type file_name: str
@@ -193,8 +194,9 @@ class UseManager:
ret = ExtendedAtomDict(dict)
else:
ret = {}
+ allow_repo = allow_repo or extended_syntax
file_dict = grabdict_package(file_name, recursive=recursive,
- allow_wildcard=extended_syntax, allow_repo=extended_syntax,
+ allow_wildcard=extended_syntax, allow_repo=allow_repo,
verify_eapi=(not extended_syntax), eapi=eapi,
eapi_default=eapi_default, allow_build_id=allow_build_id,
allow_use=False)
@@ -277,6 +279,7 @@ class UseManager:
ret[repo.name] = self._parse_file_to_dict(
os.path.join(repo.location, "profiles", file_name),
eapi_filter=eapi_filter, eapi_default=repo.eapi,
+ allow_repo=allow_profile_repo_deps(repo),
allow_build_id=("build-id" in repo.profile_formats))
return ret
@@ -294,7 +297,8 @@ class UseManager:
os.path.join(profile.location, file_name), juststrings,
recursive=profile.portage1_directories, eapi_filter=eapi_filter,
user_config=profile.user_config, eapi=profile.eapi,
- eapi_default=None, allow_build_id=profile.allow_build_id)
+ eapi_default=None, allow_build_id=profile.allow_build_id,
+ allow_repo=allow_profile_repo_deps(profile))
for profile in locations)
def _parse_repository_usealiases(self, repositories):
diff --git a/lib/portage/package/ebuild/config.py b/lib/portage/package/ebuild/config.py
index 690efde9d..0d0b51053 100644
--- a/lib/portage/package/ebuild/config.py
+++ b/lib/portage/package/ebuild/config.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2020 Gentoo Authors
+# Copyright 2010-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
__all__ = [
@@ -42,7 +42,10 @@ from portage.exception import InvalidDependString, PortageException
from portage.localization import _
from portage.output import colorize
from portage.process import fakeroot_capable, sandbox_capable
-from portage.repository.config import load_repository_config
+from portage.repository.config import (
+ allow_profile_repo_deps,
+ load_repository_config,
+)
from portage.util import ensure_dirs, getconfig, grabdict, \
grabdict_package, grabfile, grabfile_package, LazyItemsDict, \
normalize_path, shlex_split, stack_dictlist, stack_dicts, stack_lists, \
@@ -593,6 +596,7 @@ class config:
packages_list = [grabfile_package(
os.path.join(x.location, "packages"),
verify_eapi=True, eapi=x.eapi, eapi_default=None,
+ allow_repo=allow_profile_repo_deps(x),
allow_build_id=x.allow_build_id)
for x in profiles_complex]
except EnvironmentError as e:
@@ -812,7 +816,8 @@ class config:
portage.dep.ExtendedAtomDict(dict)
bashrc = grabdict_package(os.path.join(profile.location,
"package.bashrc"), recursive=1, allow_wildcard=True,
- allow_repo=True, verify_eapi=True,
+ allow_repo=allow_profile_repo_deps(profile),
+ verify_eapi=True,
eapi=profile.eapi, eapi_default=None,
allow_build_id=profile.allow_build_id)
if not bashrc:
diff --git a/lib/portage/repository/config.py b/lib/portage/repository/config.py
index 83e9746d1..c401d10b4 100644
--- a/lib/portage/repository/config.py
+++ b/lib/portage/repository/config.py
@@ -1,16 +1,21 @@
-# Copyright 2010-2020 Gentoo Authors
+# Copyright 2010-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
+import collections
import io
import logging
import warnings
import re
+import typing
import portage
from portage import eclass_cache, os
from portage.checksum import get_valid_checksum_keys
from portage.const import (PORTAGE_BASE_PATH, REPO_NAME_LOC, USER_CONFIG_PATH)
-from portage.eapi import eapi_allows_directories_on_profile_level_and_repository_level
+from portage.eapi import (
+ eapi_allows_directories_on_profile_level_and_repository_level,
+ eapi_has_repo_deps,
+)
from portage.env.loaders import KeyValuePairFileLoader
from portage.util import (normalize_path, read_corresponding_eapi_file, shlex_split,
stack_lists, writemsg, writemsg_level, _recursive_file_list)
@@ -25,6 +30,18 @@ from portage import _encodings
from portage import manifest
import portage.sync
+_profile_node = collections.namedtuple(
+ "_profile_node",
+ (
+ "location",
+ "portage1_directories",
+ "user_config",
+ "profile_formats",
+ "eapi",
+ "allow_build_id",
+ "show_deprecated_warning",
+ ),
+)
# Characters prohibited by repoman's file.name check.
_invalid_path_char_re = re.compile(r'[^a-zA-Z0-9._\-+/]')
@@ -1096,6 +1113,14 @@ class RepoConfigLoader:
config_string += "%s = %s\n" % (o, v)
return config_string.lstrip("\n")
+def allow_profile_repo_deps(
+ repo: typing.Union[RepoConfig, _profile_node],
+) -> bool:
+ if eapi_has_repo_deps(repo.eapi):
+ return True
+
+ return False
+
def load_repository_config(settings, extra_files=None):
repoconfigpaths = []
if "PORTAGE_REPOSITORIES" in settings:
diff --git a/lib/portage/tests/dep/test_isvalidatom.py b/lib/portage/tests/dep/test_isvalidatom.py
index 58d999646..4203be07b 100644
--- a/lib/portage/tests/dep/test_isvalidatom.py
+++ b/lib/portage/tests/dep/test_isvalidatom.py
@@ -1,4 +1,4 @@
-# Copyright 2006-2013 Gentoo Foundation
+# Copyright 2006-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
from portage.tests import TestCase
@@ -6,12 +6,13 @@ from portage.dep import isvalidatom
class IsValidAtomTestCase:
def __init__(self, atom, expected, allow_wildcard=False,
- allow_repo=False, allow_build_id=False):
+ allow_repo=False, allow_build_id=False, eapi=None):
self.atom = atom
self.expected = expected
self.allow_wildcard = allow_wildcard
self.allow_repo = allow_repo
self.allow_build_id = allow_build_id
+ self.eapi = eapi
class IsValidAtom(TestCase):
@@ -137,6 +138,24 @@ class IsValidAtom(TestCase):
IsValidAtomTestCase("=sys-apps/portage-2.2*:foo::repo[doc?]", False, allow_repo=False),
IsValidAtomTestCase("null/portage::repo", False, allow_repo=False),
+ # Testing repo atoms with eapi
+
+ # If allow_repo is None, it should be overwritten by eapi
+ IsValidAtomTestCase("sys-apps/portage::repo", True, allow_repo=None),
+ IsValidAtomTestCase("sys-apps/portage::repo", False, allow_repo=None, eapi="5"),
+ IsValidAtomTestCase("sys-apps/portage::repo", True, allow_repo=None, eapi="5-progress"),
+ IsValidAtomTestCase("sys-apps/portage::repo", False, allow_repo=None, eapi="7"),
+
+ # If allow_repo is not None, it should not be overwritten by eapi
+ IsValidAtomTestCase("sys-apps/portage::repo", False, allow_repo=False),
+ IsValidAtomTestCase("sys-apps/portage::repo", False, allow_repo=False, eapi="5"),
+ IsValidAtomTestCase("sys-apps/portage::repo", False, allow_repo=False, eapi="5-progress"),
+ IsValidAtomTestCase("sys-apps/portage::repo", False, allow_repo=False, eapi="7"),
+ IsValidAtomTestCase("sys-apps/portage::repo", True, allow_repo=True),
+ IsValidAtomTestCase("sys-apps/portage::repo", True, allow_repo=True, eapi="5"),
+ IsValidAtomTestCase("sys-apps/portage::repo", True, allow_repo=True, eapi="5-progress"),
+ IsValidAtomTestCase("sys-apps/portage::repo", True, allow_repo=True, eapi="7"),
+
IsValidAtomTestCase("virtual/ffmpeg:0/53", True),
IsValidAtomTestCase("virtual/ffmpeg:0/53=", True),
IsValidAtomTestCase("virtual/ffmpeg:0/53*", False),
@@ -157,6 +176,7 @@ class IsValidAtom(TestCase):
atom_type = "invalid"
self.assertEqual(bool(isvalidatom(test_case.atom, allow_wildcard=test_case.allow_wildcard,
allow_repo=test_case.allow_repo,
- allow_build_id=test_case.allow_build_id)),
+ allow_build_id=test_case.allow_build_id,
+ eapi=test_case.eapi)),
test_case.expected,
msg="isvalidatom(%s) != %s" % (test_case.atom, test_case.expected))
diff --git a/repoman/lib/repoman/repos.py b/repoman/lib/repoman/repos.py
index 31cb82caf..6df984a28 100644
--- a/repoman/lib/repoman/repos.py
+++ b/repoman/lib/repoman/repos.py
@@ -14,6 +14,7 @@ from portage import os
from portage import _encodings
from portage import _unicode_encode
from portage.checksum import get_valid_checksum_keys
+from portage.repository.config import allow_profile_repo_deps
# pylint: disable=ungrouped-imports
from repoman.errors import err
@@ -233,7 +234,9 @@ def repo_metadata(portdb, repoman_settings):
profile_list = []
global_pmasklines = []
- for path in portdb.porttrees:
+ for repo in portdb.repositories:
+ path = repo.location
+
try:
liclist.update(os.listdir(os.path.join(path, "licenses")))
except OSError:
@@ -265,7 +268,8 @@ def repo_metadata(portdb, repoman_settings):
global_pmasklines.append(
portage.util.grabfile_package(
os.path.join(path, 'profiles', 'package.mask'),
- recursive=1, verify_eapi=True))
+ recursive=1, verify_eapi=True,
+ allow_repo=allow_profile_repo_deps(repo)))
desc_path = os.path.join(path, 'profiles', 'profiles.desc')
try: