Commit a024034b authored by Anthony Baxter's avatar Anthony Baxter

Patch 1046644 - improved distutils support for SWIG.

parent 78f58abe
...@@ -81,6 +81,10 @@ class build_ext (Command): ...@@ -81,6 +81,10 @@ class build_ext (Command):
"specify the compiler type"), "specify the compiler type"),
('swig-cpp', None, ('swig-cpp', None,
"make SWIG create C++ files (default is C)"), "make SWIG create C++ files (default is C)"),
('swig-opts=', None,
"list of SWIG command line options"),
('swig=', None,
"path to the SWIG executable"),
] ]
boolean_options = ['inplace', 'debug', 'force', 'swig-cpp'] boolean_options = ['inplace', 'debug', 'force', 'swig-cpp']
...@@ -107,8 +111,9 @@ class build_ext (Command): ...@@ -107,8 +111,9 @@ class build_ext (Command):
self.debug = None self.debug = None
self.force = None self.force = None
self.compiler = None self.compiler = None
self.swig = None
self.swig_cpp = None self.swig_cpp = None
self.swig_opts = None
def finalize_options (self): def finalize_options (self):
from distutils import sysconfig from distutils import sysconfig
...@@ -205,6 +210,11 @@ class build_ext (Command): ...@@ -205,6 +210,11 @@ class build_ext (Command):
if self.undef: if self.undef:
self.undef = string.split(self.undef, ',') self.undef = string.split(self.undef, ',')
if self.swig_opts is None:
self.swig_opts = []
else:
self.swig_opts = self.swig_opts.split(' ')
# finalize_options () # finalize_options ()
...@@ -429,7 +439,7 @@ class build_ext (Command): ...@@ -429,7 +439,7 @@ class build_ext (Command):
# First, scan the sources for SWIG definition files (.i), run # First, scan the sources for SWIG definition files (.i), run
# SWIG on 'em to create .c files, and modify the sources list # SWIG on 'em to create .c files, and modify the sources list
# accordingly. # accordingly.
sources = self.swig_sources(sources) sources = self.swig_sources(sources, ext)
# Next, compile the source code to object files. # Next, compile the source code to object files.
...@@ -492,7 +502,7 @@ class build_ext (Command): ...@@ -492,7 +502,7 @@ class build_ext (Command):
target_lang=language) target_lang=language)
def swig_sources (self, sources): def swig_sources (self, sources, extension):
"""Walk the list of source files in 'sources', looking for SWIG """Walk the list of source files in 'sources', looking for SWIG
interface (.i) files. Run SWIG on all that are found, and interface (.i) files. Run SWIG on all that are found, and
...@@ -510,6 +520,9 @@ class build_ext (Command): ...@@ -510,6 +520,9 @@ class build_ext (Command):
# the temp dir. # the temp dir.
if self.swig_cpp: if self.swig_cpp:
log.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
if self.swig_cpp or ('-c++' in self.swig_opts):
target_ext = '.cpp' target_ext = '.cpp'
else: else:
target_ext = '.c' target_ext = '.c'
...@@ -526,11 +539,17 @@ class build_ext (Command): ...@@ -526,11 +539,17 @@ class build_ext (Command):
if not swig_sources: if not swig_sources:
return new_sources return new_sources
swig = self.find_swig() swig = self.swig or self.find_swig()
swig_cmd = [swig, "-python"] swig_cmd = [swig, "-python"]
swig_cmd.extend(self.swig_opts)
if self.swig_cpp: if self.swig_cpp:
swig_cmd.append("-c++") swig_cmd.append("-c++")
# Do not override commandline arguments
if not self.swig_opts:
for o in extension.swig_opts:
swig_cmd.append(o)
for source in swig_sources: for source in swig_sources:
target = swig_targets[source] target = swig_targets[source]
log.info("swigging %s to %s", source, target) log.info("swigging %s to %s", source, target)
......
...@@ -54,7 +54,7 @@ extension_keywords = ('name', 'sources', 'include_dirs', ...@@ -54,7 +54,7 @@ extension_keywords = ('name', 'sources', 'include_dirs',
'define_macros', 'undef_macros', 'define_macros', 'undef_macros',
'library_dirs', 'libraries', 'runtime_library_dirs', 'library_dirs', 'libraries', 'runtime_library_dirs',
'extra_objects', 'extra_compile_args', 'extra_link_args', 'extra_objects', 'extra_compile_args', 'extra_link_args',
'export_symbols', 'depends', 'language') 'swig_opts', 'export_symbols', 'depends', 'language')
def setup (**attrs): def setup (**attrs):
"""The gateway to the Distutils: do everything your setup script needs """The gateway to the Distutils: do everything your setup script needs
......
...@@ -75,6 +75,9 @@ class Extension: ...@@ -75,6 +75,9 @@ class Extension:
used on all platforms, and not generally necessary for Python used on all platforms, and not generally necessary for Python
extensions, which typically export exactly one symbol: "init" + extensions, which typically export exactly one symbol: "init" +
extension_name. extension_name.
swig_opts : [string]
any extra options to pass to SWIG if a source file has the .i
extension.
depends : [string] depends : [string]
list of files that the extension depends on list of files that the extension depends on
language : string language : string
...@@ -95,6 +98,7 @@ class Extension: ...@@ -95,6 +98,7 @@ class Extension:
extra_compile_args=None, extra_compile_args=None,
extra_link_args=None, extra_link_args=None,
export_symbols=None, export_symbols=None,
swig_opts = None,
depends=None, depends=None,
language=None, language=None,
**kw # To catch unknown keywords **kw # To catch unknown keywords
...@@ -116,6 +120,7 @@ class Extension: ...@@ -116,6 +120,7 @@ class Extension:
self.extra_compile_args = extra_compile_args or [] self.extra_compile_args = extra_compile_args or []
self.extra_link_args = extra_link_args or [] self.extra_link_args = extra_link_args or []
self.export_symbols = export_symbols or [] self.export_symbols = export_symbols or []
self.swig_opts = swig_opts or []
self.depends = depends or [] self.depends = depends or []
self.language = language self.language = language
......
...@@ -284,6 +284,7 @@ Eric Huss ...@@ -284,6 +284,7 @@ Eric Huss
Jeremy Hylton Jeremy Hylton
Mihai Ibanescu Mihai Ibanescu
Juan David Ibez Palomar Juan David Ibez Palomar
Lars Immisch
Tony Ingraldi Tony Ingraldi
John Interrante John Interrante
Bob Ippolito Bob Ippolito
......
...@@ -47,6 +47,11 @@ Extension modules ...@@ -47,6 +47,11 @@ Extension modules
Library Library
------- -------
- Patch 1046644: distutils build_ext grew two new options - --swig for
specifying the swig executable to use, and --swig-opts to specify
options to pass to swig. --swig-opts="-c++" is the new way to spell
--swig-cpp.
- Patch 983206: distutils now obeys environment variable LDSHARED, if - Patch 983206: distutils now obeys environment variable LDSHARED, if
it is set. it is set.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment