From 65f9e8291369742b693beb045caa2a7067721a03 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sat, 27 Mar 2004 18:24:10 +0000 Subject: [PATCH] Keep *FLAGS variables as CLVar variables after copying an Environment. git-svn-id: http://scons.tigris.org/svn/scons/trunk@932 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 4 ++ src/RELEASE.txt | 46 +++++++++++----------- src/engine/SCons/Environment.py | 2 +- src/engine/SCons/EnvironmentTests.py | 59 ++++++++++++++++++++++++---- src/engine/SCons/Util.py | 4 +- 5 files changed, 82 insertions(+), 33 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 637f9592..538d0c0d 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -14,6 +14,10 @@ RELEASE 0.96 - XXX - Make the CacheDir() directory if it doesn't already exist. + From Bob Halley: + + - Make the new *FLAGS variable type work with copied Environments. + From Chris Hoeppler: - Initialize the name of a Scanner.Classic scanner correctly. diff --git a/src/RELEASE.txt b/src/RELEASE.txt index 3ccb4cd7..619c988b 100644 --- a/src/RELEASE.txt +++ b/src/RELEASE.txt @@ -28,28 +28,30 @@ RELEASE 0.96 - XXX Please note the following important changes since release 0.95: - The behavior of the env.Append() and env.Prepend() methods has - changed when appending a string value to a UserList. They now - behave like normal Python addition of a string to a UserList. - Given an initialization like: - - env = Environment(VARIABLE = UserList(['foo'])) - - An Append() call like: - - env.Append(VARIABLE = 'bar') - - Will now yield a $VARIABLE value of ['foo', 'b', 'a', 'r']. - This is because Python UserList objects treat added strings as - sequences of letters. - - The old behavior of yielding a $VARIABLE value of ['foo', 'bar'] - now requires that the appended variable be a list (when the original - variable is a UserList object): - - env.Append(VARIABLE = ['bar']) - - Note that the behavior when appending to normal lists has *not* - changed. + changed when appending a string value to a UserList, or vice versa. + They now behave like normal Python addition of a string to + a UserList. Given an initialization and an env.Append() call like: + + env = Environment(VAR1=UserList(['foo']), VAR2='foo') + env.Append(VAR1='bar', VAR2=UserList(['bar']) + + The resulting values of $VAR1 and $VAR2 will now be ['foo', 'b', + 'a', 'r'] and ['f', 'o', 'o', 'bar'], respectively. This is because + Python UserList objects treat strings as sequences of letters when + adding them to the value of the UserList. + + The old behavior of yielding $VAR1 and $VAR2 values of ['foo', + 'bar'] when either variable is a UserList object now requires that + the string variables be enclosed in a list: + + env = Environment(VAR1=UserList(['foo']), VAR2=['foo']) + env.Append(VAR1='bar', VAR2=UserList(['bar'])) + + Note that the SCons behavior when appending to normal lists has + *not* changed, and the behavior of all of the default values that + SCons uses to initialize all construction variables has *not* + changed. This change *only* affects any cases where you explicitly + use UserList objects to initialize or append to a variable. Please note the following important changes since release 0.94: diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 1d61ae81..73b563aa 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -105,7 +105,7 @@ def our_deepcopy(x): for key in x.keys(): copy[key] = our_deepcopy(x[key]) elif SCons.Util.is_List(x): - copy = map(our_deepcopy, x) + copy = x.__class__(map(our_deepcopy, x)) else: copy = x return copy diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 11fd0d8c..8d1c3f36 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -28,6 +28,7 @@ import string import sys import TestCmd import unittest +import UserList from SCons.Environment import * import SCons.Warnings @@ -114,6 +115,16 @@ class Scanner: +class CLVar(UserList.UserList): + def __init__(self, seq): + if type(seq) == type(''): + seq = string.split(seq) + UserList.UserList.__init__(self, seq) + def __coerce__(self, other): + return (self, CLVar(other)) + + + class EnvironmentTestCase(unittest.TestCase): def test___init__(self): @@ -859,12 +870,12 @@ class EnvironmentTestCase(unittest.TestCase): cases = [ 'a1', 'A1', 'a1A1', 'a2', ['A2'], ['a2', 'A2'], - 'a3', UL(['A3']), UL(['a3', 'A3']), + 'a3', UL(['A3']), UL(['a', '3', 'A3']), 'a4', '', 'a4', 'a5', [], ['a5'], - 'a6', UL([]), UL(['a6']), + 'a6', UL([]), UL(['a', '6']), 'a7', [''], ['a7', ''], - 'a8', UL(['']), UL(['a8', '']), + 'a8', UL(['']), UL(['a', '8', '']), ['e1'], 'E1', ['e1', 'E1'], ['e2'], ['E2'], ['e2', 'E2'], @@ -945,6 +956,18 @@ class EnvironmentTestCase(unittest.TestCase): del cases[:3] assert failed == 0, "%d Append() cases failed" % failed + env['UL'] = UL(['foo']) + env.Append(UL = 'bar') + result = env['UL'] + assert isinstance(result, UL), repr(result) + assert result == ['foo', 'b', 'a', 'r'], result + + env['CLVar'] = CLVar(['foo']) + env.Append(CLVar = 'bar') + result = env['CLVar'] + assert isinstance(result, CLVar), repr(result) + assert result == ['foo', 'bar'], result + class C: def __init__(self, name): self.name = name @@ -1091,6 +1114,16 @@ class EnvironmentTestCase(unittest.TestCase): x = env2.get('XYZ') assert x == ['-DABC', 'x -DXYZ y', '-DDEF'], x + # Ensure that special properties of a class don't get + # lost on copying. + env1 = Environment(FLAGS = CLVar('flag1 flag2')) + x = env1.get('FLAGS') + assert x == ['flag1', 'flag2'], x + env2 = env1.Copy() + env2.Append(FLAGS = 'flag3 flag4') + x = env2.get('FLAGS') + assert x == ['flag1', 'flag2', 'flag3', 'flag4'], x + def test_Detect(self): """Test Detect()ing tools""" test = TestCmd.TestCmd(workdir = '') @@ -1281,12 +1314,12 @@ class EnvironmentTestCase(unittest.TestCase): cases = [ 'a1', 'A1', 'A1a1', 'a2', ['A2'], ['A2', 'a2'], - 'a3', UL(['A3']), UL(['A3', 'a3']), + 'a3', UL(['A3']), UL(['A3', 'a', '3']), 'a4', '', 'a4', 'a5', [], ['a5'], - 'a6', UL([]), UL(['a6']), + 'a6', UL([]), UL(['a', '6']), 'a7', [''], ['', 'a7'], - 'a8', UL(['']), UL(['', 'a8']), + 'a8', UL(['']), UL(['', 'a', '8']), ['e1'], 'E1', ['E1', 'e1'], ['e2'], ['E2'], ['E2', 'e2'], @@ -1365,7 +1398,19 @@ class EnvironmentTestCase(unittest.TestCase): (repr(input), repr(prepend), repr(result), repr(expect)) failed = failed + 1 del cases[:3] - assert failed == 0, "%d subst() cases failed" % failed + assert failed == 0, "%d Prepend() cases failed" % failed + + env['UL'] = UL(['foo']) + env.Prepend(UL = 'bar') + result = env['UL'] + assert isinstance(result, UL), repr(result) + assert result == ['b', 'a', 'r', 'foo'], result + + env['CLVar'] = CLVar(['foo']) + env.Prepend(CLVar = 'bar') + result = env['CLVar'] + assert isinstance(result, CLVar), repr(result) + assert result == ['bar', 'foo'], result env3 = Environment(X = {'x1' : 7}) env3.Prepend(X = {'x1' : 8, 'x2' : 9}, Y = {'y1' : 10}) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 1722f3a4..2ede614d 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -1196,9 +1196,7 @@ class CLVar(UserList.UserList): def __init__(self, seq = []): UserList.UserList.__init__(self, Split(seq)) def __coerce__(self, other): - if is_String(other): - other = Split(other) - return (self, other) + return (self, CLVar(other)) def __str__(self): return string.join(self.data) -- 2.26.2