summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-03-27 18:24:10 (GMT)
committerSteven Knight <knight@baldmt.com>2004-03-27 18:24:10 (GMT)
commitb46dad1a6665597b93ffd6cee6e89100e1d76c5e (patch)
treea37deb9300dec57ff69ecbfe1ab901a8f7dd027c /src/engine/SCons
parent6503d03e9933c9daf1bd3ad4ba4bc37a77587591 (diff)
downloadSCons-b46dad1a6665597b93ffd6cee6e89100e1d76c5e.zip
SCons-b46dad1a6665597b93ffd6cee6e89100e1d76c5e.tar.gz
SCons-b46dad1a6665597b93ffd6cee6e89100e1d76c5e.tar.bz2
Keep *FLAGS variables as CLVar variables after copying an Environment.
Diffstat (limited to 'src/engine/SCons')
-rw-r--r--src/engine/SCons/Environment.py2
-rw-r--r--src/engine/SCons/EnvironmentTests.py59
-rw-r--r--src/engine/SCons/Util.py4
3 files changed, 54 insertions, 11 deletions
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index 1d61ae8..73b563a 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 11fd0d8..8d1c3f3 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 1722f3a..2ede614 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)