Modify the SWIG tests so that OS X is treated like a UNIX platform (which it
authorGregNoel <GregNoel@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 18 Apr 2009 16:56:22 +0000 (16:56 +0000)
committerGregNoel <GregNoel@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 18 Apr 2009 16:56:22 +0000 (16:56 +0000)
really is).  OS X now not only runs all the SWIG tests (it used to skip many
of them because it could not find the appropriate files), it now passes all
the tests.

git-svn-id: http://scons.tigris.org/svn/scons/trunk@4109 fdb21ef1-2011-0410-befe-b5e4ea1792b1

13 files changed:
QMTest/TestCmd.py
QMTest/TestSCons.py
test/SWIG/SWIG.py
test/SWIG/SWIGOUTDIR-python.py
test/SWIG/SWIGPATH.py
test/SWIG/build-dir.py
test/SWIG/implicit-dependencies.py
test/SWIG/live.py
test/SWIG/module-parens.py
test/SWIG/module-quoted.py
test/SWIG/noproxy.py
test/SWIG/remove-modules.py
test/SWIG/subdir.py

index a693f6a0570f761c8607e46675fac944e1264217..cff50c78cecbdac704ad4f634bc9b5151d862e37 100644 (file)
@@ -456,11 +456,8 @@ def diff_re(a, b, fromfile='', tofile='',
     return result
 
 if os.name == 'java':
-
     python_executable = os.path.join(sys.prefix, 'jython')
-
 else:
-
     python_executable = sys.executable
 
 if sys.platform == 'win32':
index 729243d5e682842b73b6ebcb981d8b4bff478eae..26faee5179a513df663631f8ad4aac2f5cf0d1a5 100644 (file)
@@ -860,98 +860,28 @@ SConscript( sconscript )
         # see also sys.prefix documentation
         return python_minor_version_string()
 
-    def get_platform_python(self):
+    def get_platform_python_info(self):
         """
         Returns a path to a Python executable suitable for testing on
-        this platform.
-
-        Mac OS X has no static libpython for SWIG to link against,
-        so we have to link against Apple's framwork version.  However,
-        testing must use the executable version that corresponds to the
-        framework we link against, or else we get interpreter errors.
-        """
-        if sys.platform[:6] == 'darwin':
-            return sys.prefix + '/bin/python'
-        else:
-            global python
-            return python
-
-    def get_quoted_platform_python(self):
-        """
-        Returns a quoted path to a Python executable suitable for testing on
-        this platform.
-
-        Mac OS X has no static libpython for SWIG to link against,
-        so we have to link against Apple's framwork version.  However,
-        testing must use the executable version that corresponds to the
-        framework we link against, or else we get interpreter errors.
-        """
-        if sys.platform[:6] == 'darwin':
-            return '"' + self.get_platform_python() + '"'
-        else:
-            global _python_
-            return _python_
-
-#    def get_platform_sys_prefix(self):
-#        """
-#        Returns a "sys.prefix" value suitable for linking on this platform.
-#
-#        Mac OS X has a built-in Python but no static libpython,
-#        so we must link to it using Apple's 'framework' scheme.
-#        """
-#        if sys.platform[:6] == 'darwin':
-#            fmt = '/System/Library/Frameworks/Python.framework/Versions/%s/'
-#            return fmt % self.get_python_version()
-#        else:
-#            return sys.prefix
-
-    def get_python_frameworks_flags(self):
-        """
-        Returns a FRAMEWORKS value for linking with Python.
-
-        Mac OS X has a built-in Python but no static libpython,
-        so we must link to it using Apple's 'framework' scheme.
-        """
-        if sys.platform[:6] == 'darwin':
-            return 'Python'
-        else:
-            return ''
-
-    def get_python_inc(self):
+        this platform and its associated include path, library path,
+        and library name.
         """
-        Returns a path to the Python include directory.
+        python = self.where_is('python')
+        if not python:
+            self.skip_test('Can not find installed "python", skipping test.\n')
 
-        Mac OS X has a built-in Python but no static libpython,
-        so we must link to it using Apple's 'framework' scheme.
-        """
-        if sys.platform[:6] == 'darwin':
-            return sys.prefix + '/Headers'
-        try:
-            import distutils.sysconfig
-        except ImportError:
-            return os.path.join(sys.prefix, 'include',
-                                'python' + self.get_python_version())
-        else:
-            return distutils.sysconfig.get_python_inc()
+        self.run(program = python, stdin = """\
+import os, sys
+try:
+       py_ver = 'python%d.%d' % sys.version_info[:2]
+except AttributeError:
+       py_ver = 'python' + sys.version[:3]
+print os.path.join(sys.prefix, 'include', py_ver)
+print os.path.join(sys.prefix, 'lib', py_ver, 'config')
+print py_ver
+""")
 
-    def get_python_library_path(self):
-        """
-        Returns the full path of the Python static library (libpython*.a)
-        """
-        if sys.platform[:6] == 'darwin':
-            # Use the framework version (or try to) since that matches
-            # the executable and headers we return elsewhere.
-            python_lib = os.path.join(sys.prefix, 'Python')
-            if os.path.exists(python_lib):
-                return python_lib
-        python_version = self.get_python_version()
-        python_lib = os.path.join(sys.prefix, 'lib',
-                                  'python%s' % python_version, 'config',
-                                  'libpython%s.a' % python_version)
-        if os.path.exists(python_lib):
-            return python_lib
-        # We can't find it, so maybe it's in the standard path
-        return ''
+        return [python] + string.split(string.strip(self.stdout()), '\n')
 
     def wait_for(self, fname, timeout=10.0, popen=None):
         """
index d76ef6487e8b176e20b1270a1c9acbe9cdf327f7..3ddc6861283e92f1573df1d68f823048aa909b10 100644 (file)
@@ -35,8 +35,9 @@ _obj   = TestSCons._obj
 
 test = TestSCons.TestSCons()
 
-_python_ = test.get_quoted_platform_python()
-
+python = test.where_is('python')
+if not python:
+    test,skip_test('Can not find installed "python", skipping test.\n')
 
 
 test.write('myswig.py', r"""
@@ -55,7 +56,8 @@ sys.exit(0)
 """)
 
 test.write('SConstruct', """
-env = Environment(tools=['default', 'swig'], SWIG = r'%(_python_)s myswig.py')
+env = Environment(tools=['default', 'swig'],
+                  SWIG = [r'%(python)s', 'myswig.py'])
 env.Program(target = 'test1', source = 'test1.i')
 env.CFile(target = 'test2', source = 'test2.i')
 env.Clone(SWIGFLAGS = '-c++').Program(target = 'test3', source = 'test3.i')
index 3f6667ec18a1f70badc9fb82818ac068b9b3d324..763e9c4eca409ab91eeef9340764eab18634ea8c 100644 (file)
@@ -34,27 +34,23 @@ import os
 
 test = TestSCons.TestSCons()
 
-test = TestSCons.TestSCons()
-
 swig = test.where_is('swig')
-
 if not swig:
     test.skip_test('Can not find installed "swig", skipping test.\n')
 
-python_include_dir = test.get_python_inc()
-
-python_frameworks_flags = test.get_python_frameworks_flags()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
+python, python_include, python_libpath, python_lib = \
+             test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
 if not os.path.exists(Python_h):
     test.skip_test('Can not find %s, skipping test.\n' % Python_h)
 
 test.write(['SConstruct'], """\
 env = Environment(SWIGFLAGS = '-python -c++',
-                  CPPPATH=r"%(python_include_dir)s",
-                  SWIG=r'%(swig)s',
+                  CPPPATH=[r"%(python_include)s"],
+                  SWIG=[r'%(swig)s'],
                   SWIGOUTDIR='python/build dir',
-                  FRAMEWORKS='%(python_frameworks_flags)s',
+                  LIBPATH=[r'%(python_libpath)s'],
+                  LIBS='%(python_lib)s',
                  )
 
 import sys
index 4832814c732f88be18196716955351683a0cbb39..30426da10bc9e67c7e715eb455d0a2a5b20c4324 100644 (file)
@@ -33,12 +33,12 @@ import TestSCons
 test = TestSCons.TestSCons()
 
 swig = test.where_is('swig')
-
 if not swig:
     test.skip_test('Can not find installed "swig", skipping test.\n')
 
-_python_ = test.get_quoted_platform_python()
-
+python = test.where_is('python')
+if not python:
+    test,skip_test('Can not find installed "python", skipping test.\n')
 
 
 test.subdir('inc1', 'inc2')
@@ -57,7 +57,7 @@ test.write('SConstruct', """
 foo = Environment(SWIGFLAGS='-python',
                   SWIGPATH=['inc1', 'inc2'])
 swig = foo.Dictionary('SWIG')
-bar = foo.Clone(SWIG = r'%(_python_)s wrapper.py ' + swig)
+bar = foo.Clone(SWIG = [r'%(python)s', 'wrapper.py', swig])
 foo.CFile(target = 'dependent', source = ['dependent.i'])
 """ % locals())
 
index 5fa3cebe4ce1cfe5a4b72f789597a4657550fe90..d5b52360432167753c9a1e22de40fe0895b472a5 100644 (file)
@@ -38,7 +38,6 @@ import TestSCons
 test = TestSCons.TestSCons()
 
 swig = test.where_is('swig')
-
 if not swig:
     test.skip_test('Can not find installed "swig", skipping test.\n')
 
@@ -51,27 +50,26 @@ else:
 
 test.subdir(['source'])
 
-python_include_dir = test.get_python_inc()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
-
+python, python_include, python_libpath, python_lib = \
+             test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
 if not os.path.exists(Python_h):
     test.skip_test('Can not find %s, skipping test.\n' % Python_h)
 
-python_frameworks_flags = test.get_python_frameworks_flags()
-
 test.write(['SConstruct'], """\
 #
 # Create the build environment.
 #
-env = Environment(CPPPATH = [".", r'%(python_include_dir)s'],
+env = Environment(CPPPATH = [".", r'%(python_include)s'],
                   CPPDEFINES = "NDEBUG",
-                  SWIG =r'%(swig)s',
+                  SWIG = [r'%(swig)s'],
                   SWIGFLAGS = ["-python", "-c++"],
                   SWIGCXXFILESUFFIX = "_wrap.cpp",
                   LDMODULEPREFIX='_',
                   LDMODULESUFFIX='%(_dll)s',
-                  FRAMEWORKS='%(python_frameworks_flags)s')
+                  LIBPATH=[r'%(python_libpath)s'],
+                  LIBS='%(python_lib)s',
+                  )
 
 import sys
 if sys.version[0] == '1':
index 49f9cc75ebdcbf94cdf617dd04e8cfe0405705b9..6d40216251075c7a9b1dd40a6ab9facacdce6af8 100644 (file)
@@ -33,12 +33,12 @@ import TestSCons
 test = TestSCons.TestSCons()
 
 swig = test.where_is('swig')
-
 if not swig:
     test.skip_test('Can not find installed "swig", skipping test.\n')
 
-_python_ = test.get_quoted_platform_python()
-
+python = test.where_is('python')
+if not python:
+    test.skip_test('Can not find installed "python", skipping test.\n')
 
 
 test.write("dependency.i", """\
@@ -54,7 +54,7 @@ test.write("dependent.i", """\
 test.write('SConstruct', """
 foo = Environment(SWIGFLAGS='-python')
 swig = foo.Dictionary('SWIG')
-bar = foo.Clone(SWIG = r'%(_python_)s wrapper.py ' + swig)
+bar = foo.Clone(SWIG = [r'%(python)s', r'wrapper.py', swig])
 foo.CFile(target = 'dependent', source = ['dependent.i'])
 """ % locals())
 
index 0caa9b5d995005aa5b5afd884feff8847a81a55b..0a4c90592e5e4e1f8daea058e76b8364d0e30c3b 100644 (file)
@@ -47,31 +47,15 @@ swig = test.where_is('swig')
 if not swig:
     test.skip_test('Can not find installed "swig", skipping test.\n')
 
-
-python = test.where_is('python')
-
-# handle testing on other platforms:
-ldmodule_prefix = '_'
-
-test.run(program = python, stdin = """\
-import os, sys
-try:
-       py_ver = 'python%d.%d' % sys.version_info[:2]
-except AttributeError:
-       py_ver = 'python' + sys.version[:3]
-print os.path.join(sys.prefix, 'include', py_ver)
-print os.path.join(sys.prefix, 'lib', py_ver, 'config')
-print py_ver
-""")
-
-#TODO(1.5) config_info = test.stdout().strip().split('\n')
-config_info = string.split(string.strip(test.stdout()), '\n')
-python_include,python_libpath,python_lib = config_info
-
+python, python_include, python_libpath, python_lib = \
+             test.get_platform_python_info()
 Python_h = os.path.join(python_include, 'Python.h')
 if not os.path.exists(Python_h):
     test.skip_test('Can not find %s, skipping test.\n' % Python_h)
 
+# handle testing on other platforms:
+ldmodule_prefix = '_'
+
 test.write("wrapper.py",
 """import os
 import string
@@ -82,11 +66,11 @@ os.system(string.join(sys.argv[1:], " "))
 
 test.write('SConstruct', """\
 foo = Environment(SWIGFLAGS='-python',
-                  CPPPATH=r'%(python_include)s',
+                  CPPPATH=[r'%(python_include)s'],
                   LDMODULEPREFIX='%(ldmodule_prefix)s',
                   LDMODULESUFFIX='%(_dll)s',
-                  SWIG=r'%(swig)s',
-                  LIBPATH=r'%(python_libpath)s',
+                  SWIG=[r'%(swig)s'],
+                  LIBPATH=[r'%(python_libpath)s'],
                   LIBS='%(python_lib)s',
                   )
 
@@ -96,7 +80,7 @@ if sys.version[0] == '1':
     foo.Append(SWIGFLAGS = ' -classic')
 
 swig = foo.Dictionary('SWIG')
-bar = foo.Clone(SWIG = r'"%(python)s" wrapper.py ' + swig)
+bar = foo.Clone(SWIG = [r'%(python)s', 'wrapper.py', swig])
 foo.LoadableModule(target = 'foo', source = ['foo.c', 'foo.i'])
 bar.LoadableModule(target = 'bar', source = ['bar.c', 'bar.i'])
 """ % locals())
index f80e10c43db9ae11a0ccbc7fdd523eac85a883d2..78862180a1395291f658a04ce947c9acb0cfb5d8 100644 (file)
@@ -35,24 +35,22 @@ import TestSCons
 test = TestSCons.TestSCons()
 
 swig = test.where_is('swig')
-
 if not swig:
     test.skip_test('Can not find installed "swig", skipping test.\n')
 
-python_include_dir = test.get_python_inc()
-
-python_frameworks_flags = test.get_python_frameworks_flags()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
+python, python_include, python_libpath, python_lib = \
+             test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
 if not os.path.exists(Python_h):
     test.skip_test('Can not find %s, skipping test.\n' % Python_h)
 
 test.write(['SConstruct'], """\
 env = Environment(SWIGFLAGS = '-python -c++',
-                  CPPPATH=r"%(python_include_dir)s",
-                  SWIG=r'%(swig)s',
-                 FRAMEWORKS='%(python_frameworks_flags)s',
-                 )
+                  CPPPATH=[r'%(python_include)s'],
+                  SWIG=[r'%(swig)s'],
+                  LIBPATH=[r'%(python_libpath)s'],
+                  LIBS='%(python_lib)s',
+                  )
 
 import sys
 if sys.version[0] == '1':
index 2001582400b3c55b5736b4cefdf67ea9479bc412..89402ebf55acdc303ab70e3cea05f94a89ec59af 100644 (file)
@@ -35,23 +35,21 @@ import TestSCons
 test = TestSCons.TestSCons()
 
 swig = test.where_is('swig')
-
 if not swig:
     test.skip_test('Can not find installed "swig", skipping test.\n')
 
-python_include_dir = test.get_python_inc()
-
-python_frameworks_flags = test.get_python_frameworks_flags()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
+python, python_include, python_libpath, python_lib = \
+             test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
 if not os.path.exists(Python_h):
     test.skip_test('Can not find %s, skipping test.\n' % Python_h)
 
 test.write(['SConstruct'], """\
 env = Environment(SWIGFLAGS = '-python -c++',
-                  CPPPATH=r"%(python_include_dir)s",
-                  SWIG=r'%(swig)s',
-                 FRAMEWORKS='%(python_frameworks_flags)s',
+                  CPPPATH=[r'%(python_include)s'],
+                  SWIG=[r'%(swig)s'],
+                  LIBPATH=[r'%(python_libpath)s'],
+                  LIBS='%(python_lib)s',
                  )
 
 import sys
index 0d109b85f9e7a8072ea6899e1a0e23ad33423e41..1aaeb08c7b00cbd70bac3af42d00a6c6bc158f17 100644 (file)
@@ -29,6 +29,7 @@ Verify that SCons realizes the -noproxy option means no .py file will
 be created.
 """
 
+import os
 import sys
 
 import TestSCons
@@ -43,19 +44,18 @@ else:
 test = TestSCons.TestSCons()
 
 swig = test.where_is('swig')
-
 if not swig:
     test.skip_test('Can not find installed "swig", skipping test.\n')
 
-_python_ = test.get_quoted_platform_python()
+python, python_include, python_libpath, python_lib = \
+             test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
+if not os.path.exists(Python_h):
+    test.skip_test('Can not find %s, skipping test.\n' % Python_h)
 
 # handle testing on other platforms:
 ldmodule_prefix = '_'
 
-python_include_dir = test.get_python_inc()
-
-python_frameworks_flags = test.get_python_frameworks_flags()
-
 test.write("dependency.i", """\
 %module dependency
 """)
@@ -68,14 +68,16 @@ test.write("dependent.i", """\
 
 test.write('SConstruct', """
 foo = Environment(SWIGFLAGS=['-python', '-noproxy'],
-                  CPPPATH='%(python_include_dir)s',
+                  CPPPATH=[r'%(python_include)s'],
                   LDMODULEPREFIX='%(ldmodule_prefix)s',
                   LDMODULESUFFIX='%(_dll)s',
-                  FRAMEWORKS='%(python_frameworks_flags)s',
+                  SWIG=[r'%(swig)s'],
+                  LIBPATH=[r'%(python_libpath)s'],
+                  LIBS='%(python_lib)s',
                   )
 
 swig = foo.Dictionary('SWIG')
-bar = foo.Clone(SWIG = r'%(_python_)s wrapper.py ' + swig)
+bar = foo.Clone(SWIG = [r'%(python)s', 'wrapper.py', swig])
 foo.CFile(target = 'dependent', source = ['dependent.i'])
 """ % locals())
 
index e0e91da82ec1b1b4739585c73d8d84137e325d40..8ed24effaf46774bff7044e9557c8c74df1459dc 100644 (file)
@@ -39,29 +39,23 @@ import TestSCons
 if sys.platform == 'win32':
     _dll = '.dll'
 else:
-    _dll   = '.so' 
+    _dll   = '.so'
 
 test = TestSCons.TestSCons()
 
 swig = test.where_is('swig')
-
 if not swig:
     test.skip_test('Can not find installed "swig", skipping test.\n')
 
-
+python, python_include, python_libpath, python_lib = \
+             test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
+if not os.path.exists(Python_h):
+    test.skip_test('Can not find %s, skipping test.\n' % Python_h)
 
 # handle testing on other platforms:
 ldmodule_prefix = '_'
 
-python_include_dir = test.get_python_inc()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
-
-if not os.path.exists(Python_h):
-    test.skip_test('Can not find %s, skipping test.\n' % Python_h)
-
-python_frameworks_flags = test.get_python_frameworks_flags()
-    
 
 test.write("module.i", """\
 %module modulename
@@ -69,11 +63,12 @@ test.write("module.i", """\
 
 test.write('SConstruct', """
 foo = Environment(SWIGFLAGS='-python',
-                  CPPPATH='%(python_include_dir)s',
+                  CPPPATH=['%(python_include)s'],
                   LDMODULEPREFIX='%(ldmodule_prefix)s',
                   LDMODULESUFFIX='%(_dll)s',
-                  FRAMEWORKS='%(python_frameworks_flags)s',
-                  SWIG=r'%(swig)s',
+                  SWIG=[r'%(swig)s'],
+                  LIBPATH=[r'%(python_libpath)s'],
+                  LIBS='%(python_lib)s',
                   )
 
 import sys
index 6a746f36d3374e9992f9b68f646dfec6596d4ddf..d4798f66dd5b6480b32f0b7c145f3895f57673b8 100644 (file)
@@ -46,32 +46,26 @@ test = TestSCons.TestSCons()
 test.subdir('sub')
 
 swig = test.where_is('swig')
-
 if not swig:
     test.skip_test('Can not find installed "swig", skipping test.\n')
 
-python = test.get_platform_python()
-_python_ = test.get_quoted_platform_python()
-
-# handle testing on other platforms:
-ldmodule_prefix = '_'
-
-python_include_dir = test.get_python_inc()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
-
+python, python_include, python_libpath, python_lib = \
+             test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
 if not os.path.exists(Python_h):
     test.skip_test('Can not find %s, skipping test.\n' % Python_h)
 
-python_frameworks_flags = test.get_python_frameworks_flags()
+# handle testing on other platforms:
+ldmodule_prefix = '_'
 
 test.write('SConstruct', """
 env = Environment(SWIGFLAGS='-python',
-                  CPPPATH='%(python_include_dir)s/',
+                  CPPPATH=['%(python_include)s/'],
                   LDMODULEPREFIX='%(ldmodule_prefix)s',
                   LDMODULESUFFIX='%(_dll)s',
-                  FRAMEWORKS='%(python_frameworks_flags)s',
                   SWIG=r'%(swig)s',
+                  LIBPATH=[r'%(python_libpath)s'],
+                  LIBS='%(python_lib)s',
                   )
 
 import sys