#!/usr/bin/env python
#
# __COPYRIGHT__
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"

"""
Verify that SWIG implicit dependencies are caught.
"""

import sys

import TestSCons

if sys.platform =='darwin':
    # change to make it work with stock OS X python framework
    # we can't link to static libpython because there isn't one on OS X
    # so we link to a framework version. However, testing must also
    # use the same version, or else you get interpreter errors.
    python = "/System/Library/Frameworks/Python.framework/Versions/Current/bin/python"
    _python_ = '"' + python + '"'
else:
    python = TestSCons.python
    _python_ = TestSCons._python_

# swig-python expects specific filenames.
# the platform specific suffix won't necessarily work.
if sys.platform == 'win32':
    _dll = '.dll'
else:
    _dll   = '.so' 

test = TestSCons.TestSCons()

swig = test.where_is('swig')

if not swig:
    test.skip_test('Can not find installed "swig", skipping test.\n')



version = sys.version[:3] # see also sys.prefix documentation

# handle testing on other platforms:
ldmodule_prefix = '_'

frameworks = ''
platform_sys_prefix = sys.prefix
if sys.platform == 'darwin':
    # OS X has a built-in Python but no static libpython
    # so you should link to it using apple's 'framework' scheme.
    # (see top of file for further explanation)
    frameworks = '-framework Python'
    platform_sys_prefix = '/System/Library/Frameworks/Python.framework/Versions/%s/' % version

test.write("dependency.i", """\
%module dependency
""")

test.write("dependent.i", """\
%module dependent

%include dependency.i
""")

test.write('SConstruct', """
foo = Environment(SWIGFLAGS='-python',
                  CPPPATH='%(platform_sys_prefix)s/include/python%(version)s/',
                  LDMODULEPREFIX='%(ldmodule_prefix)s',
                  LDMODULESUFFIX='%(_dll)s',
                  FRAMEWORKSFLAGS='%(frameworks)s',
                  )

swig = foo.Dictionary('SWIG')
bar = foo.Clone(SWIG = r'%(_python_)s wrapper.py ' + swig)
foo.CFile(target = 'dependent', source = ['dependent.i'])
""" % locals())

test.run()

test.write("dependency.i", """%module dependency

extern char *dependency_string();
""")

test.not_up_to_date(arguments = "dependent_wrap.c")



test.pass_test()

@@ -1738,178 +1738,8 @@
 n_%0A%0A
-# swig-python expects specific filenames.%0A# the platform specific suffix won't necessarily work.%0Aif sys.platform == 'win32':%0A    _dll = '.dll'%0Aelse:%0A    _dll   = '.so' %0A%0A
 test
@@ -1947,905 +1947,211 @@
 on%0A%0A
-# handle testing on other platforms:%0Aldmodule_prefix = '_'%0A%0Aframeworks = ''%0Aplatform_sys_prefix = sys.prefix%0Aif sys.platform == 'darwin':%0A    # OS X has a built-in Python but no static libpython%0A    # so you should link to it using apple's 'framework' scheme.%0A    # (see top of file for further explanation)%0A    frameworks = '-framework Python'%0A    platform_sys_prefix = '/System/Library/Frameworks/Python.framework/Versions/%25s/' %25 version%0A%0Atest.write(%22dependency.i%22, %22%22%22%5C%0A%25module dependency%0A%22%22%22)%0A%0Atest.write(%22dependent.i%22, %22%22%22%5C%0A%25module dependent%0A%0A%25include dependency.i%0A%22%22%22)%0A%0Atest.write('SConstruct', %22%22%22%0Afoo = Environment(SWIGFLAGS='-python',%0A                  CPPPATH='%25(platform_sys_prefix)s/include/python%25(version)s/',%0A                  LDMODULEPREFIX='%25(ldmodule_prefix)s',%0A                  LDMODULESUFFIX='%25(_dll)s',%0A                  FRAMEWORKSFLAGS='%25(frameworks)s',%0A                  )%0A
+%0Atest.write(%22dependency.i%22, %22%22%22%5C%0A%25module dependency%0A%22%22%22)%0A%0Atest.write(%22dependent.i%22, %22%22%22%5C%0A%25module dependent%0A%0A%25include dependency.i%0A%22%22%22)%0A%0Atest.write('SConstruct', %22%22%22%0Afoo = Environment(SWIGFLAGS='-python')
 %0Aswi

Remove left-over cut-and-paste stuff about loadable modules and frameworks.