Commits

Anonymous committed 90e82f4

http://scons.tigris.org/issues/show_bug.cgi?id=2345

Pass the python executable from the -P option to runtest to TestCmd.py. Create the escaped executable name in TestCmd.py as well. Pass those two values into
derived test modules. Fix cascade problems in test scripts due to incorrect
assumptions about the name of the executable.

Comments (0)

Files changed (11)

     'match_exact',
     'match_re',
     'match_re_dotall',
-    'python_executable',
+    'python',
+    '_python_',
     'TestCmd'
 ]
 
         i = i+1
     return result
 
+if os.name == 'posix':
+    def escape(arg):
+        "escape shell special characters"
+        slash = '\\'
+        special = '"$'
+        arg = arg.replace(slash, slash+slash)
+        for c in special:
+            arg = arg.replace(c, slash+c)
+        if re_space.search(arg):
+            arg = '"' + arg + '"'
+        return arg
+else:
+    # Windows does not allow special characters in file names
+    # anyway, so no need for an escape function, we will just quote
+    # the arg.
+    def escape(arg):
+        if re_space.search(arg):
+            arg = '"' + arg + '"'
+        return arg
+
 if os.name == 'java':
-
-    python_executable = os.path.join(sys.prefix, 'jython')
-
+    python = os.path.join(sys.prefix, 'jython')
 else:
-
-    python_executable = sys.executable
+    python = os.environ.get("python_executable", sys.executable)
+_python_ = escape(python)
 
 if sys.platform == 'win32':
 
             width = self.banner_width
         return s + self.banner_char * (width - len(s))
 
-    if os.name == 'posix':
-
-        def escape(self, arg):
-            "escape shell special characters"
-            slash = '\\'
-            special = '"$'
-
-            arg = arg.replace(slash, slash+slash)
-            for c in special:
-                arg = arg.replace(c, slash+c)
-
-            if re_space.search(arg):
-                arg = '"' + arg + '"'
-            return arg
-
-    else:
-
-        # Windows does not allow special characters in file names
-        # anyway, so no need for an escape function, we will just quote
-        # the arg.
-        def escape(self, arg):
-            if re_space.search(arg):
-                arg = '"' + arg + '"'
-            return arg
+    escape = staticmethod(escape)
 
     def canonicalize(self, path):
         if is_List(path):
 
 The TestCommon module also provides the following variables
 
-    TestCommon.python_executable
+    TestCommon.python
+    TestCommon._python_
     TestCommon.exe_suffix
     TestCommon.obj_suffix
     TestCommon.shobj_prefix

QMTest/TestRuntest.py

 from TestCommon import __all__
 
 __all__.extend([ 'TestRuntest',
-                 'python',
                  'pythonstring',
-                 '_python_',
                ])
 
-python = python_executable
-_python_ = '"' + python_executable + '"'
-
 if re.search('\s', python):
     pythonstring = _python_
 else:
     machine = uname()[4]
     machine = machine_map.get(machine, machine)
 
-python = python_executable
-_python_ = '"' + python_executable + '"'
 _exe = exe_suffix
 _obj = obj_suffix
 _shobj = shobj_suffix

QMTest/TestSCons_time.py

 from TestCommon import *
 from TestCommon import __all__
 
-__all__.extend([ 'TestSCons',
-                 'python',
-                 '_exe',
-                 '_obj',
-                 '_shobj',
-                 'lib_',
-                 '_lib',
-                 'dll_',
-                 '_dll'
+__all__.extend([ 'TestSCons_time',
                ])
 
-python = python_executable
-_python_ = '"' + python_executable + '"'
-
 SConstruct = """\
 import os
 print "SConstruct file directory:", os.getcwd()
         python = os.path.join(sys.prefix, 'jython')
     else:
         python = sys.executable
+os.environ["python_executable"] = python
 
 # time.clock() is the suggested interface for doing benchmarking timings,
 # but time.time() does a better job on Linux systems, so let that be

src/engine/SCons/Util.py

         # Profiling shows that there is an impressive speed-up of 2x
         # when explicitely checking for strings instead of just not
         # sequence when the argument (i.e. obj) is already a string.
-        # But, if obj is a not string than it is twice as fast to
+        # But, if obj is a not string then it is twice as fast to
         # check only for 'not sequence'. The following code therefore
         # assumes that the obj argument is a string must of the time.
         return isinstance(obj, StringTypes) or not isinstance(obj, SequenceTypes)

src/engine/SCons/compat/_scons_subprocess.py

                 startupinfo.wShowWindow = SW_HIDE
                 comspec = os.environ.get("COMSPEC", "cmd.exe")
                 args = comspec + " /c " + args
-                if (GetVersion() >= 0x80000000 or
+                if (GetVersion() >= 0x80000000L or
                         os.path.basename(comspec).lower() == "command.com"):
                     # Win9x, or using command.com on NT. We need to
                     # use the w9xpopen intermediate program. For more

test/Builder/multi/same-overrides.py

 test.write('file4a.in', 'file4a.in\n')
 test.write('file4b.in', 'file4b.in\n')
 
-python_expr = TestSCons.python.replace('\\', '\\\\')
-act = TestSCons.re_escape('"%s" build.py \$foo \$TARGET \$SOURCES' % python_expr)
+python_expr = _python_.replace('\\', '\\\\')
+act = TestSCons.re_escape('%s build.py \$foo \$TARGET \$SOURCES' % python_expr)
 
 expect = ("""
 scons: warning: Two different environments were specified for target file4.out,

test/VariantDir/reflect.py

 # The .+ after mycc\\.py below handles /nologo flags from Visual C/C++.
 expect = test.wrap_stdout("""\
 scons: building associated VariantDir targets: %(targets)s
-"%(re_python)s" mycc\\.py.* %(INC_CNI)s.*
+%(re_python)s mycc\\.py.* %(INC_CNI)s.*
 Compile
-"%(re_python)s" mylink\\.py .+
+%(re_python)s mylink\\.py .+
 Link
 """ % locals())
 
 test.run(arguments = '',
          stdout=test.wrap_stdout("""\
 scons: building associated VariantDir targets: %(targets)s
-"%(re_python)s" mycc\\.py.* %(INC_CNI)s.*
+%(re_python)s mycc\\.py.* %(INC_CNI)s.*
 Compile
-"%(re_python)s" mylink\\.py .+
+%(re_python)s mylink\\.py .+
 Link
 """ % locals()),
          match=TestSCons.match_re,

test/scons-time/run/option/verbose.py

 Verify that the run -v and --verbose options display command output.
 """
 
+import sys
 import re
 
 import TestSCons_time
 
-_python_ = re.escape(TestSCons_time._python_)
+_python_ = re.escape('"' + sys.executable + '"')
 
 
 test = TestSCons_time.TestSCons_time(match = TestSCons_time.match_re,