Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoolkit:gentoolkit-dev commit in: src/ekeyword/
Date: Mon, 20 Jan 2014 16:30:03
Message-Id: 1390235093.b7014219ba7425daa9fafda82fafcc129f8628ce.vapier@gentoo
1 commit: b7014219ba7425daa9fafda82fafcc129f8628ce
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Mon Jan 20 16:24:53 2014 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Mon Jan 20 16:24:53 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=b7014219
7
8 ekeyword: fix keyword sorting between platforms
9
10 We need to sort first upon the platform (part after the '-') before we
11 look at the arch at all.
12
13 Reported-by: Ulrich Mueller <ulm <AT> gentoo.org>
14
15 ---
16 src/ekeyword/ekeyword | 1 +
17 src/ekeyword/ekeyword.py | 24 ++++++++++++++++--------
18 src/ekeyword/ekeyword_unittest.py | 9 ++++++++-
19 3 files changed, 25 insertions(+), 9 deletions(-)
20
21 diff --git a/src/ekeyword/ekeyword b/src/ekeyword/ekeyword
22 new file mode 120000
23 index 0000000..8374306
24 --- /dev/null
25 +++ b/src/ekeyword/ekeyword
26 @@ -0,0 +1 @@
27 +ekeyword.py
28 \ No newline at end of file
29
30 diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
31 index b53daef..66cf48a 100755
32 --- a/src/ekeyword/ekeyword.py
33 +++ b/src/ekeyword/ekeyword.py
34 @@ -78,15 +78,23 @@ def sort_keywords(arches):
35 a1 = keyword_to_arch(a1)
36 a2 = keyword_to_arch(a2)
37
38 - # If a keyword has a "-" in it, then it always comes after ones
39 - # that do not. We want things like alpha/mips/sparc showing up
40 - # before amd64-fbsd and amd64-linux.
41 - if '-' in a1 and not '-' in a2:
42 - return 1
43 - elif '-' not in a1 and '-' in a2:
44 - return -1
45 + # A keyword may have a "-" in it. We split on that and sort
46 + # by the two resulting items. The part after the hyphen is
47 + # the primary key.
48 + if '-' in a1:
49 + arch1, plat1 = a1.split('-', 1)
50 else:
51 - return cmp(a1, a2)
52 + arch1, plat1 = a1, ''
53 + if '-' in a2:
54 + arch2, plat2 = a2.split('-', 1)
55 + else:
56 + arch2, plat2 = a2, ''
57 +
58 + ret = cmp(plat1, plat2)
59 + if ret:
60 + return ret
61 + else:
62 + return cmp(arch1, arch2)
63
64 keywords += sorted(arches, cmp=arch_cmp)
65
66
67 diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
68 index a1d8d85..5096c71 100755
69 --- a/src/ekeyword/ekeyword_unittest.py
70 +++ b/src/ekeyword/ekeyword_unittest.py
71 @@ -31,14 +31,21 @@ class TestSortKeywords(unittest.TestCase):
72 self._test('arm -* x86', '-* arm x86')
73 self._test('hppa ~* amd64', '~* amd64 hppa')
74
75 - def testNonLinux(self):
76 + def testMixedPlatform(self):
77 + """Verify core arches get sorted before all w/suffix"""
78 self._test('arm-linux alpha amd64-fbsd hppa',
79 'alpha hppa amd64-fbsd arm-linux')
80
81 def testPrefixes(self):
82 + """Verify -/~ and such get ignored for sorting"""
83 self._test('-hppa arm ~alpha -* ~arm-linux',
84 '-* ~alpha arm -hppa ~arm-linux')
85
86 + def testPlatform(self):
87 + """Verify we sort based on platform first"""
88 + self._test('x86-linux ppc-macos x86-fbsd amd64-linux amd64-fbsd',
89 + 'amd64-fbsd x86-fbsd amd64-linux x86-linux ppc-macos')
90 +
91
92 class TestDiffKeywords(unittest.TestCase):
93 """Tests for diff_keywords"""