Don't blow up if the external PATH variable is not set.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 30 Jul 2004 19:07:46 +0000 (19:07 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 30 Jul 2004 19:07:46 +0000 (19:07 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1017 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py

index 32d03c58d53ed177179b4c66618f5cb048eb60b5..083d64017dfc970cb1d03b1979c218c9b115f19d 100644 (file)
@@ -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
index 998a01b532b9254934e6a56c8cdec22346c17af2..261d73c84dea7178609a0328cd5e80ae0a47686b 100644 (file)
@@ -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):
index 1bce1af5c3a11ad71ea4b658e6c68659ce6e1c32..fb9f14c1a5a28c9d7145e0d94574ded046643621 100644 (file)
@@ -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()"""