summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2017-10-11 22:43:46 (GMT)
committerWilliam Deegan <bill@baddogconsulting.com>2017-10-11 22:43:46 (GMT)
commit4f7b5abd7c9fe05a6f894005fdd3586c87d02462 (patch)
treec4b72a1578ff3e846a908aa65776d21e5a3c907c /src/engine
parent7144cf56430cff650a34ef102ad64ce5feb1d9cd (diff)
downloadSCons-4f7b5abd7c9fe05a6f894005fdd3586c87d02462.zip
SCons-4f7b5abd7c9fe05a6f894005fdd3586c87d02462.tar.gz
SCons-4f7b5abd7c9fe05a6f894005fdd3586c87d02462.tar.bz2
Fix logic which was broken by automatic fixers. the sort parameter to GenerateHelpText() is now actually called.
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Variables/VariablesTests.py20
-rw-r--r--src/engine/SCons/Variables/__init__.py7
2 files changed, 26 insertions, 1 deletions
diff --git a/src/engine/SCons/Variables/VariablesTests.py b/src/engine/SCons/Variables/VariablesTests.py
index b260d54..175a14b 100644
--- a/src/engine/SCons/Variables/VariablesTests.py
+++ b/src/engine/SCons/Variables/VariablesTests.py
@@ -487,9 +487,29 @@ B: b - alpha test
default: 42
actual: 54
"""
+
+ expectBackwards = """
+B: b - alpha test
+ default: 42
+ actual: 54
+
+ANSWER: THE answer to THE question
+ default: 42
+ actual: 54
+
+A: a - alpha test
+ default: 42
+ actual: 54
+"""
text = opts.GenerateHelpText(env, sort=cmp)
assert text == expectAlpha, text
+ textBool = opts.GenerateHelpText(env, sort=True)
+ assert text == expectAlpha, text
+
+ textBackwards = opts.GenerateHelpText(env, sort=lambda x, y: cmp(y, x))
+ assert textBackwards == expectBackwards, "Expected:\n%s\nGot:\n%s\n"%(textBackwards, expectBackwards)
+
def test_FormatVariableHelpText(self):
"""Test generating custom format help text"""
opts = SCons.Variables.Variables()
diff --git a/src/engine/SCons/Variables/__init__.py b/src/engine/SCons/Variables/__init__.py
index 5b20b30..6ad40ed 100644
--- a/src/engine/SCons/Variables/__init__.py
+++ b/src/engine/SCons/Variables/__init__.py
@@ -30,6 +30,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os.path
import sys
+from functools import cmp_to_key
import SCons.Environment
import SCons.Errors
@@ -287,9 +288,13 @@ class Variables(object):
env - an environment that is used to get the current values
of the options.
+ cmp - Either a function as follows: The specific sort function should take two arguments and return -1, 0 or 1
+ or a boolean to indicate if it should be sorted.
"""
- if sort:
+ if callable(sort):
+ options = sorted(self.options, key=cmp_to_key(lambda x,y: sort(x.key,y.key)))
+ elif sort is True:
options = sorted(self.options, key=lambda x: x.key)
else:
options = self.options