From a42bf7218937b6c8c3c6efe95d5ee4529ea9bd32 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Sun, 23 May 2004 12:13:44 +0000 Subject: Better handling of syntax errors during variable expansion. (Anthony Roach) --- src/CHANGES.txt | 3 --- src/engine/SCons/Script/__init__.py | 6 +++--- src/engine/SCons/Util.py | 14 ++++++++++---- src/engine/SCons/UtilTests.py | 8 ++++++-- test/errors.py | 15 +++++++++++++-- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 57166df..70556c6 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -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. diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index ab76011..e77297d 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -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) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index d2e1d73..8b7207c 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -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 diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index 5825406..846aaaa 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -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" diff --git a/test/errors.py b/test/errors.py index 4c493f6..7e24fed 100644 --- a/test/errors.py +++ b/test/errors.py @@ -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() -- cgit v0.12