run-tests: on windows, put correct python at front of PATH stable
authorBryan O'Sullivan <bryano@fb.com>
Wed, 12 Dec 2012 14:52:58 -0800
branchstable
changeset 1174 193946338595
parent 1173 d5da1c5cf1f5
child 1175 62cc0851c70f
run-tests: on windows, put correct python at front of PATH The older approach of trying to copy the python executable into the test directory was doomed to fail. There remains one weakness with this approach: if you've run "make local", tests may pick up the wrong extension DLLs from inside the source tree. I don't know why this happens. A reasonable workaround for now is to test either using --local or with a working directory that does not contain built DLLs. [ original upstream message ]
tests/run-tests.py
--- a/tests/run-tests.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/tests/run-tests.py	Wed Dec 12 14:52:58 2012 -0800
@@ -328,7 +328,7 @@
     # Before we go any further, check for pre-requisite tools
     # stuff from coreutils (cat, rm, etc) are not tested
     for p in requiredtools:
-        if os.name == 'nt':
+        if os.name == 'nt' and not p.endswith('.exe'):
             p += '.exe'
         found = findprogram(p)
         if found:
@@ -365,18 +365,24 @@
         exename = 'python'
         if sys.platform == 'win32':
             exename = 'python.exe'
-    vlog('# Making python executable in test path use correct Python')
-    mypython = os.path.join(BINDIR, exename)
-    try:
-        os.symlink(sys.executable, mypython)
-    except AttributeError:
-        # windows fallback
-        shutil.copyfile(sys.executable, mypython)
-        shutil.copymode(sys.executable, mypython)
-    except OSError, err:
-        # child processes may race, which is harmless
-        if err.errno != errno.EEXIST:
-            raise
+    if getattr(os, 'symlink', None):
+        vlog("# Making python executable in test path a symlink to '%s'" % 
+             sys.executable)
+        mypython = os.path.join(BINDIR, exename)
+        try:
+            os.symlink(sys.executable, mypython)
+        except OSError, err:
+            # child processes may race, which is harmless
+            if err.errno != errno.EEXIST:
+                raise
+    else:
+        vlog("# Modifying search path to find %s in '%s'" % (exename, exedir))
+        path = os.environ['PATH'].split(os.pathsep)
+        while exedir in path:
+            path.remove(exedir)
+        os.environ['PATH'] = os.pathsep.join([exedir] + path)
+        if not findprogram(exename):
+            print "WARNING: Cannot find %s in search path" % exename
 
 def installhg(options):
     vlog("# Performing temporary installation of HG")