Better handling of syntax errors during variable expansion. (Anthony Roach)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 23 May 2004 12:13:44 +0000 (12:13 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 23 May 2004 12:13:44 +0000 (12:13 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@983 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Script/__init__.py
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py
test/errors.py

index 57166dff22ee93349b7f4116d804d4fa1d94fdde..70556c6ff979fa218fc1ae4f7a7c2226d133f5d9 100644 (file)
@@ -142,9 +142,6 @@ RELEASE 0.96 - XXX
   - Try to find the ICL license file path name in the external environment
     and the registry before resorting to the hard-coded path name.
 
-  - Add support for fetching command-line keyword=value arguments in
-    order from an ARGLIST list.
-
   From Simon Perkins:
 
   - Fix a bug introduced in building shared libraries under MinGW.
index ab760112418507c958715c5c4c1d7c9ceb3cc9f2..e77297d30b04a52ec5d3feefd6e3d7d52b21b9f2 100644 (file)
@@ -181,9 +181,9 @@ class BuildTask(SCons.Taskmaster.Task):
                 s = s + '  Stop.'
             sys.stderr.write("scons: *** %s\n" % s)
 
-        if tb:
-            sys.stderr.write("scons: internal stack trace:\n")
-            traceback.print_tb(tb, file=sys.stderr)
+            if tb:
+                sys.stderr.write("scons: internal stack trace:\n")
+                traceback.print_tb(tb, file=sys.stderr)
 
         self.do_failed(status)
 
index d2e1d73c0979e409908aa9136fb98e15c0cd54df..8b7207ce4020533e8692c793cec33331d9b20a91 100644 (file)
@@ -552,8 +552,11 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, dict=No
                             s = eval(key, self.gvars, lvars)
                         except (IndexError, NameError, TypeError):
                             return ''
-                        except (SyntaxError):
-                            raise SCons.Errors.UserError, "Syntax error trying to evaluate `%s'" % s
+                        except SyntaxError,e:
+                            if self.target:
+                                raise SCons.Errors.BuildError, (self.target[0], "Syntax error `%s' trying to evaluate `%s'" % (e,s))
+                            else:
+                                raise SCons.Errors.UserError, "Syntax error `%s' trying to evaluate `%s'" % (e,s)
                         else:
                             # Before re-expanding the result, handle
                             # recursive expansion by copying the local
@@ -695,8 +698,11 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, di
                             s = eval(key, self.gvars, lvars)
                         except (IndexError, NameError, TypeError):
                             return
-                        except (SyntaxError):
-                            raise SCons.Errors.UserError, "Syntax error trying to evaluate `%s'" % s
+                        except SyntaxError,e:
+                            if self.target:
+                                raise SCons.Errors.BuildError, (self.target[0], "Syntax error `%s' trying to evaluate `%s'" % (e,s))
+                            else:
+                                raise SCons.Errors.UserError, "Syntax error `%s' trying to evaluate `%s'" % (e,s)
                         else:
                             # Before re-expanding the result, handle
                             # recursive expansion by copying the local
index 5825406ed49d45a3aced5b7ce77a2b7dc9bca8e8..846aaaa2bd41bef1e393cd9f9eb43c6864b028a0 100644 (file)
@@ -425,7 +425,9 @@ class UtilTestCase(unittest.TestCase):
         try:
             scons_subst('$foo.bar.3.0', env)
         except SCons.Errors.UserError, e:
-            assert str(e) == "Syntax error trying to evaluate `$foo.bar.3.0'", e
+            expect1 = "Syntax error `invalid syntax' trying to evaluate `$foo.bar.3.0'"
+            expect2 = "Syntax error `invalid syntax (line 1)' trying to evaluate `$foo.bar.3.0'"
+            assert str(e) in [expect1, expect2], e
         else:
             raise AssertionError, "did not catch expected UserError"
 
@@ -787,7 +789,9 @@ class UtilTestCase(unittest.TestCase):
         try:
             scons_subst_list('$foo.bar.3.0', env)
         except SCons.Errors.UserError, e:
-            assert str(e) == "Syntax error trying to evaluate `$foo.bar.3.0'", e
+            expect1 = "Syntax error `invalid syntax' trying to evaluate `$foo.bar.3.0'"
+            expect2 = "Syntax error `invalid syntax (line 1)' trying to evaluate `$foo.bar.3.0'"
+            assert str(e) in [expect1, expect2], e
         else:
             raise AssertionError, "did not catch expected SyntaxError"
 
index 4c493f6952a3f70a668f72095f53d73cefb34b08..7e24fed2151ddd872fecc96b0ecf12bff9a47628 100644 (file)
@@ -189,7 +189,7 @@ env.subst('$foo.bar.3.0')
 """)
 
 test.run(status=2, stderr="""
-scons: \*\*\* Syntax error trying to evaluate `\$foo\.bar\.3\.0'
+scons: \*\*\* Syntax error `invalid syntax( \(line 1\))?' trying to evaluate `\$foo\.bar\.3\.0'
 File "SConstruct", line 2, in \?
 """)
 
@@ -199,10 +199,21 @@ env.subst_list('$foo.3.0.x')
 """)
 
 test.run(status=2, stderr="""
-scons: \*\*\* Syntax error trying to evaluate `\$foo\.3\.0\.x'
+scons: \*\*\* Syntax error `invalid syntax( \(line 1\))?' trying to evaluate `\$foo\.3\.0\.x'
 File "SConstruct", line 2, in \?
 """)
 
+#Test syntax errors when trying to expand construction variables at build time:
+test.write('SConstruct', """\
+env = Environment()
+env.Command('foo.bar', [], '$foo.bar.3.0')
+""")
+
+test.run(status=2, stderr=r"""scons: \*\*\* \[foo\.bar\] Syntax error `invalid syntax( \(line 1\))?' trying to evaluate `\$foo\.bar\.3\.0'
+""")
+
+
+
 
 
 test.pass_test()