Add the ability to map keywords to ListOption (like we already do with EnumOption).
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 23 Nov 2004 18:03:51 +0000 (18:03 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 23 Nov 2004 18:03:51 +0000 (18:03 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1175 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/CHANGES.txt
src/engine/SCons/Options/ListOption.py
src/engine/SCons/Options/ListOptionTests.py
test/Options/ListOption.py

index 2f504a69e906d7a208a37baf3faa28ac2a773b8d..870377e229fe1582231970f268c6ad86795bad7f 100644 (file)
@@ -7536,7 +7536,7 @@ and all input values will be
 converted to lower case.
 
 .TP
-.RI ListOption( key ", " help ", " default ", " names )
+.RI ListOption( key ", " help ", " default ", " names ", [", map ])
 Return a tuple of arguments
 to set up an option
 whose value may be one or more
@@ -7560,6 +7560,14 @@ with all values separated by commas.
 The default may be a string of
 comma-separated default values,
 or a list of the default values.
+The optional
+.I map
+argument is a dictionary
+that can be used to convert
+input values into specific legal values
+in the
+.I names
+list.
 
 .TP
 .RI PackageOption( key ", " help ", " default )
index 62d691a0329e9df442dc65a1b1ad4a825d8f2a7b..48483d185a68d0e4f9767afce8bb3de862bcfdfc 100644 (file)
@@ -139,6 +139,9 @@ RELEASE 0.97 - XXX
     $SHF90COMSTR, $SHF95COMSTR, $SHFORTRANCOMSTR, $SHLINKCOMSTR and
     $YACCCOMSTR.
 
+  - Add an optional "map" keyword argument to ListOption() that takes a
+    dictionary to map user-specified values to legal values from the list
+    (like EnumOption() already doee).
 
   From Wayne Lee:
 
index 903d52b180455d63bcd58942d50c033cf1df659b..d14b22ac9c3dcdba37fc0acc54f88ff9e111e1b3 100644 (file)
@@ -89,7 +89,7 @@ class _ListOption(UserList.UserList):
     def __repr__(self):
         return self.__str__()
     
-def _converter(val, allowedElems):
+def _converter(val, allowedElems, mapdict):
     """
     """
     if val == 'none':
@@ -98,10 +98,8 @@ def _converter(val, allowedElems):
         val = allowedElems
     else:
         val = filter(None, string.split(val, ','))
-        notAllowed = []
-        for v in val:
-            if not v in allowedElems:
-                notAllowed.append(v)
+        val = map(lambda v, m=mapdict: m.get(v, v), val)
+        notAllowed = filter(lambda v, aE=allowedElems: not v in aE, val)
         if notAllowed:
             raise ValueError("Invalid value(s) for option: %s" %
                              string.join(notAllowed, ','))
@@ -115,7 +113,7 @@ def _converter(val, allowedElems):
 ##     return 1
 
 
-def ListOption(key, help, default, names):
+def ListOption(key, help, default, names, map={}):
     """
     The input parameters describe a 'package list' option, thus they
     are returned with the correct converter and validater appended. The
@@ -132,4 +130,4 @@ def ListOption(key, help, default, names):
         '\n    ')
     return (key, help, default,
             None, #_validator,
-            lambda val, elems=names: _converter(val, elems))
+            lambda val, elems=names, m=map: _converter(val, elems, m))
index ec604f8123b45053fdc79d354422001429488e31..a892e18b5672bc37253490af26ccc4b0075d81bb 100644 (file)
@@ -56,7 +56,8 @@ class ListOptionTestCase(unittest.TestCase):
         """Test the ListOption converter"""
         opts = SCons.Options.Options()
         opts.Add(SCons.Options.ListOption('test', 'test option help', 'all',
-                                          ['one', 'two', 'three']))
+                                          ['one', 'two', 'three'],
+                                          {'ONE':'one', 'TWO':'two'}))
 
         o = opts.options[0]
 
@@ -68,9 +69,13 @@ class ListOptionTestCase(unittest.TestCase):
 
         x = o.converter('one')
         assert str(x) == 'one', x
+        x = o.converter('ONE')
+        assert str(x) == 'one', x
 
         x = o.converter('two')
         assert str(x) == 'two', x
+        x = o.converter('TWO')
+        assert str(x) == 'two', x
 
         x = o.converter('three')
         assert str(x) == 'three', x
@@ -96,6 +101,9 @@ class ListOptionTestCase(unittest.TestCase):
         x = o.converter('three,two,one')
         assert str(x) == 'all', x
 
+        x = o.converter('three,ONE,TWO')
+        assert str(x) == 'all', x
+
         caught = None
         try:
             x = o.converter('no_match')
index 3f0c426368a482304cb361c79aca473eec66f65a..5dbe0c372e92bcf84ce6e0bc90f100e242d4a362 100644 (file)
@@ -51,7 +51,8 @@ opts.AddOptions(
     ListOption('shared',
                'libraries to build as shared libraries',
                'all',
-               names = list_of_libs),
+               names = list_of_libs,
+               map = {'GL':'gl', 'QT':'qt'}),
     )
 
 env = Environment(options=opts)
@@ -77,13 +78,17 @@ test.run(arguments='shared=x11,ical')
 check(['ical,x11', '1', 'ical x11', 'ical x11'])
 test.run(arguments='shared=x11,,ical,,')
 check(['ical,x11', '1', 'ical x11', 'ical x11'])
+test.run(arguments='shared=GL')
+check(['gl', '0', 'gl', 'gl'])
+test.run(arguments='shared=QT,GL')
+check(['gl,qt', '0', 'gl qt', 'gl qt'])
 
 
 test.run(arguments='shared=foo',
          stderr = """
 scons: *** Error converting option: shared
 Invalid value(s) for option: foo
-File "SConstruct", line 14, in ?
+File "SConstruct", line 15, in ?
 """, status=2)
 
 # be paranoid in testing some more combinations
@@ -92,28 +97,28 @@ test.run(arguments='shared=foo,ical',
          stderr = """
 scons: *** Error converting option: shared
 Invalid value(s) for option: foo
-File "SConstruct", line 14, in ?
+File "SConstruct", line 15, in ?
 """, status=2)
 
 test.run(arguments='shared=ical,foo',
          stderr = """
 scons: *** Error converting option: shared
 Invalid value(s) for option: foo
-File "SConstruct", line 14, in ?
+File "SConstruct", line 15, in ?
 """, status=2)
 
 test.run(arguments='shared=ical,foo,x11',
          stderr = """
 scons: *** Error converting option: shared
 Invalid value(s) for option: foo
-File "SConstruct", line 14, in ?
+File "SConstruct", line 15, in ?
 """, status=2)
 
 test.run(arguments='shared=foo,x11,,,bar',
          stderr = """
 scons: *** Error converting option: shared
 Invalid value(s) for option: foo,bar
-File "SConstruct", line 14, in ?
+File "SConstruct", line 15, in ?
 """, status=2)
 
 test.write('SConstruct', """