aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2014-01-20 11:24:53 -0500
committerMike Frysinger <vapier@gentoo.org>2014-01-20 11:24:53 -0500
commitb7014219ba7425daa9fafda82fafcc129f8628ce (patch)
tree423171919491ac434ddbcdd5d6b84deb99c6ce5b
parentekeyword: make sure ~all does not expand into entire arch list (diff)
downloadgentoolkit-b7014219ba7425daa9fafda82fafcc129f8628ce.tar.gz
gentoolkit-b7014219ba7425daa9fafda82fafcc129f8628ce.tar.bz2
gentoolkit-b7014219ba7425daa9fafda82fafcc129f8628ce.zip
ekeyword: fix keyword sorting between platforms
We need to sort first upon the platform (part after the '-') before we look at the arch at all. Reported-by: Ulrich Mueller <ulm@gentoo.org>
l---------src/ekeyword/ekeyword1
-rwxr-xr-xsrc/ekeyword/ekeyword.py24
-rwxr-xr-xsrc/ekeyword/ekeyword_unittest.py9
3 files changed, 25 insertions, 9 deletions
diff --git a/src/ekeyword/ekeyword b/src/ekeyword/ekeyword
new file mode 120000
index 0000000..8374306
--- /dev/null
+++ b/src/ekeyword/ekeyword
@@ -0,0 +1 @@
+ekeyword.py \ No newline at end of file
diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py
index b53daef..66cf48a 100755
--- a/src/ekeyword/ekeyword.py
+++ b/src/ekeyword/ekeyword.py
@@ -78,15 +78,23 @@ def sort_keywords(arches):
a1 = keyword_to_arch(a1)
a2 = keyword_to_arch(a2)
- # If a keyword has a "-" in it, then it always comes after ones
- # that do not. We want things like alpha/mips/sparc showing up
- # before amd64-fbsd and amd64-linux.
- if '-' in a1 and not '-' in a2:
- return 1
- elif '-' not in a1 and '-' in a2:
- return -1
+ # A keyword may have a "-" in it. We split on that and sort
+ # by the two resulting items. The part after the hyphen is
+ # the primary key.
+ if '-' in a1:
+ arch1, plat1 = a1.split('-', 1)
else:
- return cmp(a1, a2)
+ arch1, plat1 = a1, ''
+ if '-' in a2:
+ arch2, plat2 = a2.split('-', 1)
+ else:
+ arch2, plat2 = a2, ''
+
+ ret = cmp(plat1, plat2)
+ if ret:
+ return ret
+ else:
+ return cmp(arch1, arch2)
keywords += sorted(arches, cmp=arch_cmp)
diff --git a/src/ekeyword/ekeyword_unittest.py b/src/ekeyword/ekeyword_unittest.py
index a1d8d85..5096c71 100755
--- a/src/ekeyword/ekeyword_unittest.py
+++ b/src/ekeyword/ekeyword_unittest.py
@@ -31,14 +31,21 @@ class TestSortKeywords(unittest.TestCase):
self._test('arm -* x86', '-* arm x86')
self._test('hppa ~* amd64', '~* amd64 hppa')
- def testNonLinux(self):
+ def testMixedPlatform(self):
+ """Verify core arches get sorted before all w/suffix"""
self._test('arm-linux alpha amd64-fbsd hppa',
'alpha hppa amd64-fbsd arm-linux')
def testPrefixes(self):
+ """Verify -/~ and such get ignored for sorting"""
self._test('-hppa arm ~alpha -* ~arm-linux',
'-* ~alpha arm -hppa ~arm-linux')
+ def testPlatform(self):
+ """Verify we sort based on platform first"""
+ self._test('x86-linux ppc-macos x86-fbsd amd64-linux amd64-fbsd',
+ 'amd64-fbsd x86-fbsd amd64-linux x86-linux ppc-macos')
+
class TestDiffKeywords(unittest.TestCase):
"""Tests for diff_keywords"""