E.Z. Evgenii
2018-01-19 18:56:37 UTC
Hello.
I ended up monkey-patching SWIG emitter to work when module name is not inside .i file, but provided with -module option instead. The latter is preferred for us, because we often need to base some names off this module name, and we don't want to have it in two places.
The original code in SCons/Tool/swig.py completely ignores this option and results in not emitting anything.
Here's a chunk of code I patched:
def _swigEmitter(target, source, env):
swigflags = env.subst("$SWIGFLAGS", target=target, source=source)
flags = SCons.Util.CLVar(swigflags)
for src in source:
src = str(src.rfile())
##### Replace this line: mnames = None
##### Begin patch
try:
mod_index = flags.index('-module')
mod_name = flags[mod_index+1]
mnames = [mod_name] if mod_name else None
except ValueError, IndexError:
mnames = None
directors = 0
##### end patch
if "-python" in flags and "-noproxy" not in flags:
# etc. etc.
I now get the .py file emitted (should work for other languages, as this is a language-independent section)
It would be nice to have that inside SCons, by default.
I am using 2.5.0, by the way.
Evgenii
I ended up monkey-patching SWIG emitter to work when module name is not inside .i file, but provided with -module option instead. The latter is preferred for us, because we often need to base some names off this module name, and we don't want to have it in two places.
The original code in SCons/Tool/swig.py completely ignores this option and results in not emitting anything.
Here's a chunk of code I patched:
def _swigEmitter(target, source, env):
swigflags = env.subst("$SWIGFLAGS", target=target, source=source)
flags = SCons.Util.CLVar(swigflags)
for src in source:
src = str(src.rfile())
##### Replace this line: mnames = None
##### Begin patch
try:
mod_index = flags.index('-module')
mod_name = flags[mod_index+1]
mnames = [mod_name] if mod_name else None
except ValueError, IndexError:
mnames = None
directors = 0
##### end patch
if "-python" in flags and "-noproxy" not in flags:
# etc. etc.
I now get the .py file emitted (should work for other languages, as this is a language-independent section)
It would be nice to have that inside SCons, by default.
I am using 2.5.0, by the way.
Evgenii