Deprecate the overrides Builder() keyword argument in favor of specifying values...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 8 Feb 2004 14:54:08 +0000 (14:54 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 8 Feb 2004 14:54:08 +0000 (14:54 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@892 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/CHANGES.txt
src/RELEASE.txt
src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py
src/engine/SCons/Executor.py
src/engine/SCons/ExecutorTests.py
src/engine/SCons/Tool/CVS.py
src/engine/SCons/Tool/Subversion.py
test/overrides.py

index c5a1c4a2ad54a6e9fe1a1c9875e49b0839fc1aee..efa59ba79c5ae63089151d913364b54c33d3ef95 100644 (file)
@@ -6170,18 +6170,21 @@ used for normal builds of normal target files,
 which use the environment that was
 used to call the Builder for the target file.)
 
-.IP overrides
-A dictionary of construction variables
-that will be set in the executing
-construction environment when this
-Builder is invoked.
+Any additional keyword arguments supplied
+when a Builder object is created
+(that is, when the Builder() function is called)
+will be set in the executing construction
+environment when the Builder object is called.
 The canonical example here would be
 to set a construction variable to 
 the repository of a source code system.
 
 Any additional keyword arguments supplied
-when a Builder object is called
-will be associated with the target
+when a Builder
+.I object
+is called
+will only be associated with the target
+created by that particular Builder call
 (and any other files built as a
 result of the call).
 
index 2f1540b61f23ddcf5de939b7ab10258c82ce8edb..18181fc5888622b32d37c6c335966e70d51966a6 100644 (file)
@@ -154,6 +154,13 @@ RELEASE 0.95 - XXX
     --debug=count and --debug=objects only print anything when run
     under Python 2.1 or later.
 
+  - Deprecate the "overrides" keyword argument to Builder() creation
+    in favor of using keyword argument values directly (like we do
+    for builder execution and the like).
+
+  - Always use the Builder overrides in substitutions, not just if
+    there isn't a target-specific environment.
+
   From Vincent Risi:
 
   - Add support for the bcc32, ilink32 and tlib Borland tools.
index b52d3adba3f1c96bb2ad89e0b17d175831e1d32c..54a079b4bb972db61befd826dd73e0d881aa0ac1 100644 (file)
@@ -43,6 +43,19 @@ RELEASE 0.95 - XXX
       into the SCons internals and calling either of the SCons.Util
       functions directly.)
 
+    - The "overrides" keyword argument to calls to the Builder() function
+      used to create new Builder objects has been deprecated and will
+      be removed in a future release.  The items in an "overrides"
+      dictionary should now be specified as keyword arguments:
+
+          # Old way, "overrides" is a dictionary:
+          Builder(action = 'cp $TDIR/$TARGET $SDIR/$SOURCE',
+                  overrides = {'TDIR' : dir1, 'SDIR' : dir2})
+
+          # New way, items are specified as keyword arguments:
+          Builder(action = 'cp $TDIR/$TARGET $SDIR/$SOURCE',
+                  TDIR = dir1, SDIR = dir2)
+
   SCons is developed with an extensive regression test suite, and a
   rigorous development methodology for continually improving that suite.
   Because of this, SCons is of sufficient quality that you can use it
index 3010e9808c379f407a6c86a605956c617671b4e5..6714a3d4808e96740d007a795fcfadfe4e613976 100644 (file)
@@ -269,7 +269,7 @@ class BuilderBase:
                         emitter = None,
                         multi = 0,
                         env = None,
-                        overrides = {}):
+                        **overrides):
         if __debug__: logInstanceCreation(self, 'BuilderBase')
         self.action = SCons.Action.Action(action)
         self.multi = multi
@@ -280,6 +280,12 @@ class BuilderBase:
             suffix = CallableSelector(suffix)
         self.suffix = suffix
         self.env = env
+        if overrides.has_key('overrides'):
+            SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning,
+                "The \"overrides\" keyword to Builder() creation has been deprecated;\n" +\
+                "\tspecify the items as keyword arguments to the Builder() call instead.")
+            overrides.update(overrides['overrides'])
+            del overrides['overrides']
         self.overrides = overrides
 
         self.set_src_suffix(src_suffix)
index cf11f6b0dd64ccee1592508e2a3960df07083bfa..b03a99e960a532b76334d55d49cf817f22766489 100644 (file)
@@ -160,6 +160,15 @@ class MyNode(MyNode_without_target_from_source):
 
 class BuilderTestCase(unittest.TestCase):
 
+    def test__init__(self):
+        """Test simple Builder creation
+        """
+        builder = SCons.Builder.Builder(action="foo")
+        assert not builder is None, builder
+        builder = SCons.Builder.Builder(action="foo", OVERRIDE='x')
+        x = builder.overrides['OVERRIDE']
+        assert x == 'x', x
+
     def test__nonzero__(self):
         """Test a builder raising an exception when __nonzero__ is called
         """
index 797bddac1a9c53b6dc86f8ac40f3d6a1fc130e68..2a0882e0f2d98c1d45087123807bd7fb501fee0e 100644 (file)
@@ -64,12 +64,13 @@ class Executor:
                 # So use the environment associated with the Builder
                 # itself.
                 env = self.builder.env
-                overrides = self.builder.overrides
             else:
                 # The normal case:  use the Environment that was
                 # used to specify how these targets will be built.
                 env = self.env
-                overrides = self.overrides
+            overrides = {}
+            overrides.update(self.builder.overrides)
+            overrides.update(self.overrides)
             self.build_env = env.Override(overrides)
             return self.build_env
 
index 6ead30687a7cd37a5766e995bfa893991810dccd..2a79e2db8092f250c0919d0ab8575a72280b09fb 100644 (file)
@@ -75,24 +75,38 @@ class ExecutorTestCase(unittest.TestCase):
 
     def test_get_build_env(self):
         """Test fetching and generating a build environment"""
-        x = SCons.Executor.Executor('b', 'e', 'o', 't', ['s1', 's2'])
+        x = SCons.Executor.Executor(MyBuilder('e', {}),
+                                    'e',
+                                    {},
+                                    't',
+                                    ['s1', 's2'])
         x.build_env = 'eee'
         be = x.get_build_env()
         assert be == 'eee', be
 
-        x = SCons.Executor.Executor('b',
+        x = SCons.Executor.Executor(MyBuilder('e', {}),
                                     MyEnvironment(X='xxx'),
-                                    {'O':'ooo'},
+                                    {'O':'o2'},
                                     't',
                                     ['s1', 's2'])
         be = x.get_build_env()
-        assert be == {'O':'ooo', 'X':'xxx'}, be
+        assert be == {'O':'o2', 'X':'xxx'}, be
 
         env = MyEnvironment(Y='yyy')
-        over = {'O':'ooo'}
-        x = SCons.Executor.Executor(MyBuilder(env, over), None, {}, 't', 's')
+        x = SCons.Executor.Executor(MyBuilder(env, {'O':'ob3'}),
+                                    None,
+                                    {'O':'oo3'},
+                                    't',
+                                    's')
+        be = x.get_build_env()
+        assert be == {'O':'oo3', 'Y':'yyy'}, be
+        x = SCons.Executor.Executor(MyBuilder(env, {'O':'ob3'}),
+                                    None,
+                                    {},
+                                    't',
+                                    's')
         be = x.get_build_env()
-        assert be == {'O':'ooo', 'Y':'yyy'}, be
+        assert be == {'O':'ob3', 'Y':'yyy'}, be
 
     def test_get_action_list(self):
         """Test fetching and generating an action list"""
index b3bd16636e25212d7fcbff1b84ae1d402f0ceeed..6d5b046d239280015db4c074c3ff5c3fb950f339 100644 (file)
@@ -51,8 +51,8 @@ def generate(env):
            env['CVSCOM']   = '$CVS $CVSFLAGS co $CVSCOFLAGS -d ${TARGET.dir} $CVSMODULE${TARGET.posix}'
         return SCons.Builder.Builder(action = '$CVSCOM',
                                      env = env,
-                                     overrides = {'CVSREPOSITORY':repos,
-                                                  'CVSMODULE':module})
+                                     CVSREPOSITORY = repos,
+                                     CVSMODULE = module)
 
     setattr(env, 'CVS', CVSFactory)
 
index 56569f31cf137d89177365863eebb81d86fb49a7..92839bc7608caa6751e99d1d667c1e2ffedb9308 100644 (file)
@@ -48,8 +48,8 @@ def generate(env):
             module = os.path.join(module, '')
         return SCons.Builder.Builder(action = '$SVNCOM',
                                      env = env,
-                                     overrides = {'SVNREPOSITORY':repos,
-                                                  'SVNMODULE':module})
+                                     SVNREPOSITORY = repos,
+                                     SVNMODULE = module)
 
     setattr(env, 'Subversion', SubversionFactory)
 
index f1a22be29536d910a1caf70b3bad9188d363937a..d9b6fdea74dc63dad4e3998e2123d18aa4e8d6d2 100644 (file)
@@ -36,17 +36,29 @@ python = TestSCons.python
 test.write('SConstruct', """
 env = Environment(LIBS=['a'])
 def build(target, source, env):
-    assert env['CC'] == 'mycc'
-    assert env['LIBS'] == ['a','b']
-builder = Builder(action=build)
+    print "env['CC'] =", env['CC']
+    print "env['LIBS'] =", env['LIBS']
+builder = Builder(action=build, CC='buildcc', LIBS='buildlibs')
 env['BUILDERS']['Build'] = builder
 
-Default(env.Build('foo', 'bar', CC='mycc', LIBS = env['LIBS']+['b']))
+foo = env.Build('foo.out', 'foo.in', CC='mycc', LIBS = env['LIBS']+['b'])
+bar = env.Build('bar.out', 'bar.in')
+Default([foo, bar])
+""")
+
+test.write('foo.in', "foo.in\n")
+test.write('bar.in', "bar.in\n")
+
+test.run(arguments = "-Q", stdout = """\
+build("foo.out", "foo.in")
+env['CC'] = mycc
+env['LIBS'] = ['a', 'b']
+build("bar.out", "bar.in")
+env['CC'] = buildcc
+env['LIBS'] = buildlibs
 """)
 
-test.write('bar', "bar\n")
 
-test.run()
 
 test.write('SConstruct', """
 env = Environment()
@@ -75,5 +87,3 @@ assert test.read('hello.not_exe') == 'this is not a program!'
 test.up_to_date(arguments='hello.not_exe')
 
 test.pass_test()
-
-