diff options
| author | Steven Knight <knight@baldmt.com> | 2008-04-17 06:35:51 (GMT) |
|---|---|---|
| committer | Steven Knight <knight@baldmt.com> | 2008-04-17 06:35:51 (GMT) |
| commit | 12ced93c8d443babcf3ba0c0a3503ed6a8fed2d9 (patch) | |
| tree | 340da0ff0ef5002982fcfd5ee2a2a5e34a4bf5e0 /src/engine/SCons/Options | |
| parent | f80d3313d70eace1274f0b5ffbdc53b19acf8250 (diff) | |
| download | SCons-12ced93c8d443babcf3ba0c0a3503ed6a8fed2d9.zip SCons-12ced93c8d443babcf3ba0c0a3503ed6a8fed2d9.tar.gz SCons-12ced93c8d443babcf3ba0c0a3503ed6a8fed2d9.tar.bz2 | |
Merged revisions 2725-2865 via svnmerge from
http://scons.tigris.org/svn/scons/branches/core
........
r2731 | stevenknight | 2008-04-01 09:22:37 -0700 (Tue, 01 Apr 2008) | 4 lines
Fix test/Interactive/version.py, which still had the old hard-coded
Copyright string, by moving the test copy of the Copyright string
into QMTest/TestSCons.py, where it's available to all test scripts.
........
r2732 | stevenknight | 2008-04-02 13:28:32 -0700 (Wed, 02 Apr 2008) | 3 lines
Issues 317, 323, 329: Ignore the -d, -e and -w options, which we're
not going to implement.
........
r2734 | stevenknight | 2008-04-05 07:50:49 -0700 (Sat, 05 Apr 2008) | 2 lines
Fix bootstrap.py for pre-2.3 versions of Python, which don't have __file__.
........
r2735 | stevenknight | 2008-04-05 07:54:44 -0700 (Sat, 05 Apr 2008) | 2 lines
Fix the non-breaking-hyphen regular expression(s) for Python 1.5.
........
r2736 | garyo | 2008-04-05 19:15:52 -0700 (Sat, 05 Apr 2008) | 1 line
Added Users Guide section for AddMethod.
........
r2737 | stevenknight | 2008-04-08 09:43:31 -0700 (Tue, 08 Apr 2008) | 3 lines
Don't raise strings as exceptions in the exception-handling unit tests.
That's now deprecated Python behavior.
........
r2738 | stevenknight | 2008-04-08 10:36:00 -0700 (Tue, 08 Apr 2008) | 5 lines
Address a serious inefficiency in Java builds by moving the pre-build
check for whether source files exist from the Node class to the Executor
class, so we only have to perform the check once when building a whole
bunch of targets from a whole bunch of sources.
........
r2739 | stevenknight | 2008-04-08 13:53:44 -0700 (Tue, 08 Apr 2008) | 2 lines
Add a backwards-compatibility version of the "itertools" module.
........
r2740 | stevenknight | 2008-04-08 14:12:05 -0700 (Tue, 08 Apr 2008) | 2 lines
Issue 1961: speed up SCons.Util.to_String*() functions. (Benoit Belley)
........
r2741 | stevenknight | 2008-04-08 14:15:36 -0700 (Tue, 08 Apr 2008) | 2 lines
Use the itertools.izip() method for some key Node.FS methods. (Benoit Belley)
........
r2742 | stevenknight | 2008-04-08 14:35:35 -0700 (Tue, 08 Apr 2008) | 2 lines
Issues 1961: use izip() instead of zip() where possible (Benoit Belley)
........
r2743 | stevenknight | 2008-04-08 14:48:08 -0700 (Tue, 08 Apr 2008) | 3 lines
Issue 1961: more efficient get_contents() implementation for Python
function Actions. (Benoit Belley)
........
r2744 | stevenknight | 2008-04-08 17:55:30 -0700 (Tue, 08 Apr 2008) | 3 lines
Issue 1961: make SCons.Node.* state variables global in Taskmaster.py so
we avoid unneceesary attribute fetches. (Benoit Belley)
........
r2745 | stevenknight | 2008-04-08 20:40:31 -0700 (Tue, 08 Apr 2008) | 2 lines
Issue 1961: Optimize the code in Node.get_binfo(). (Benoit Belley)
........
r2746 | stevenknight | 2008-04-08 21:05:17 -0700 (Tue, 08 Apr 2008) | 3 lines
Issue 1961: Enhance the backwards-compatibility sets() module with the
ability to compare sets. (Benoit Belley)
........
r2747 | stevenknight | 2008-04-08 22:11:20 -0700 (Tue, 08 Apr 2008) | 2 lines
Issue 1961: Optimize Executor.scan(). (Benoit Belley)
........
r2748 | stevenknight | 2008-04-08 22:17:55 -0700 (Tue, 08 Apr 2008) | 3 lines
Python 1.5 compatibility: use for p in paths.keys() for dictionaries.
(Benoit Belley)
........
r2749 | stevenknight | 2008-04-08 22:54:02 -0700 (Tue, 08 Apr 2008) | 10 lines
Issue 1961: additional build optimizations:
-- Make taskmastertrace output more useful and readable.
-- Move dependency cycle checking to avoid re-doing it.
-- Have Nodes use sets, not dictionaries, to track various things.
-- Eliminate intermediate function calls from fetching Node children.
-- Add a Task.needs_execute() method to avoid doing that check over and
over as part of needs_execute().
-- Remove the unused Node.found_includes attribute.
(Benoit Belley)
........
r2750 | stevenknight | 2008-04-09 14:47:44 -0700 (Wed, 09 Apr 2008) | 4 lines
Make target Java .class files depend *only* on the input .java files as
their sources when determining if they require rebuilding. This eliminates
O(NxM) checking for every single edge in a big, overly-connected DAG mesh.
........
r2751 | stevenknight | 2008-04-09 16:58:41 -0700 (Wed, 09 Apr 2008) | 2 lines
Remove 0.95 and 0.96* release notes.
........
r2752 | stevenknight | 2008-04-10 02:24:50 -0700 (Thu, 10 Apr 2008) | 2 lines
Issue 1956: Fix --debug=stree printing its tree twice. (Benoit Belley)
........
r2753 | stevenknight | 2008-04-10 02:33:28 -0700 (Thu, 10 Apr 2008) | 2 lines
Issue 1896: Add support for the GDC D language compiler. (Matthew Wesley)
........
r2754 | stevenknight | 2008-04-10 02:39:24 -0700 (Thu, 10 Apr 2008) | 2 lines
Fix tabs.
........
r2755 | stevenknight | 2008-04-10 02:41:50 -0700 (Thu, 10 Apr 2008) | 3 lines
Issue 1964: Fix passing variable names in a list to Return() (as
already documented in the man page!) (Mike Wake)
........
r2756 | stevenknight | 2008-04-10 02:55:40 -0700 (Thu, 10 Apr 2008) | 2 lines
Support the ability to download 2.6 candidate releases (e.g. 2.6a2).
........
r2757 | stevenknight | 2008-04-10 02:58:35 -0700 (Thu, 10 Apr 2008) | 3 lines
Issue 1669: Fix the ability to use LoadableModule() under MinGW.
(Johan Boule)
........
r2758 | stevenknight | 2008-04-10 03:03:15 -0700 (Thu, 10 Apr 2008) | 3 lines
Update the test/Interactive/tree.py script for Benoit's fix to
remove duplicate tree printing.
........
r2759 | stevenknight | 2008-04-10 06:43:44 -0700 (Thu, 10 Apr 2008) | 3 lines
Fix Tool/dmd.py when no D compiler is installed -- we don't want to
search for a path if the result is None.
........
r2760 | GregNoel | 2008-04-10 15:30:34 -0700 (Thu, 10 Apr 2008) | 1 line
Issue 2009: separate Debug.caller() by functionality
........
r2761 | stevenknight | 2008-04-11 04:47:25 -0700 (Fri, 11 Apr 2008) | 3 lines
Issue 1882: Add the scons.bat directory to %PATH% so it can find python.exe.
(Anatoly Techtonik)
........
r2762 | stevenknight | 2008-04-11 09:15:22 -0700 (Fri, 11 Apr 2008) | 4 lines
Issues 1835,1901: fix the ability to list a source file multiple
times for a target by making sure we only store unique entries in the
.sconsign file.
........
r2763 | stevenknight | 2008-04-11 10:58:26 -0700 (Fri, 11 Apr 2008) | 4 lines
Issue 1882: Fix earlier patch to scons.bat by adding ~dp0;~dp0.. to
the front of %PATH%, and only executing endlocal on NT-based systems.
(Anatoly Techtonik)
........
r2764 | stevenknight | 2008-04-11 13:06:29 -0700 (Fri, 11 Apr 2008) | 4 lines
Add a Variables object and {Bool,Envum,List,Package,Path}Variable()
functions as a first step towards eventually deprecating the
Options object and {Bool,Envum,List,Package,Path}Option() functions.
........
r2765 | stevenknight | 2008-04-11 18:13:53 -0700 (Fri, 11 Apr 2008) | 3 lines
Issue 1962: Capture a test case for ListActions that contain a
command-line string containing unicode, and Python FunctionAction.
........
r2766 | stevenknight | 2008-04-11 22:03:14 -0700 (Fri, 11 Apr 2008) | 3 lines
Issue 1933: expect .py files generated by the SWIG -python option
to be in the same (sub)directory as the target.
........
r2767 | stevenknight | 2008-04-12 06:41:57 -0700 (Sat, 12 Apr 2008) | 2 lines
Remove the SCons.Options package in favor of the new SCons.Variables package.
........
r2768 | stevenknight | 2008-04-12 13:33:52 -0700 (Sat, 12 Apr 2008) | 5 lines
Issue 1971: Move the incorporation of $CCFLAGS and $SHCCFLAGS directly
into the C++ command lines (${SHCXX,CXX}COM) instead of through indirect
expansion of $CXXFLAGS and $SHCXXFLAGS. This requires removing -fPIC
from the default setting of $SHCXXFLAGS under the GNU toolchain.
........
r2769 | stevenknight | 2008-04-13 07:01:27 -0700 (Sun, 13 Apr 2008) | 3 lines
Fix __all__ definitions in the Variables/*Variable.py file that were
cause epydoc to blow up when generating developer documentation.
........
r2770 | stevenknight | 2008-04-13 11:47:49 -0700 (Sun, 13 Apr 2008) | 3 lines
Add variables= keyword argument to Environment() creation as a first
step towards deprecating options=.
........
r2771 | stevenknight | 2008-04-13 11:54:19 -0700 (Sun, 13 Apr 2008) | 2 lines
Correct underscore-instead-of-hyphen misspellings in option names.
........
r2772 | bdbaddog | 2008-04-13 17:39:21 -0700 (Sun, 13 Apr 2008) | 3 lines
Changes to fix 15 tests which were failing on cygwin.
........
r2773 | GregNoel | 2008-04-13 22:31:07 -0700 (Sun, 13 Apr 2008) | 1 line
Various fixes to tests on Darwin using 1.5.2
........
r2774 | stevenknight | 2008-04-14 15:00:44 -0700 (Mon, 14 Apr 2008) | 2 lines
Python 1.5.2 fix in new test/SWIG/subdir.py script (use the -classic option).
........
r2775 | belley | 2008-04-14 18:02:40 -0700 (Mon, 14 Apr 2008) | 32 lines
Dont use KeyboardInterrupt to stop a build! [Issue 1907]
SCons would often hang after pressing Ctrl-C. I started investigating and I
realized that most of the Python libraries are not really safe with respect to
asynchronous exceptions. Although,there are enough try/finally blocks to handle
exceptions thrown synchronously by the library code, the Python libraries are
not always protected against exceptions being thrown asynchronously, such as a
KeyboardInterrupt being thrown at a completely random location.
For example, the function Queue.empty() does not protect its mutex with a
try/finally block. If the KeyboardInterrupt exception gets thrown while the
mutex is held, any further attempt to access the Queue will lead to dead-lock
(explaining why SCons hangs sometimes after pressing CTRL-C). Even the
threading.Condition condition variables are not async-exception safe. It
therefore seems a lost battle to try to stop a build by raising an exception.
Instead, I have implemented a signal handler that tells the Jobs (and its
associated Taskmaster) to stop the build. I have been careful to wait after the
.sconsign file has been written back to re-install the default SIGINT signal
handler that raises a KeyboardInterrupt exception.
This patch is submitted against changeset 2773 of branches/core. The
regression test suite has been run on RHEL4 using Pyhon 2.5.1 and
1.5.2. My team has been using an SCons build with this patch for a
while now on Windows, Linux and OSX.
See:
http://scons.tigris.org/issues/show_bug.cgi?id=1907
Benoit Belley
........
r2777 | cournape | 2008-04-14 20:11:56 -0700 (Mon, 14 Apr 2008) | 3 lines
Initialized merge tracking via "svnmerge" with revisions "1-2776" from
http://scons.tigris.org/svn/scons/branches/fortran_refactor
........
r2788 | stevenknight | 2008-04-14 22:09:27 -0700 (Mon, 14 Apr 2008) | 2 lines
Fix the print the "script" line in the --version output.
........
r2789 | stevenknight | 2008-04-14 22:18:27 -0700 (Mon, 14 Apr 2008) | 2 lines
Add a __COPYRIGHT__ line.
........
r2790 | stevenknight | 2008-04-14 22:20:39 -0700 (Mon, 14 Apr 2008) | 3 lines
Issue 2008: in checkpoint releases, use a '.' to separate (e.g.) 0.98.0
from 0d20080414.
........
r2817 | belley | 2008-04-15 06:44:21 -0700 (Tue, 15 Apr 2008) | 13 lines
TestSCons.up_to_date() should use match_re_dotall
I changed TestSCons.up_to_date() to use match_re_dotall instead of
match_exact. This is necessary so that I can call up_to_date() with
the TestSCons.deprecated_python_expr error message in one of my test.
Note that TestSCons.not_up_to_date() is already using match_re_dotall.
Ran the test suite on both Python 2.5.1 and 1.5.2.
Benoit
........
r2818 | belley | 2008-04-15 12:10:52 -0700 (Tue, 15 Apr 2008) | 10 lines
Improved the multiple-parents.py test to also tests the following
cases:
d) Some children are ignored
e) Some children are pre-requesites
f) Some sources are missing
The test still passes. No extra bug were found.
........
r2850 | stevenknight | 2008-04-16 11:15:24 -0700 (Wed, 16 Apr 2008) | 4 lines
Fix problems with the __del__() method referencing other module functions
through global variables, which can get deleted out from under us at
shutdown.
........
r2851 | stevenknight | 2008-04-16 11:17:07 -0700 (Wed, 16 Apr 2008) | 4 lines
Fix use of --interactive with -u/-U/-D and VariantDir() by making the
method that cleans Node states between interactive commands aware of
the alter_targets() method that tells us about an associated VariantDir().
........
Diffstat (limited to 'src/engine/SCons/Options')
| -rw-r--r-- | src/engine/SCons/Options/.cvsignore | 1 | ||||
| -rw-r--r-- | src/engine/SCons/Options/BoolOption.py | 86 | ||||
| -rw-r--r-- | src/engine/SCons/Options/BoolOptionTests.py | 123 | ||||
| -rw-r--r-- | src/engine/SCons/Options/EnumOption.py | 101 | ||||
| -rw-r--r-- | src/engine/SCons/Options/EnumOptionTests.py | 198 | ||||
| -rw-r--r-- | src/engine/SCons/Options/ListOption.py | 133 | ||||
| -rw-r--r-- | src/engine/SCons/Options/ListOptionTests.py | 128 | ||||
| -rw-r--r-- | src/engine/SCons/Options/OptionsTests.py | 552 | ||||
| -rw-r--r-- | src/engine/SCons/Options/PackageOption.py | 104 | ||||
| -rw-r--r-- | src/engine/SCons/Options/PackageOptionTests.py | 120 | ||||
| -rw-r--r-- | src/engine/SCons/Options/PathOption.py | 139 | ||||
| -rw-r--r-- | src/engine/SCons/Options/PathOptionTests.py | 231 | ||||
| -rw-r--r-- | src/engine/SCons/Options/__init__.py | 306 |
13 files changed, 0 insertions, 2222 deletions
diff --git a/src/engine/SCons/Options/.cvsignore b/src/engine/SCons/Options/.cvsignore deleted file mode 100644 index 0d20b64..0000000 --- a/src/engine/SCons/Options/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.pyc diff --git a/src/engine/SCons/Options/BoolOption.py b/src/engine/SCons/Options/BoolOption.py deleted file mode 100644 index 80b607d..0000000 --- a/src/engine/SCons/Options/BoolOption.py +++ /dev/null @@ -1,86 +0,0 @@ -"""engine.SCons.Options.BoolOption - -This file defines the option type for SCons implementing true/false values. - -Usage example: - - opts = Options() - opts.Add(BoolOption('embedded', 'build for an embedded system', 0)) - ... - if env['embedded'] == 1: - ... -""" - -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -__all__ = ('BoolOption') - -import string - -import SCons.compat -import SCons.Errors - -__true_strings = ('y', 'yes', 'true', 't', '1', 'on' , 'all' ) -__false_strings = ('n', 'no', 'false', 'f', '0', 'off', 'none') - - -def _text2bool(val): - """ - Converts strings to True/False depending on the 'truth' expressed by - the string. If the string can't be converted, the original value - will be returned. - - See '__true_strings' and '__false_strings' for values considered - 'true' or 'false respectivly. - - This is usable as 'converter' for SCons' Options. - """ - lval = string.lower(val) - if lval in __true_strings: return True - if lval in __false_strings: return False - raise ValueError("Invalid value for boolean option: %s" % val) - - -def _validator(key, val, env): - """ - Validates the given value to be either '0' or '1'. - - This is usable as 'validator' for SCons' Options. - """ - if not env[key] in (True, False): - raise SCons.Errors.UserError( - 'Invalid value for boolean option %s: %s' % (key, env[key])) - - -def BoolOption(key, help, default): - """ - The input parameters describe a boolen option, thus they are - returned with the correct converter and validator appended. The - 'help' text will by appended by '(yes|no) to show the valid - valued. The result is usable for input to opts.Add(). - """ - return (key, '%s (yes|no)' % help, default, - _validator, _text2bool) diff --git a/src/engine/SCons/Options/BoolOptionTests.py b/src/engine/SCons/Options/BoolOptionTests.py deleted file mode 100644 index 07b5b79..0000000 --- a/src/engine/SCons/Options/BoolOptionTests.py +++ /dev/null @@ -1,123 +0,0 @@ -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import SCons.compat - -import sys -import unittest - -import SCons.Errors -import SCons.Options - -class BoolOptionTestCase(unittest.TestCase): - def test_BoolOption(self): - """Test BoolOption creation""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.BoolOption('test', 'test option help', 0)) - - o = opts.options[0] - assert o.key == 'test', o.key - assert o.help == 'test option help (yes|no)', o.help - assert o.default == 0, o.default - assert not o.validator is None, o.validator - assert not o.converter is None, o.converter - - def test_converter(self): - """Test the BoolOption converter""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.BoolOption('test', 'test option help', 0)) - - o = opts.options[0] - - true_values = [ - 'y', 'Y', - 'yes', 'YES', - 't', 'T', - 'true', 'TRUE', - 'on', 'ON', - 'all', 'ALL', - '1', - ] - false_values = [ - 'n', 'N', - 'no', 'NO', - 'f', 'F', - 'false', 'FALSE', - 'off', 'OFF', - 'none', 'NONE', - '0', - ] - - for t in true_values: - x = o.converter(t) - assert x, "converter returned false for '%s'" % t - - for f in false_values: - x = o.converter(f) - assert not x, "converter returned true for '%s'" % f - - caught = None - try: - o.converter('x') - except ValueError: - caught = 1 - assert caught, "did not catch expected ValueError" - - def test_validator(self): - """Test the BoolOption validator""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.BoolOption('test', 'test option help', 0)) - - o = opts.options[0] - - env = { - 'T' : True, - 'F' : False, - 'N' : 'xyzzy', - } - - o.validator('T', 0, env) - - o.validator('F', 0, env) - - caught = None - try: - o.validator('N', 0, env) - except SCons.Errors.UserError: - caught = 1 - assert caught, "did not catch expected UserError for N" - - caught = None - try: - o.validator('NOSUCHKEY', 0, env) - except KeyError: - caught = 1 - assert caught, "did not catch expected KeyError for NOSUCHKEY" - - -if __name__ == "__main__": - suite = unittest.makeSuite(BoolOptionTestCase, 'test_') - if not unittest.TextTestRunner().run(suite).wasSuccessful(): - sys.exit(1) diff --git a/src/engine/SCons/Options/EnumOption.py b/src/engine/SCons/Options/EnumOption.py deleted file mode 100644 index d4e2ac1..0000000 --- a/src/engine/SCons/Options/EnumOption.py +++ /dev/null @@ -1,101 +0,0 @@ -"""engine.SCons.Options.EnumOption - -This file defines the option type for SCons allowing only specified -input-values. - -Usage example: - - opts = Options() - opts.Add(EnumOption('debug', 'debug output and symbols', 'no', - allowed_values=('yes', 'no', 'full'), - map={}, ignorecase=2)) - ... - if env['debug'] == 'full': - ... -""" - -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -__all__ = ('EnumOption',) - -import string - -import SCons.Errors - -def _validator(key, val, env, vals): - if not val in vals: - raise SCons.Errors.UserError( - 'Invalid value for option %s: %s' % (key, val)) - - -def EnumOption(key, help, default, allowed_values, map={}, ignorecase=0): - """ - The input parameters describe a option with only certain values - allowed. They are returned with an appropriate converter and - validator appended. The result is usable for input to - Options.Add(). - - 'key' and 'default' are the values to be passed on to Options.Add(). - - 'help' will be appended by the allowed values automatically - - 'allowed_values' is a list of strings, which are allowed as values - for this option. - - The 'map'-dictionary may be used for converting the input value - into canonical values (eg. for aliases). - - 'ignorecase' defines the behaviour of the validator: - - If ignorecase == 0, the validator/converter are case-sensitive. - If ignorecase == 1, the validator/converter are case-insensitive. - If ignorecase == 2, the validator/converter is case-insensitive and - the converted value will always be lower-case. - - The 'validator' tests whether the value is in the list of allowed - values. The 'converter' converts input values according to the - given 'map'-dictionary (unmapped input values are returned - unchanged). - """ - help = '%s (%s)' % (help, string.join(allowed_values, '|')) - # define validator - if ignorecase >= 1: - validator = lambda key, val, env, vals=allowed_values: \ - _validator(key, string.lower(val), env, vals) - else: - validator = lambda key, val, env, vals=allowed_values: \ - _validator(key, val, env, vals) - # define converter - if ignorecase == 2: - converter = lambda val, map=map: \ - string.lower(map.get(string.lower(val), val)) - elif ignorecase == 1: - converter = lambda val, map=map: \ - map.get(string.lower(val), val) - else: - converter = lambda val, map=map: \ - map.get(val, val) - return (key, help, default, validator, converter) diff --git a/src/engine/SCons/Options/EnumOptionTests.py b/src/engine/SCons/Options/EnumOptionTests.py deleted file mode 100644 index 20ae6c3..0000000 --- a/src/engine/SCons/Options/EnumOptionTests.py +++ /dev/null @@ -1,198 +0,0 @@ -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import sys -import unittest - -import SCons.Errors -import SCons.Options - -class EnumOptionTestCase(unittest.TestCase): - def test_EnumOption(self): - """Test EnumOption creation""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.EnumOption('test', 'test option help', 0, - ['one', 'two', 'three'], - {})) - - o = opts.options[0] - assert o.key == 'test', o.key - assert o.help == 'test option help (one|two|three)', o.help - assert o.default == 0, o.default - assert not o.validator is None, o.validator - assert not o.converter is None, o.converter - - def test_converter(self): - """Test the EnumOption converter""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.EnumOption('test', 'test option help', 0, - ['one', 'two', 'three'])) - - o = opts.options[0] - - for a in ['one', 'two', 'three', 'no_match']: - x = o.converter(a) - assert x == a, x - - opts = SCons.Options.Options() - opts.Add(SCons.Options.EnumOption('test', 'test option help', 0, - ['one', 'two', 'three'], - {'1' : 'one', - '2' : 'two', - '3' : 'three'})) - - o = opts.options[0] - - x = o.converter('one') - assert x == 'one', x - x = o.converter('1') - assert x == 'one', x - - x = o.converter('two') - assert x == 'two', x - x = o.converter('2') - assert x == 'two', x - - x = o.converter('three') - assert x == 'three', x - x = o.converter('3') - assert x == 'three', x - - opts = SCons.Options.Options() - opts.Add(SCons.Options.EnumOption('test0', 'test option help', 0, - ['one', 'two', 'three'], - {'a' : 'one', - 'b' : 'two', - 'c' : 'three'}, - ignorecase=0)) - opts.Add(SCons.Options.EnumOption('test1', 'test option help', 0, - ['one', 'two', 'three'], - {'a' : 'one', - 'b' : 'two', - 'c' : 'three'}, - ignorecase=1)) - opts.Add(SCons.Options.EnumOption('test2', 'test option help', 0, - ['one', 'two', 'three'], - {'a' : 'one', - 'b' : 'two', - 'c' : 'three'}, - ignorecase=2)) - - o0 = opts.options[0] - o1 = opts.options[1] - o2 = opts.options[2] - - table = { - 'one' : ['one', 'one', 'one'], - 'One' : ['One', 'One', 'one'], - 'ONE' : ['ONE', 'ONE', 'one'], - 'two' : ['two', 'two', 'two'], - 'twO' : ['twO', 'twO', 'two'], - 'TWO' : ['TWO', 'TWO', 'two'], - 'three' : ['three', 'three', 'three'], - 'thRee' : ['thRee', 'thRee', 'three'], - 'THREE' : ['THREE', 'THREE', 'three'], - 'a' : ['one', 'one', 'one'], - 'A' : ['A', 'one', 'one'], - 'b' : ['two', 'two', 'two'], - 'B' : ['B', 'two', 'two'], - 'c' : ['three', 'three', 'three'], - 'C' : ['C', 'three', 'three'], - } - - for k, l in table.items(): - x = o0.converter(k) - assert x == l[0], "o0 got %s, expected %s" % (x, l[0]) - x = o1.converter(k) - assert x == l[1], "o1 got %s, expected %s" % (x, l[1]) - x = o2.converter(k) - assert x == l[2], "o2 got %s, expected %s" % (x, l[2]) - - def test_validator(self): - """Test the EnumOption validator""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.EnumOption('test0', 'test option help', 0, - ['one', 'two', 'three'], - {'a' : 'one', - 'b' : 'two', - 'c' : 'three'}, - ignorecase=0)) - opts.Add(SCons.Options.EnumOption('test1', 'test option help', 0, - ['one', 'two', 'three'], - {'a' : 'one', - 'b' : 'two', - 'c' : 'three'}, - ignorecase=1)) - opts.Add(SCons.Options.EnumOption('test2', 'test option help', 0, - ['one', 'two', 'three'], - {'a' : 'one', - 'b' : 'two', - 'c' : 'three'}, - ignorecase=2)) - - o0 = opts.options[0] - o1 = opts.options[1] - o2 = opts.options[2] - - def valid(o, v): - o.validator('X', v, {}) - - def invalid(o, v): - caught = None - try: - o.validator('X', v, {}) - except SCons.Errors.UserError: - caught = 1 - assert caught, "did not catch expected UserError for o = %s, v = %s" % (o.key, v) - - table = { - 'one' : [ valid, valid, valid], - 'One' : [invalid, valid, valid], - 'ONE' : [invalid, valid, valid], - 'two' : [ valid, valid, valid], - 'twO' : [invalid, valid, valid], - 'TWO' : [invalid, valid, valid], - 'three' : [ valid, valid, valid], - 'thRee' : [invalid, valid, valid], - 'THREE' : [invalid, valid, valid], - 'a' : [invalid, invalid, invalid], - 'A' : [invalid, invalid, invalid], - 'b' : [invalid, invalid, invalid], - 'B' : [invalid, invalid, invalid], - 'c' : [invalid, invalid, invalid], - 'C' : [invalid, invalid, invalid], - 'no_v' : [invalid, invalid, invalid], - } - - for v, l in table.items(): - l[0](o0, v) - l[1](o1, v) - l[2](o2, v) - - -if __name__ == "__main__": - suite = unittest.makeSuite(EnumOptionTestCase, 'test_') - if not unittest.TextTestRunner().run(suite).wasSuccessful(): - sys.exit(1) diff --git a/src/engine/SCons/Options/ListOption.py b/src/engine/SCons/Options/ListOption.py deleted file mode 100644 index 6954905..0000000 --- a/src/engine/SCons/Options/ListOption.py +++ /dev/null @@ -1,133 +0,0 @@ -"""engine.SCons.Options.ListOption - -This file defines the option type for SCons implementing 'lists'. - -A 'list' option may either be 'all', 'none' or a list of names -separated by comma. After the option has been processed, the option -value holds either the named list elements, all list elemens or no -list elements at all. - -Usage example: - - list_of_libs = Split('x11 gl qt ical') - - opts = Options() - opts.Add(ListOption('shared', - 'libraries to build as shared libraries', - 'all', - elems = list_of_libs)) - ... - for lib in list_of_libs: - if lib in env['shared']: - env.SharedObject(...) - else: - env.Object(...) -""" - -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -# Know Bug: This should behave like a Set-Type, but does not really, -# since elements can occur twice. - -__all__ = ('ListOption',) - -import string -import UserList - -import SCons.Util - - -class _ListOption(UserList.UserList): - def __init__(self, initlist=[], allowedElems=[]): - UserList.UserList.__init__(self, filter(None, initlist)) - self.allowedElems = allowedElems[:] - self.allowedElems.sort() - - def __cmp__(self, other): - raise NotImplementedError - def __eq__(self, other): - raise NotImplementedError - def __ge__(self, other): - raise NotImplementedError - def __gt__(self, other): - raise NotImplementedError - def __le__(self, other): - raise NotImplementedError - def __lt__(self, other): - raise NotImplementedError - def __str__(self): - if len(self) == 0: - return 'none' - self.data.sort() - if self.data == self.allowedElems: - return 'all' - else: - return string.join(self, ',') - def prepare_to_store(self): - return self.__str__() - -def _converter(val, allowedElems, mapdict): - """ - """ - if val == 'none': - val = [] - elif val == 'all': - val = allowedElems - else: - val = filter(None, string.split(val, ',')) - 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, ',')) - return _ListOption(val, allowedElems) - - -## def _validator(key, val, env): -## """ -## """ -## # todo: write validater for pgk list -## return 1 - - -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 - result is usable for input to opts.Add() . - - A 'package list' option may either be 'all', 'none' or a list of - package names (separated by space). - """ - names_str = 'allowed names: %s' % string.join(names, ' ') - if SCons.Util.is_List(default): - default = string.join(default, ',') - help = string.join( - (help, '(all|none|comma-separated list of names)', names_str), - '\n ') - return (key, help, default, - None, #_validator, - lambda val, elems=names, m=map: _converter(val, elems, m)) diff --git a/src/engine/SCons/Options/ListOptionTests.py b/src/engine/SCons/Options/ListOptionTests.py deleted file mode 100644 index 22378bc..0000000 --- a/src/engine/SCons/Options/ListOptionTests.py +++ /dev/null @@ -1,128 +0,0 @@ -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import copy -import sys -import unittest - -import SCons.Errors -import SCons.Options - -class ListOptionTestCase(unittest.TestCase): - def test_ListOption(self): - """Test ListOption creation""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.ListOption('test', 'test option help', 'all', - ['one', 'two', 'three'])) - - o = opts.options[0] - assert o.key == 'test', o.key - assert o.help == 'test option help\n (all|none|comma-separated list of names)\n allowed names: one two three', repr(o.help) - assert o.default == 'all', o.default - assert o.validator is None, o.validator - assert not o.converter is None, o.converter - - opts = SCons.Options.Options() - opts.Add(SCons.Options.ListOption('test2', 'test2 help', - ['one', 'three'], - ['one', 'two', 'three'])) - - o = opts.options[0] - assert o.default == 'one,three' - - def test_converter(self): - """Test the ListOption converter""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.ListOption('test', 'test option help', 'all', - ['one', 'two', 'three'], - {'ONE':'one', 'TWO':'two'})) - - o = opts.options[0] - - x = o.converter('all') - assert str(x) == 'all', x - - x = o.converter('none') - assert str(x) == 'none', x - - 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 - - x = o.converter('one,two') - assert str(x) == 'one,two', x - x = o.converter('two,one') - assert str(x) == 'one,two', x - - x = o.converter('one,three') - assert str(x) == 'one,three', x - x = o.converter('three,one') - assert str(x) == 'one,three', x - - x = o.converter('two,three') - assert str(x) == 'three,two', x - x = o.converter('three,two') - assert str(x) == 'three,two', x - - x = o.converter('one,two,three') - assert str(x) == 'all', x - - 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') - except ValueError: - caught = 1 - assert caught, "did not catch expected ValueError" - - def test_copy(self): - """Test copying a ListOption like an Environment would""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.ListOption('test', 'test option help', 'all', - ['one', 'two', 'three'])) - - o = opts.options[0] - - l = o.converter('all') - n = l.__class__(copy.copy(l)) - -if __name__ == "__main__": - suite = unittest.makeSuite(ListOptionTestCase, 'test_') - if not unittest.TextTestRunner().run(suite).wasSuccessful(): - sys.exit(1) diff --git a/src/engine/SCons/Options/OptionsTests.py b/src/engine/SCons/Options/OptionsTests.py deleted file mode 100644 index 5ec9d7a..0000000 --- a/src/engine/SCons/Options/OptionsTests.py +++ /dev/null @@ -1,552 +0,0 @@ -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import string -import sys -import unittest -import TestSCons - -import SCons.Options -import SCons.Subst -import SCons.Warnings - - -class Environment: - def __init__(self): - self.dict = {} - def subst(self, x): - return SCons.Subst.scons_subst(x, self, gvars=self.dict) - def __setitem__(self, key, value): - self.dict[key] = value - def __getitem__(self, key): - return self.dict[key] - def has_key(self, key): - return self.dict.has_key(key) - - -def check(key, value, env): - assert int(value) == 6 * 9, "key %s = %s" % (key, repr(value)) - -# Check saved option file by executing and comparing against -# the expected dictionary -def checkSave(file, expected): - gdict = {} - ldict = {} - execfile(file, gdict, ldict) - assert expected == ldict, "%s\n...not equal to...\n%s" % (expected, ldict) - -class OptionsTestCase(unittest.TestCase): - - def test_keys(self): - """Test the Options.keys() method""" - opts = SCons.Options.Options() - - opts.Add('VAR1') - opts.Add('VAR2', - 'THE answer to THE question', - "42", - check, - lambda x: int(x) + 12) - keys = opts.keys() - assert keys == ['VAR1', 'VAR2'], keys - - def test_Add(self): - """Test adding to an Options object""" - opts = SCons.Options.Options() - - opts.Add('VAR') - opts.Add('ANSWER', - 'THE answer to THE question', - "42", - check, - lambda x: int(x) + 12) - - o = opts.options[0] - assert o.key == 'VAR' - assert o.help == '' - assert o.default == None - assert o.validator == None - assert o.converter == None - - o = opts.options[1] - assert o.key == 'ANSWER' - assert o.help == 'THE answer to THE question' - assert o.default == "42" - o.validator(o.key, o.converter(o.default), {}) - - def test_it(var, opts=opts): - exc_caught = None - try: - opts.Add(var) - except SCons.Errors.UserError: - exc_caught = 1 - assert exc_caught, "did not catch UserError for '%s'" % var - test_it('foo/bar') - test_it('foo-bar') - test_it('foo.bar') - - def test_AddOptions(self): - """Test adding a list of options to an Options object""" - opts = SCons.Options.Options() - - opts.AddOptions(('VAR2',), - ('ANSWER2', - 'THE answer to THE question', - "42", - check, - lambda x: int(x) + 12)) - - o = opts.options[0] - assert o.key == 'VAR2', o.key - assert o.help == '', o.help - assert o.default == None, o.default - assert o.validator == None, o.validator - assert o.converter == None, o.converter - - o = opts.options[1] - assert o.key == 'ANSWER2', o.key - assert o.help == 'THE answer to THE question', o.help - assert o.default == "42", o.default - o.validator(o.key, o.converter(o.default), {}) - - def test_Update(self): - """Test updating an Environment""" - - # Test that a default value is validated correctly. - test = TestSCons.TestSCons() - file = test.workpath('custom.py') - opts = SCons.Options.Options(file) - - opts.Add('ANSWER', - 'THE answer to THE question', - "42", - check, - lambda x: int(x) + 12) - - env = Environment() - opts.Update(env) - assert env['ANSWER'] == 54 - - env = Environment() - opts.Update(env, {}) - assert env['ANSWER'] == 54 - - # Test that a bad value from the file is used and - # validation fails correctly. - test = TestSCons.TestSCons() - file = test.workpath('custom.py') - test.write('custom.py', 'ANSWER=54') - opts = SCons.Options.Options(file) - - opts.Add('ANSWER', - 'THE answer to THE question', - "42", - check, - lambda x: int(x) + 12) - - env = Environment() - exc_caught = None - try: - opts.Update(env) - except AssertionError: - exc_caught = 1 - assert exc_caught, "did not catch expected assertion" - - env = Environment() - exc_caught = None - try: - opts.Update(env, {}) - except AssertionError: - exc_caught = 1 - assert exc_caught, "did not catch expected assertion" - - # Test that a good value from the file is used and validated. - test = TestSCons.TestSCons() - file = test.workpath('custom.py') - test.write('custom.py', 'ANSWER=42') - opts = SCons.Options.Options(file) - - opts.Add('ANSWER', - 'THE answer to THE question', - "10", - check, - lambda x: int(x) + 12) - - env = Environment() - opts.Update(env) - assert env['ANSWER'] == 54 - - env = Environment() - opts.Update(env, {}) - assert env['ANSWER'] == 54 - - # Test that a bad value from an args dictionary passed to - # Update() is used and validation fails correctly. - test = TestSCons.TestSCons() - file = test.workpath('custom.py') - test.write('custom.py', 'ANSWER=10') - opts = SCons.Options.Options(file) - - opts.Add('ANSWER', - 'THE answer to THE question', - "12", - check, - lambda x: int(x) + 12) - - env = Environment() - exc_caught = None - try: - opts.Update(env, {'ANSWER':'54'}) - except AssertionError: - exc_caught = 1 - assert exc_caught, "did not catch expected assertion" - - # Test that a good value from an args dictionary - # passed to Update() is used and validated. - test = TestSCons.TestSCons() - file = test.workpath('custom.py') - test.write('custom.py', 'ANSWER=10') - opts = SCons.Options.Options(file) - - opts.Add('ANSWER', - 'THE answer to THE question', - "12", - check, - lambda x: int(x) + 12) - - env = Environment() - opts.Update(env, {'ANSWER':'42'}) - assert env['ANSWER'] == 54 - - # Test against a former bug. If we supply a converter, - # but no default, the value should *not* appear in the - # Environment if no value is specified in the options file - # or args. - test = TestSCons.TestSCons() - file = test.workpath('custom.py') - opts = SCons.Options.Options(file) - - opts.Add('ANSWER', - help='THE answer to THE question', - converter=str) - - env = Environment() - opts.Update(env, {}) - assert not env.has_key('ANSWER') - - # Test that a default value of None is all right. - test = TestSCons.TestSCons() - file = test.workpath('custom.py') - opts = SCons.Options.Options(file) - - opts.Add('ANSWER', - "This is the answer", - None, - check) - - env = Environment() - opts.Update(env, {}) - assert not env.has_key('ANSWER') - - def test_args(self): - """Test updating an Environment with arguments overridden""" - - # Test that a bad (command-line) argument is used - # and the validation fails correctly. - test = TestSCons.TestSCons() - file = test.workpath('custom.py') - test.write('custom.py', 'ANSWER=42') - opts = SCons.Options.Options(file, {'ANSWER':54}) - - opts.Add('ANSWER', - 'THE answer to THE question', - "42", - check, - lambda x: int(x) + 12) - - env = Environment() - exc_caught = None - try: - opts.Update(env) - except AssertionError: - exc_caught = 1 - assert exc_caught, "did not catch expected assertion" - - # Test that a good (command-line) argument is used and validated. - test = TestSCons.TestSCons() - file = test.workpath('custom.py') - test.write('custom.py', 'ANSWER=54') - opts = SCons.Options.Options(file, {'ANSWER':42}) - - opts.Add('ANSWER', - 'THE answer to THE question', - "54", - check, - lambda x: int(x) + 12) - - env = Environment() - opts.Update(env) - assert env['ANSWER'] == 54 - - # Test that a (command-line) argument is overridden by a dictionary - # supplied to Update() and the dictionary value is validated correctly. - test = TestSCons.TestSCons() - file = test.workpath('custom.py') - test.write('custom.py', 'ANSWER=54') - opts = SCons.Options.Options(file, {'ANSWER':54}) - - opts.Add('ANSWER', - 'THE answer to THE question', - "54", - check, - lambda x: int(x) + 12) - - env = Environment() - opts.Update(env, {'ANSWER':42}) - assert env['ANSWER'] == 54 - - def test_Save(self): - """Testing saving Options""" - - test = TestSCons.TestSCons() - cache_file = test.workpath('cached.options') - opts = SCons.Options.Options() - - def bool_converter(val): - if val in [1, 'y']: val = 1 - if val in [0, 'n']: val = 0 - return val - - # test saving out empty file - opts.Add('OPT_VAL', - 'An option to test', - 21, - None, - None) - opts.Add('OPT_VAL_2', - default='foo') - opts.Add('OPT_VAL_3', - default=1) - opts.Add('OPT_BOOL_0', - default='n', - converter=bool_converter) - opts.Add('OPT_BOOL_1', - default='y', - converter=bool_converter) - opts.Add('OPT_BOOL_2', - default=0, - converter=bool_converter) - - env = Environment() - opts.Update(env, {'OPT_VAL_3' : 2}) - assert env['OPT_VAL'] == 21, env['OPT_VAL'] - assert env['OPT_VAL_2'] == 'foo', env['OPT_VAL_2'] - assert env['OPT_VAL_3'] == 2, env['OPT_VAL_3'] - assert env['OPT_BOOL_0'] == 0, env['OPT_BOOL_0'] - assert env['OPT_BOOL_1'] == 1, env['OPT_BOOL_1'] - assert env['OPT_BOOL_2'] == '0', env['OPT_BOOL_2'] - - env['OPT_VAL_2'] = 'bar' - env['OPT_BOOL_0'] = 0 - env['OPT_BOOL_1'] = 1 - env['OPT_BOOL_2'] = 2 - - opts.Save(cache_file, env) - checkSave(cache_file, { 'OPT_VAL_2' : 'bar', - 'OPT_VAL_3' : 2, - 'OPT_BOOL_2' : 2}) - - # Test against some old bugs - class Foo: - def __init__(self, x): - self.x = x - def __str__(self): - return self.x - - test = TestSCons.TestSCons() - cache_file = test.workpath('cached.options') - opts = SCons.Options.Options() - - opts.Add('THIS_USED_TO_BREAK', - 'An option to test', - "Default") - - opts.Add('THIS_ALSO_BROKE', - 'An option to test', - "Default2") - - opts.Add('THIS_SHOULD_WORK', - 'An option to test', - Foo('bar')) - - env = Environment() - opts.Update(env, { 'THIS_USED_TO_BREAK' : "Single'Quotes'In'String", - 'THIS_ALSO_BROKE' : "\\Escape\nSequences\t", - 'THIS_SHOULD_WORK' : Foo('baz') }) - opts.Save(cache_file, env) - checkSave(cache_file, { 'THIS_USED_TO_BREAK' : "Single'Quotes'In'String", - 'THIS_ALSO_BROKE' : "\\Escape\nSequences\t", - 'THIS_SHOULD_WORK' : 'baz' }) - - def test_GenerateHelpText(self): - """Test generating the default format help text""" - opts = SCons.Options.Options() - - opts.Add('ANSWER', - 'THE answer to THE question', - "42", - check, - lambda x: int(x) + 12) - - opts.Add('B', - 'b - alpha test', - "42", - check, - lambda x: int(x) + 12) - - opts.Add('A', - 'a - alpha test', - "42", - check, - lambda x: int(x) + 12) - - env = Environment() - opts.Update(env, {}) - - expect = """ -ANSWER: THE answer to THE question - default: 42 - actual: 54 - -B: b - alpha test - default: 42 - actual: 54 - -A: a - alpha test - default: 42 - actual: 54 -""" - - text = opts.GenerateHelpText(env) - assert text == expect, text - - expectAlpha = """ -A: a - alpha test - default: 42 - actual: 54 - -ANSWER: THE answer to THE question - default: 42 - actual: 54 - -B: b - alpha test - default: 42 - actual: 54 -""" - text = opts.GenerateHelpText(env, sort=cmp) - assert text == expectAlpha, text - - def test_FormatOptionHelpText(self): - """Test generating custom format help text""" - opts = SCons.Options.Options() - - def my_format(env, opt, help, default, actual, aliases): - return '%s %s %s %s %s\n' % (opt, default, actual, help, aliases) - - opts.FormatOptionHelpText = my_format - - opts.Add('ANSWER', - 'THE answer to THE question', - "42", - check, - lambda x: int(x) + 12) - - opts.Add('B', - 'b - alpha test', - "42", - check, - lambda x: int(x) + 12) - - opts.Add('A', - 'a - alpha test', - "42", - check, - lambda x: int(x) + 12) - - env = Environment() - opts.Update(env, {}) - - expect = """\ -ANSWER 42 54 THE answer to THE question ['ANSWER'] -B 42 54 b - alpha test ['B'] -A 42 54 a - alpha test ['A'] -""" - - text = opts.GenerateHelpText(env) - assert text == expect, text - - expectAlpha = """\ -A 42 54 a - alpha test ['A'] -ANSWER 42 54 THE answer to THE question ['ANSWER'] -B 42 54 b - alpha test ['B'] -""" - text = opts.GenerateHelpText(env, sort=cmp) - assert text == expectAlpha, text - - - -class UnknownOptionsTestCase(unittest.TestCase): - - def test_unknown(self): - """Test the UnknownOptions() method""" - opts = SCons.Options.Options() - - opts.Add('ANSWER', - 'THE answer to THE question', - "42") - - args = { - 'ANSWER' : 'answer', - 'UNKNOWN' : 'unknown', - } - - env = Environment() - opts.Update(env, args) - - r = opts.UnknownOptions() - assert r == {'UNKNOWN' : 'unknown'}, r - assert env['ANSWER'] == 'answer', env['ANSWER'] - - - -if __name__ == "__main__": - suite = unittest.TestSuite() - tclasses = [ OptionsTestCase, - UnknownOptionsTestCase ] - for tclass in tclasses: - names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) - if not unittest.TextTestRunner().run(suite).wasSuccessful(): - sys.exit(1) diff --git a/src/engine/SCons/Options/PackageOption.py b/src/engine/SCons/Options/PackageOption.py deleted file mode 100644 index 3b4f0ce..0000000 --- a/src/engine/SCons/Options/PackageOption.py +++ /dev/null @@ -1,104 +0,0 @@ -"""engine.SCons.Options.PackageOption - -This file defines the option type for SCons implementing 'package -activation'. - -To be used whenever a 'package' may be enabled/disabled and the -package path may be specified. - -Usage example: - - Examples: - x11=no (disables X11 support) - x11=yes (will search for the package installation dir) - x11=/usr/local/X11 (will check this path for existance) - - To replace autoconf's --with-xxx=yyy - - opts = Options() - opts.Add(PackageOption('x11', - 'use X11 installed here (yes = search some places', - 'yes')) - ... - if env['x11'] == True: - dir = ... search X11 in some standard places ... - env['x11'] = dir - if env['x11']: - ... build with x11 ... -""" - -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -__all__ = ('PackageOption') - -import string - -import SCons.compat -import SCons.Errors - -__enable_strings = ('1', 'yes', 'true', 'on', 'enable', 'search') -__disable_strings = ('0', 'no', 'false', 'off', 'disable') - -def _converter(val): - """ - """ - lval = string.lower(val) - if lval in __enable_strings: return True - if lval in __disable_strings: return False - #raise ValueError("Invalid value for boolean option: %s" % val) - return val - - -def _validator(key, val, env, searchfunc): - # NB: searchfunc is currenty undocumented and unsupported - """ - """ - # todo: write validator, check for path - import os - if env[key] is True: - if searchfunc: - env[key] = searchfunc(key, val) - elif env[key] and not os.path.exists(val): - raise SCons.Errors.UserError( - 'Path does not exist for option %s: %s' % (key, val)) - - -def PackageOption(key, help, default, searchfunc=None): - # NB: searchfunc is currenty undocumented and unsupported - """ - The input parameters describe a 'package list' option, thus they - are returned with the correct converter and validator appended. The - result is usable for input to opts.Add() . - - A 'package list' option may either be 'all', 'none' or a list of - package names (seperated by space). - """ - help = string.join( - (help, '( yes | no | /path/to/%s )' % key), - '\n ') - return (key, help, default, - lambda k, v, e, f=searchfunc: _validator(k,v,e,f), - _converter) diff --git a/src/engine/SCons/Options/PackageOptionTests.py b/src/engine/SCons/Options/PackageOptionTests.py deleted file mode 100644 index 68f14e5..0000000 --- a/src/engine/SCons/Options/PackageOptionTests.py +++ /dev/null @@ -1,120 +0,0 @@ -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import SCons.compat - -import sys -import unittest - -import SCons.Errors -import SCons.Options - -import TestCmd - -class PackageOptionTestCase(unittest.TestCase): - def test_PackageOption(self): - """Test PackageOption creation""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path')) - - o = opts.options[0] - assert o.key == 'test', o.key - assert o.help == 'test option help\n ( yes | no | /path/to/test )', repr(o.help) - assert o.default == '/default/path', o.default - assert not o.validator is None, o.validator - assert not o.converter is None, o.converter - - def test_converter(self): - """Test the PackageOption converter""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path')) - - o = opts.options[0] - - true_values = [ - 'yes', 'YES', - 'true', 'TRUE', - 'on', 'ON', - 'enable', 'ENABLE', - 'search', 'SEARCH', - ] - false_values = [ - 'no', 'NO', - 'false', 'FALSE', - 'off', 'OFF', - 'disable', 'DISABLE', - ] - - for t in true_values: - x = o.converter(t) - assert x, "converter returned false for '%s'" % t - - for f in false_values: - x = o.converter(f) - assert not x, "converter returned true for '%s'" % f - - x = o.converter('/explicit/path') - assert x == '/explicit/path', x - - # Make sure the converter returns True if we give it str(True) and - # False when we give it str(False). This assures consistent operation - # through a cycle of Options.Save(<file>) -> Options(<file>). - x = o.converter(str(True)) - assert x == True, "converter returned a string when given str(True)" - - x = o.converter(str(False)) - assert x == False, "converter returned a string when given str(False)" - - def test_validator(self): - """Test the PackageOption validator""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path')) - - test = TestCmd.TestCmd(workdir='') - test.write('exists', 'exists\n') - - o = opts.options[0] - - env = {'F':False, 'T':True, 'X':'x'} - - exists = test.workpath('exists') - does_not_exist = test.workpath('does_not_exist') - - o.validator('F', '/path', env) - o.validator('T', '/path', env) - o.validator('X', exists, env) - - caught = None - try: - o.validator('X', does_not_exist, env) - except SCons.Errors.UserError: - caught = 1 - assert caught, "did not catch expected UserError" - - -if __name__ == "__main__": - suite = unittest.makeSuite(PackageOptionTestCase, 'test_') - if not unittest.TextTestRunner().run(suite).wasSuccessful(): - sys.exit(1) diff --git a/src/engine/SCons/Options/PathOption.py b/src/engine/SCons/Options/PathOption.py deleted file mode 100644 index 995eeb9..0000000 --- a/src/engine/SCons/Options/PathOption.py +++ /dev/null @@ -1,139 +0,0 @@ -"""SCons.Options.PathOption - -This file defines an option type for SCons implementing path settings. - -To be used whenever a a user-specified path override should be allowed. - -Arguments to PathOption are: - option-name = name of this option on the command line (e.g. "prefix") - option-help = help string for option - option-dflt = default value for this option - validator = [optional] validator for option value. Predefined - validators are: - - PathAccept -- accepts any path setting; no validation - PathIsDir -- path must be an existing directory - PathIsDirCreate -- path must be a dir; will create - PathIsFile -- path must be a file - PathExists -- path must exist (any type) [default] - - The validator is a function that is called and which - should return True or False to indicate if the path - is valid. The arguments to the validator function - are: (key, val, env). The key is the name of the - option, the val is the path specified for the option, - and the env is the env to which the Otions have been - added. - -Usage example: - - Examples: - prefix=/usr/local - - opts = Options() - - opts = Options() - opts.Add(PathOption('qtdir', - 'where the root of Qt is installed', - qtdir, PathIsDir)) - opts.Add(PathOption('qt_includes', - 'where the Qt includes are installed', - '$qtdir/includes', PathIsDirCreate)) - opts.Add(PathOption('qt_libraries', - 'where the Qt library is installed', - '$qtdir/lib')) - -""" - -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import os -import os.path - -import SCons.Errors - -class _PathOptionClass: - - def PathAccept(self, key, val, env): - """Accepts any path, no checking done.""" - pass - - def PathIsDir(self, key, val, env): - """Validator to check if Path is a directory.""" - if not os.path.isdir(val): - if os.path.isfile(val): - m = 'Directory path for option %s is a file: %s' - else: - m = 'Directory path for option %s does not exist: %s' - raise SCons.Errors.UserError(m % (key, val)) - - def PathIsDirCreate(self, key, val, env): - """Validator to check if Path is a directory, - creating it if it does not exist.""" - if os.path.isfile(val): - m = 'Path for option %s is a file, not a directory: %s' - raise SCons.Errors.UserError(m % (key, val)) - if not os.path.isdir(val): - os.makedirs(val) - - def PathIsFile(self, key, val, env): - """validator to check if Path is a file""" - if not os.path.isfile(val): - if os.path.isdir(val): - m = 'File path for option %s is a directory: %s' - else: - m = 'File path for option %s does not exist: %s' - raise SCons.Errors.UserError(m % (key, val)) - - def PathExists(self, key, val, env): - """validator to check if Path exists""" - if not os.path.exists(val): - m = 'Path for option %s does not exist: %s' - raise SCons.Errors.UserError(m % (key, val)) - - def __call__(self, key, help, default, validator=None): - # NB: searchfunc is currenty undocumented and unsupported - """ - The input parameters describe a 'path list' option, thus they - are returned with the correct converter and validator appended. The - result is usable for input to opts.Add() . - - The 'default' option specifies the default path to use if the - user does not specify an override with this option. - - validator is a validator, see this file for examples - """ - if validator is None: - validator = self.PathExists - - if SCons.Util.is_List(key) or SCons.Util.is_Tuple(key): - return (key, '%s ( /path/to/%s )' % (help, key[0]), default, - validator, None) - else: - return (key, '%s ( /path/to/%s )' % (help, key), default, - validator, None) - -PathOption = _PathOptionClass() diff --git a/src/engine/SCons/Options/PathOptionTests.py b/src/engine/SCons/Options/PathOptionTests.py deleted file mode 100644 index 22e79ae..0000000 --- a/src/engine/SCons/Options/PathOptionTests.py +++ /dev/null @@ -1,231 +0,0 @@ -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import os.path -import sys -import unittest - -import SCons.Errors -import SCons.Options - -import TestCmd - -class PathOptionTestCase(unittest.TestCase): - def test_PathOption(self): - """Test PathOption creation""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.PathOption('test', - 'test option help', - '/default/path')) - - o = opts.options[0] - assert o.key == 'test', o.key - assert o.help == 'test option help ( /path/to/test )', repr(o.help) - assert o.default == '/default/path', o.default - assert not o.validator is None, o.validator - assert o.converter is None, o.converter - - def test_PathExists(self): - """Test the PathExists validator""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.PathOption('test', - 'test option help', - '/default/path', - SCons.Options.PathOption.PathExists)) - - test = TestCmd.TestCmd(workdir='') - test.write('exists', 'exists\n') - - o = opts.options[0] - - o.validator('X', test.workpath('exists'), {}) - - dne = test.workpath('does_not_exist') - try: - o.validator('X', dne, {}) - except SCons.Errors.UserError, e: - assert str(e) == 'Path for option X does not exist: %s' % dne, e - except: - raise "did not catch expected UserError" - - def test_PathIsDir(self): - """Test the PathIsDir validator""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.PathOption('test', - 'test option help', - '/default/path', - SCons.Options.PathOption.PathIsDir)) - - test = TestCmd.TestCmd(workdir='') - test.subdir('dir') - test.write('file', "file\n") - - o = opts.options[0] - - o.validator('X', test.workpath('dir'), {}) - - f = test.workpath('file') - try: - o.validator('X', f, {}) - except SCons.Errors.UserError, e: - assert str(e) == 'Directory path for option X is a file: %s' % f, e - except: - raise "did not catch expected UserError" - - dne = test.workpath('does_not_exist') - try: - o.validator('X', dne, {}) - except SCons.Errors.UserError, e: - assert str(e) == 'Directory path for option X does not exist: %s' % dne, e - except: - raise "did not catch expected UserError" - - def test_PathIsDirCreate(self): - """Test the PathIsDirCreate validator""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.PathOption('test', - 'test option help', - '/default/path', - SCons.Options.PathOption.PathIsDirCreate)) - - test = TestCmd.TestCmd(workdir='') - test.write('file', "file\n") - - o = opts.options[0] - - d = test.workpath('dir') - o.validator('X', d, {}) - assert os.path.isdir(d) - - f = test.workpath('file') - try: - o.validator('X', f, {}) - except SCons.Errors.UserError, e: - assert str(e) == 'Path for option X is a file, not a directory: %s' % f, e - except: - raise "did not catch expected UserError" - - def test_PathIsFile(self): - """Test the PathIsFile validator""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.PathOption('test', - 'test option help', - '/default/path', - SCons.Options.PathOption.PathIsFile)) - - test = TestCmd.TestCmd(workdir='') - test.subdir('dir') - test.write('file', "file\n") - - o = opts.options[0] - - o.validator('X', test.workpath('file'), {}) - - d = test.workpath('d') - try: - o.validator('X', d, {}) - except SCons.Errors.UserError, e: - assert str(e) == 'File path for option X does not exist: %s' % d, e - except: - raise "did not catch expected UserError" - - dne = test.workpath('does_not_exist') - try: - o.validator('X', dne, {}) - except SCons.Errors.UserError, e: - assert str(e) == 'File path for option X does not exist: %s' % dne, e - except: - raise "did not catch expected UserError" - - def test_PathAccept(self): - """Test the PathAccept validator""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.PathOption('test', - 'test option help', - '/default/path', - SCons.Options.PathOption.PathAccept)) - - test = TestCmd.TestCmd(workdir='') - test.subdir('dir') - test.write('file', "file\n") - - o = opts.options[0] - - o.validator('X', test.workpath('file'), {}) - - d = test.workpath('d') - o.validator('X', d, {}) - - dne = test.workpath('does_not_exist') - o.validator('X', dne, {}) - - def test_validator(self): - """Test the PathOption validator argument""" - opts = SCons.Options.Options() - opts.Add(SCons.Options.PathOption('test', - 'test option help', - '/default/path')) - - test = TestCmd.TestCmd(workdir='') - test.write('exists', 'exists\n') - - o = opts.options[0] - - o.validator('X', test.workpath('exists'), {}) - - dne = test.workpath('does_not_exist') - try: - o.validator('X', dne, {}) - except SCons.Errors.UserError, e: - expect = 'Path for option X does not exist: %s' % dne - assert str(e) == expect, e - else: - raise "did not catch expected UserError" - - def my_validator(key, val, env): - raise Exception, "my_validator() got called for %s, %s!" % (key, val) - - opts = SCons.Options.Options() - opts.Add(SCons.Options.PathOption('test2', - 'more help', - '/default/path/again', - my_validator)) - - o = opts.options[0] - - try: - o.validator('Y', 'value', {}) - except Exception, e: - assert str(e) == 'my_validator() got called for Y, value!', e - else: - raise "did not catch expected exception from my_validator()" - - - - -if __name__ == "__main__": - suite = unittest.makeSuite(PathOptionTestCase, 'test_') - if not unittest.TextTestRunner().run(suite).wasSuccessful(): - sys.exit(1) diff --git a/src/engine/SCons/Options/__init__.py b/src/engine/SCons/Options/__init__.py deleted file mode 100644 index 9389c7b..0000000 --- a/src/engine/SCons/Options/__init__.py +++ /dev/null @@ -1,306 +0,0 @@ -"""engine.SCons.Options - -This file defines the Options class that is used to add user-friendly -customizable variables to an SCons build. -""" - -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import SCons.compat - -import os.path -import string -import sys - -import SCons.Environment -import SCons.Errors -import SCons.Util -import SCons.Warnings - -from BoolOption import BoolOption # okay -from EnumOption import EnumOption # okay -from ListOption import ListOption # naja -from PackageOption import PackageOption # naja -from PathOption import PathOption # okay - - -class Options: - instance=None - - """ - Holds all the options, updates the environment with the variables, - and renders the help text. - """ - def __init__(self, files=[], args={}, is_global=1): - """ - files - [optional] List of option configuration files to load - (backward compatibility) If a single string is passed it is - automatically placed in a file list - """ - self.options = [] - self.args = args - if not SCons.Util.is_List(files): - if files: - files = [ files ] - else: - files = [] - self.files = files - self.unknown = {} - - # create the singleton instance - if is_global: - self=Options.instance - - if not Options.instance: - Options.instance=self - - def _do_add(self, key, help="", default=None, validator=None, converter=None): - class Option: - pass - - option = Option() - - # if we get a list or a tuple, we take the first element as the - # option key and store the remaining in aliases. - if SCons.Util.is_List(key) or SCons.Util.is_Tuple(key): - option.key = key[0] - option.aliases = key[1:] - else: - option.key = key - option.aliases = [ key ] - option.help = help - option.default = default - option.validator = validator - option.converter = converter - - self.options.append(option) - - def keys(self): - """ - Returns the keywords for the options - """ - return map(lambda o: o.key, self.options) - - def Add(self, key, help="", default=None, validator=None, converter=None, **kw): - """ - Add an option. - - key - the name of the variable, or a list or tuple of arguments - help - optional help text for the options - default - optional default value - validator - optional function that is called to validate the option's value - Called with (key, value, environment) - converter - optional function that is called to convert the option's value before - putting it in the environment. - """ - - if SCons.Util.is_List(key) or type(key) == type(()): - apply(self._do_add, key) - return - - if not SCons.Util.is_String(key) or \ - not SCons.Environment.is_valid_construction_var(key): - raise SCons.Errors.UserError, "Illegal Options.Add() key `%s'" % str(key) - - self._do_add(key, help, default, validator, converter) - - def AddOptions(self, *optlist): - """ - Add a list of options. - - Each list element is a tuple/list of arguments to be passed on - to the underlying method for adding options. - - Example: - opt.AddOptions( - ('debug', '', 0), - ('CC', 'The C compiler'), - ('VALIDATE', 'An option for testing validation', 'notset', - validator, None), - ) - """ - for o in optlist: - apply(self._do_add, o) - - - def Update(self, env, args=None): - """ - Update an environment with the option variables. - - env - the environment to update. - """ - - values = {} - - # first set the defaults: - for option in self.options: - if not option.default is None: - values[option.key] = option.default - - # next set the value specified in the options file - for filename in self.files: - if os.path.exists(filename): - dir = os.path.split(os.path.abspath(filename))[0] - if dir: - sys.path.insert(0, dir) - try: - values['__name__'] = filename - execfile(filename, {}, values) - finally: - if dir: - del sys.path[0] - del values['__name__'] - - # set the values specified on the command line - if args is None: - args = self.args - - for arg, value in args.items(): - added = False - for option in self.options: - if arg in option.aliases + [ option.key ]: - values[option.key] = value - added = True - if not added: - self.unknown[arg] = value - - # put the variables in the environment: - # (don't copy over variables that are not declared as options) - for option in self.options: - try: - env[option.key] = values[option.key] - except KeyError: - pass - - # Call the convert functions: - for option in self.options: - if option.converter and values.has_key(option.key): - value = env.subst('${%s}'%option.key) - try: - try: - env[option.key] = option.converter(value) - except TypeError: - env[option.key] = option.converter(value, env) - except ValueError, x: - raise SCons.Errors.UserError, 'Error converting option: %s\n%s'%(option.key, x) - - - # Finally validate the values: - for option in self.options: - if option.validator and values.has_key(option.key): - option.validator(option.key, env.subst('${%s}'%option.key), env) - - def UnknownOptions(self): - """ - Returns any options in the specified arguments lists that - were not known, declared options in this object. - """ - return self.unknown - - def Save(self, filename, env): - """ - Saves all the options in the given file. This file can - then be used to load the options next run. This can be used - to create an option cache file. - - filename - Name of the file to save into - env - the environment get the option values from - """ - - # Create the file and write out the header - try: - fh = open(filename, 'w') - - try: - # Make an assignment in the file for each option - # within the environment that was assigned a value - # other than the default. - for option in self.options: - try: - value = env[option.key] - try: - prepare = value.prepare_to_store - except AttributeError: - try: - eval(repr(value)) - except KeyboardInterrupt: - raise - except: - # Convert stuff that has a repr() that - # cannot be evaluated into a string - value = SCons.Util.to_String(value) - else: - value = prepare() - - defaultVal = env.subst(SCons.Util.to_String(option.default)) - if option.converter: - defaultVal = option.converter(defaultVal) - - if str(env.subst('${%s}' % option.key)) != str(defaultVal): - fh.write('%s = %s\n' % (option.key, repr(value))) - except KeyError: - pass - finally: - fh.close() - - except IOError, x: - raise SCons.Errors.UserError, 'Error writing options to file: %s\n%s' % (filename, x) - - def GenerateHelpText(self, env, sort=None): - """ - Generate the help text for the options. - - env - an environment that is used to get the current values - of the options. - """ - - if sort: - options = self.options[:] - options.sort(lambda x,y,func=sort: func(x.key,y.key)) - else: - options = self.options - - def format(opt, self=self, env=env): - if env.has_key(opt.key): - actual = env.subst('${%s}' % opt.key) - else: - actual = None - return self.FormatOptionHelpText(env, opt.key, opt.help, opt.default, actual, opt.aliases) - lines = filter(None, map(format, options)) - - return string.join(lines, '') - - format = '\n%s: %s\n default: %s\n actual: %s\n' - format_ = '\n%s: %s\n default: %s\n actual: %s\n aliases: %s\n' - - def FormatOptionHelpText(self, env, key, help, default, actual, aliases=[]): - # Don't display the key name itself as an alias. - aliases = filter(lambda a, k=key: a != k, aliases) - if len(aliases)==0: - return self.format % (key, help, default, actual) - else: - return self.format_ % (key, help, default, actual, aliases) - |
