Hi, I had troubles with distutils 1.0 and the way I use SWIG. I couldn't find any support for the -shadow option and no way to pass an extra include dir to swig (like it´s possible for the c compiler) Therefore I wrote a patch. It adds an extra_swig_args (list of string) option to Extension. All the strings are passed to swig without modification, but if extra_swig_args contains "-c++" or "-shadow" there is some special action: "-c++": behaves like build_ext --swig-cpp "-shadow": Normally swig generates a file: foo.c -> foo.so In this case SWIG generates two files: foo.py (python shadow classes, imports fooc) fooc.c -> fooc.so With this patch build_ext can handle this und generates for foo.i (foo.py, fooc.c) compiles them and installs them. Below is the diff against disutils 1.0, apply in your Distutils-1.0 directory with: patch -p5 < file I hope it doesn´t break anything, isn´t against distutils design principles and is so useful that it might become part of distutils. Please answer me directly, because I didn´t not subscribe ths list. Regards joerg Joerg Baumann joerg.baumann@stud.informatik.uni-erlangen.de +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Beware of bugs in the above code; I have only proved it correct, not tried it. Don Knuth diff -r -C 2 -x *pyc /home/jgbauman/download/Distutils-1.0/distutils/command/build_ext.py ./command/build_ext.py *** /home/jgbauman/download/Distutils-1.0/distutils/command/build_ext.py Sat Sep 30 20:27:54 2000 --- ./command/build_ext.py Fri Oct 6 01:23:08 2000 *************** *** 386,390 **** # SWIG on 'em to create .c files, and modify the sources list # accordingly. ! sources = self.swig_sources(sources) # Next, compile the source code to object files. --- 386,398 ---- # SWIG on 'em to create .c files, and modify the sources list # accordingly. ! sources,extra_modules = self.swig_sources(sources,ext.extra_swig_args) ! ! # if there are extra_modules after running swig due to -shadow option ! # copy them to build/lib.xxx ! for module in extra_modules: ! outfile = os.path.join(self.build_lib,os.path.basename(module)) ! dir = os.path.dirname(outfile) ! self.mkpath(dir) ! self.copy_file(module, outfile, preserve_mode=0) # Next, compile the source code to object files. *************** *** 444,448 **** ! def swig_sources (self, sources): """Walk the list of source files in 'sources', looking for SWIG --- 452,456 ---- ! def swig_sources (self, sources, extra_swig_args): """Walk the list of source files in 'sources', looking for SWIG *************** *** 453,456 **** --- 461,465 ---- new_sources = [] + new_modules = [] swig_sources = [] swig_targets = {} *************** *** 461,464 **** --- 470,479 ---- # the temp dir. + if "-c++" in extra_swig_args: + self.swig_cpp=1 + if "-shadow" in extra_swig_args: + shadow=1 + else: + shadow=None if self.swig_cpp: target_ext = '.cpp' *************** *** 469,473 **** (base, ext) = os.path.splitext(source) if ext == ".i": # SWIG interface file ! new_sources.append(base + target_ext) swig_sources.append(source) swig_targets[source] = new_sources[-1] --- 484,492 ---- (base, ext) = os.path.splitext(source) if ext == ".i": # SWIG interface file ! if shadow: ! new_modules.append(base + ".py") ! new_sources.append(base + "c" + target_ext) ! else: ! new_sources.append(base + target_ext) swig_sources.append(source) swig_targets[source] = new_sources[-1] *************** *** 476,480 **** if not swig_sources: ! return new_sources swig = self.find_swig() --- 495,499 ---- if not swig_sources: ! return new_sources,new_modules swig = self.find_swig() *************** *** 482,486 **** if self.swig_cpp: swig_cmd.append("-c++") ! for source in swig_sources: target = swig_targets[source] --- 501,507 ---- if self.swig_cpp: swig_cmd.append("-c++") ! for arg in extra_swig_args: ! swig_cmd.append(arg) ! for source in swig_sources: target = swig_targets[source] *************** *** 488,492 **** self.spawn(swig_cmd + ["-o", target, source]) ! return new_sources # swig_sources () --- 509,513 ---- self.spawn(swig_cmd + ["-o", target, source]) ! return new_sources,new_modules # swig_sources () diff -r -C 2 -x *pyc /home/jgbauman/download/Distutils-1.0/distutils/command/install_lib.py ./command/install_lib.py *** /home/jgbauman/download/Distutils-1.0/distutils/command/install_lib.py Tue Oct 3 05:32:37 2000 --- ./command/install_lib.py Fri Oct 6 01:11:21 2000 *************** *** 90,94 **** # (Optionally) compile .py to .pyc ! if outfiles is not None and self.distribution.has_pure_modules(): self.byte_compile(outfiles) --- 90,94 ---- # (Optionally) compile .py to .pyc ! if outfiles is not None: self.byte_compile(outfiles) diff -r -C 2 -x *pyc /home/jgbauman/download/Distutils-1.0/distutils/extension.py ./extension.py *** /home/jgbauman/download/Distutils-1.0/distutils/extension.py Sun Sep 17 02:45:18 2000 --- ./extension.py Fri Oct 6 01:18:12 2000 *************** *** 74,78 **** extensions, which typically export exactly one symbol: "init" + extension_name. ! """ def __init__ (self, name, sources, --- 74,84 ---- extensions, which typically export exactly one symbol: "init" + extension_name. ! extra_swig_args : [string] ! any additional options for the swig tool. Unknown options will ! be passed unchanged. ! Known options: ! -c++: enable swig´s C++ support ! -shadow: generate shadow classes in python ! """ def __init__ (self, name, sources, *************** *** 87,90 **** --- 93,97 ---- extra_link_args=None, export_symbols=None, + extra_swig_args=None, ): *************** *** 106,109 **** --- 113,117 ---- self.extra_link_args = extra_link_args or [] self.export_symbols = export_symbols or [] + self.extra_swig_args = extra_swig_args or [] # class Extension
participants (1)
-
Joerg Baumann