diff options
author | Steven Knight <knight@baldmt.com> | 2004-07-30 19:07:46 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2004-07-30 19:07:46 (GMT) |
commit | 270710e4d281bfa66c0fa70c36457afc0328a23a (patch) | |
tree | d5e6c84204e3b36d2d1c413e00a9853312afb4fb | |
parent | 443b2276843a2ec8e2496876a83577a7d5399cda (diff) | |
download | SCons-270710e4d281bfa66c0fa70c36457afc0328a23a.zip SCons-270710e4d281bfa66c0fa70c36457afc0328a23a.tar.gz SCons-270710e4d281bfa66c0fa70c36457afc0328a23a.tar.bz2 |
Don't blow up if the external PATH variable is not set.
-rw-r--r-- | src/CHANGES.txt | 3 | ||||
-rw-r--r-- | src/engine/SCons/Util.py | 15 | ||||
-rw-r--r-- | src/engine/SCons/UtilTests.py | 97 |
3 files changed, 68 insertions, 47 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 32d03c5..083d640 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -144,6 +144,9 @@ RELEASE 0.96 - XXX arguments when creating Builder objects. Enhance Dir Nodes so that they can be created with user-specified Builder objects. + - Don't blow up with stack trace when the external $PATH environment + variable isn't set. + From Chris Murray: - Add a .win32 attribute to force file names to expand with diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 998a01b..261d73c 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -1055,7 +1055,10 @@ if sys.platform == 'win32': def WhereIs(file, path=None, pathext=None, reject=[]): if path is None: - path = os.environ['PATH'] + try: + path = os.environ['PATH'] + except KeyError: + return None if is_String(path): path = string.split(path, os.pathsep) if pathext is None: @@ -1087,7 +1090,10 @@ elif os.name == 'os2': def WhereIs(file, path=None, pathext=None, reject=[]): if path is None: - path = os.environ['PATH'] + try: + path = os.environ['PATH'] + except KeyError: + return None if is_String(path): path = string.split(path, os.pathsep) if pathext is None: @@ -1114,7 +1120,10 @@ else: def WhereIs(file, path=None, pathext=None, reject=[]): if path is None: - path = os.environ['PATH'] + try: + path = os.environ['PATH'] + except KeyError: + return None if is_String(path): path = string.split(path, os.pathsep) if not is_List(reject): diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index 1bce1af..fb9f14c 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -1040,54 +1040,63 @@ class UtilTestCase(unittest.TestCase): env_path = os.environ['PATH'] - pathdirs_1234 = [ test.workpath('sub1'), - test.workpath('sub2'), - test.workpath('sub3'), - test.workpath('sub4'), - ] + string.split(env_path, os.pathsep) - - pathdirs_1243 = [ test.workpath('sub1'), - test.workpath('sub2'), - test.workpath('sub4'), - test.workpath('sub3'), - ] + string.split(env_path, os.pathsep) - - os.environ['PATH'] = string.join(pathdirs_1234, os.pathsep) - wi = WhereIs('xxx.exe') - assert wi == test.workpath(sub3_xxx_exe), wi - wi = WhereIs('xxx.exe', pathdirs_1243) - assert wi == test.workpath(sub4_xxx_exe), wi - wi = WhereIs('xxx.exe', string.join(pathdirs_1243, os.pathsep)) - assert wi == test.workpath(sub4_xxx_exe), wi - - wi = WhereIs('xxx.exe',reject = sub3_xxx_exe) - assert wi == test.workpath(sub4_xxx_exe), wi - wi = WhereIs('xxx.exe', pathdirs_1243, reject = sub3_xxx_exe) - assert wi == test.workpath(sub4_xxx_exe), wi - - os.environ['PATH'] = string.join(pathdirs_1243, os.pathsep) - wi = WhereIs('xxx.exe') - assert wi == test.workpath(sub4_xxx_exe), wi - wi = WhereIs('xxx.exe', pathdirs_1234) - assert wi == test.workpath(sub3_xxx_exe), wi - wi = WhereIs('xxx.exe', string.join(pathdirs_1234, os.pathsep)) - assert wi == test.workpath(sub3_xxx_exe), wi - - if sys.platform == 'win32': - wi = WhereIs('xxx', pathext = '') - assert wi is None, wi + try: + pathdirs_1234 = [ test.workpath('sub1'), + test.workpath('sub2'), + test.workpath('sub3'), + test.workpath('sub4'), + ] + string.split(env_path, os.pathsep) + + pathdirs_1243 = [ test.workpath('sub1'), + test.workpath('sub2'), + test.workpath('sub4'), + test.workpath('sub3'), + ] + string.split(env_path, os.pathsep) + + os.environ['PATH'] = string.join(pathdirs_1234, os.pathsep) + wi = WhereIs('xxx.exe') + assert wi == test.workpath(sub3_xxx_exe), wi + wi = WhereIs('xxx.exe', pathdirs_1243) + assert wi == test.workpath(sub4_xxx_exe), wi + wi = WhereIs('xxx.exe', string.join(pathdirs_1243, os.pathsep)) + assert wi == test.workpath(sub4_xxx_exe), wi + + wi = WhereIs('xxx.exe',reject = sub3_xxx_exe) + assert wi == test.workpath(sub4_xxx_exe), wi + wi = WhereIs('xxx.exe', pathdirs_1243, reject = sub3_xxx_exe) + assert wi == test.workpath(sub4_xxx_exe), wi - wi = WhereIs('xxx', pathext = '.exe') + os.environ['PATH'] = string.join(pathdirs_1243, os.pathsep) + wi = WhereIs('xxx.exe') assert wi == test.workpath(sub4_xxx_exe), wi + wi = WhereIs('xxx.exe', pathdirs_1234) + assert wi == test.workpath(sub3_xxx_exe), wi + wi = WhereIs('xxx.exe', string.join(pathdirs_1234, os.pathsep)) + assert wi == test.workpath(sub3_xxx_exe), wi + + if sys.platform == 'win32': + wi = WhereIs('xxx', pathext = '') + assert wi is None, wi + + wi = WhereIs('xxx', pathext = '.exe') + assert wi == test.workpath(sub4_xxx_exe), wi - wi = WhereIs('xxx', path = pathdirs_1234, pathext = '.BAT;.EXE') - assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi + wi = WhereIs('xxx', path = pathdirs_1234, pathext = '.BAT;.EXE') + assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi + + # Test that we return a normalized path even when + # the path contains forward slashes. + forward_slash = test.workpath('') + '/sub3' + wi = WhereIs('xxx', path = forward_slash, pathext = '.EXE') + assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi + + del os.environ['PATH'] + wi = WhereIs('xxx.exe') + assert wi is None, wi - # Test that we return a normalized path even when - # the path contains forward slashes. - forward_slash = test.workpath('') + '/sub3' - wi = WhereIs('xxx', path = forward_slash, pathext = '.EXE') - assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi + finally: + os.environ['PATH'] = env_path + def test_is_valid_construction_var(self): """Testing is_valid_construction_var()""" |