Skip to content

Commit

Permalink
Do not add ALLARCHES if previous versions do not have st kws
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Górny <[email protected]>
  • Loading branch information
mgorny committed Jul 29, 2021
1 parent 40b618c commit 99a90d2
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 4 deletions.
7 changes: 5 additions & 2 deletions nattka/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
expand_package_list, ExpandImpossible,
format_results, filter_prefix_keywords,
PackageKeywordsDict, get_suggested_keywords,
load_profiles, MaskReason)
load_profiles, MaskReason,
can_allarches_for_keywords)

try:
from nattka.depgraph import (get_ordered_nodes,
Expand Down Expand Up @@ -677,7 +678,9 @@ def sanity_check(self) -> int:
check_packages.values())))])
# check if we have ALLARCHES to toggle
allarches = (b.category == BugCategory.STABLEREQ
and all(is_allarches(x) for x in plist))
and all(is_allarches(x) for x in plist)
and can_allarches_for_keywords(
repo, check_packages.items()))
allarches_chg = (allarches != ('ALLARCHES' in b.keywords))

# check if keywords need expanding
Expand Down
23 changes: 23 additions & 0 deletions nattka/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,29 @@ def is_allarches(pkg: pkgcore.ebuild.ebuild_src.package
return False


def can_allarches_for_keywords(repo: UnconfiguredTree,
tuples: PackageKeywordsIterable,
) -> bool:
"""
Verify whether `pkg` is actually suitable for ALLARCHES.
Return True if all packages in tuples have at least one stable
version on each requested architecture, False otherwise.
"""

for req_package, keywords in tuples:
keywords_left = set(keywords)
for p in repo.itermatch(req_package.unversioned_atom):
# NB: we don't need to filter ~arch or -arch keywords, they
# just won't match anything
keywords_left.difference_update(p.keywords)
# if we couldn't match at least one keyword, we can't
# do ALLARCHES
if keywords_left:
return False
return True


def result_group_key(r: NonsolvableDeps) -> tuple:
"""Key used to group pkgcheck results"""
return (r.category, r.package, r.version)
Expand Down
11 changes: 11 additions & 0 deletions test/data/test/mixed-keywords/mixed-keywords-5.ebuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

DESCRIPTION="Test ebuild"
HOMEPAGE="https://github.com/mgorny/nattka/"

LICENSE="none"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~hppa"
22 changes: 21 additions & 1 deletion test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ def test_sanity_allarches_add(self, bugz):
bugz_inst = bugz.return_value
bugz_inst.find_bugs.return_value = {
560322: BugInfo(BugCategory.STABLEREQ,
'test/amd64-stable-hppa-testing-1 hppa\r\n',
'test/mixed-keywords-5 amd64 hppa\r\n',
last_change_time=datetime.datetime(
2020, 1, 1, 12, 0, 0)),
}
Expand All @@ -1446,6 +1446,26 @@ def test_sanity_allarches_add(self, bugz):
keywords_add=['ALLARCHES'])
self.post_verify()

@patch('nattka.__main__.NattkaBugzilla')
def test_sanity_allarches_extra_keywords(self, bugz):
bugz_inst = bugz.return_value
bugz_inst.find_bugs.return_value = {
560322: BugInfo(BugCategory.STABLEREQ,
'test/mixed-keywords-5 amd64 hppa alpha\r\n',
last_change_time=datetime.datetime(
2020, 1, 1, 12, 0, 0)),
}
bugz_inst.resolve_dependencies.return_value = (
bugz_inst.find_bugs.return_value)
self.assertEqual(
main(self.common_args + ['sanity-check', '--update-bugs',
'560322']),
0)
bugz_inst.find_bugs.assert_called_with(bugs=[560322])
bugz_inst.update_status.assert_called_with(
560322, True, None)
self.post_verify()

@patch('nattka.__main__.NattkaBugzilla')
def test_sanity_allarches_remove(self, bugz):
bugz_inst = bugz.return_value
Expand Down
33 changes: 32 additions & 1 deletion test/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
merge_package_list, is_allarches,
expand_package_list, ExpandImpossible,
format_results, filter_prefix_keywords,
is_masked, load_profiles, MaskReason)
is_masked, load_profiles, MaskReason,
can_allarches_for_keywords)


def get_test_repo(path: Path = Path(__file__).parent):
Expand Down Expand Up @@ -1239,6 +1240,36 @@ def test_wrong_packagerestrict(self):
self.get_package('=test/wrong-package-restrict-1'))


class CanAllArchesForKeywordsTests(BaseRepoTestCase):
def test_allarches(self):
self.assertTrue(
can_allarches_for_keywords(
self.repo,
[(self.get_package('=test/mixed-keywords-5'),
['amd64', 'hppa'])]))

def test_some_nonstable_keywords(self):
self.assertFalse(
can_allarches_for_keywords(
self.repo,
[(self.get_package('=test/mixed-keywords-5'),
['amd64', 'hppa', 'alpha'])]))

def test_pure_nonstable(self):
self.assertFalse(
can_allarches_for_keywords(
self.repo,
[(self.get_package('=test/amd64-testing-2'),
['amd64'])]))

def test_nonkeyworded(self):
self.assertFalse(
can_allarches_for_keywords(
self.repo,
[(self.get_package('=test/amd64-testing-2'),
['alpha'])]))


class ResultFormatterTests(BaseRepoTestCase):
maxDiff = None

Expand Down

0 comments on commit 99a90d2

Please sign in to comment.