summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2003-02-22 16:17:24 (GMT)
committerSteven Knight <knight@baldmt.com>2003-02-22 16:17:24 (GMT)
commit97af32a2c590938ddb9967776c65caab1ad9a2dd (patch)
tree2659a65c21712cd69214ba365c50927a781df876
parent2a95aa36269ad195a3579382889489cc3b1bac0f (diff)
downloadSCons-97af32a2c590938ddb9967776c65caab1ad9a2dd.zip
SCons-97af32a2c590938ddb9967776c65caab1ad9a2dd.tar.gz
SCons-97af32a2c590938ddb9967776c65caab1ad9a2dd.tar.bz2
Warn when the user tries to set TARGET[S] or SOURCE[S] in an Environment.
-rw-r--r--doc/man/scons.123
-rw-r--r--src/CHANGES.txt3
-rw-r--r--src/engine/SCons/Environment.py8
-rw-r--r--src/engine/SCons/EnvironmentTests.py20
-rw-r--r--src/engine/SCons/Warnings.py6
-rw-r--r--src/engine/SCons/WarningsTests.py19
6 files changed, 72 insertions, 7 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1
index f026b72..f76bc01 100644
--- a/doc/man/scons.1
+++ b/doc/man/scons.1
@@ -2460,6 +2460,16 @@ The prefix used for shared object file names.
.IP SHOBJSUFFIX
The suffix used for shared object file names.
+.IP SOURCE
+A reserved variable name
+that may not be set or used in a construction environment.
+(See "Variable Substitution," below.)
+
+.IP SOURCES
+A reserved variable name
+that may not be set or used in a construction environment.
+(See "Variable Substitution," below.)
+
.IP SPAWN
A command interpreter function that will be called to execute command line
strings. The function must expect 4 arguments:
@@ -2501,6 +2511,16 @@ The command line used to call the tar archiver.
.IP TARFLAGS
General options passed to the tar archiver.
+.IP TARGET
+A reserved variable name
+that may not be set or used in a construction environment.
+(See "Variable Substitution," below.)
+
+.IP TARGETS
+A reserved variable name
+that may not be set or used in a construction environment.
+(See "Variable Substitution," below.)
+
.IP TARSUFFIX
The suffix used for tar file names.
@@ -3676,6 +3696,9 @@ first source if multiple sources are being built.
.IP SOURCES
The file names of the sources of the build command.
+(Note that the above variables are reserved
+and may not be set in a construction environment.)
+
.LP
For example, given the construction variable CC='cc', targets=['foo'], and
sources=['foo.c', 'bar.c']:
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 6470800..9befe24 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -28,6 +28,9 @@ RELEASE 0.12 - XXX
- Make the error message the same as other build errors when there's a
problem unlinking a target file in preparation for it being built.
+ - Make TARGET, TARGETS, SOURCE and SOURCES reserved variable names and
+ warn if the user tries to set them in a construction environment.
+
RELEASE 0.11 - Tue, 11 Feb 2003 05:24:33 -0600
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index 54c91bb..6857109 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -315,7 +315,13 @@ class Environment:
return dlist
def __setitem__(self, key, value):
- if key == 'BUILDERS':
+ if key == 'TARGET' or \
+ key == 'TARGETS' or \
+ key == 'SOURCE' or \
+ key == 'SOURCES':
+ SCons.Warnings.warn(SCons.Warnings.ReservedVariableWarning,
+ "Ignoring attempt to set reserved variable `%s'" % key)
+ elif key == 'BUILDERS':
try:
bd = self._dict[key]
for k in bd.keys():
diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py
index e313939..1163545 100644
--- a/src/engine/SCons/EnvironmentTests.py
+++ b/src/engine/SCons/EnvironmentTests.py
@@ -332,6 +332,26 @@ class EnvironmentTestCase(unittest.TestCase):
for tnode in tgt:
assert tnode.builder == InstallBuilder
+ def test_ReservedVariables(self):
+ """Test generation of warnings when reserved variable names
+ are set in an environment."""
+
+ SCons.Warnings.enableWarningClass(SCons.Warnings.ReservedVariableWarning)
+ old = SCons.Warnings.warningAsException(1)
+
+ try:
+ env4 = Environment()
+ for kw in ['TARGET', 'TARGETS', 'SOURCE', 'SOURCES']:
+ exc_caught = None
+ try:
+ env4[kw] = 'xyzzy'
+ except SCons.Warnings.ReservedVariableWarning:
+ exc_caught = 1
+ assert exc_caught, "Did not catch ReservedVariableWarning for `%s'" % kw
+ assert not env4.has_key(kw), "`%s' variable was incorrectly set" % kw
+ finally:
+ SCons.Warnings.warningAsException(old)
+
def test_Replace(self):
"""Test replacing construction variables in an Environment
diff --git a/src/engine/SCons/Warnings.py b/src/engine/SCons/Warnings.py
index 30f1b00..6d75c06 100644
--- a/src/engine/SCons/Warnings.py
+++ b/src/engine/SCons/Warnings.py
@@ -43,6 +43,9 @@ class DependencyWarning(Warning):
class CorruptSConsignWarning(Warning):
pass
+class ReservedVariableWarning(Warning):
+ pass
+
_warningAsException = 0
# The below is a list of 2-tuples. The first element is a class object.
@@ -62,8 +65,11 @@ def enableWarningClass(clazz):
_enabled.insert(0, (clazz, 1))
def warningAsException(flag=1):
+ """Turn warnings into exceptions. Returns the old value of the flag."""
global _warningAsException
+ old = _warningAsException
_warningAsException = flag
+ return old
def warn(clazz, *args):
global _enabled, _warningAsException, _warningOut
diff --git a/src/engine/SCons/WarningsTests.py b/src/engine/SCons/WarningsTests.py
index e04ffc3..1016fdb 100644
--- a/src/engine/SCons/WarningsTests.py
+++ b/src/engine/SCons/WarningsTests.py
@@ -57,16 +57,23 @@ class WarningsTestCase(unittest.TestCase):
SCons.Warnings._warningAsException = 0
SCons.Warnings.enableWarningClass(SCons.Warnings.Warning)
- SCons.Warnings.warningAsException()
+ old = SCons.Warnings.warningAsException()
+ assert old == 0, old
+ exc_caught = 0
try:
SCons.Warnings.warn(SCons.Warnings.Warning, "Foo")
except:
- pass
- else:
- assert 0
+ exc_caught = 1
+ assert exc_caught == 1
- SCons.Warnings.warningAsException(0)
- SCons.Warnings.warn(SCons.Warnings.Warning, "Foo")
+ old = SCons.Warnings.warningAsException(old)
+ assert old == 1, old
+ exc_caught = 0
+ try:
+ SCons.Warnings.warn(SCons.Warnings.Warning, "Foo")
+ except:
+ exc_caught = 1
+ assert exc_caught == 0
def test_Disable(self):
"""Test disabling/enabling warnings."""