Discussion:
[Scons-users] SWIG emitter patch
E.Z. Evgenii
2018-01-19 18:56:37 UTC
Permalink
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
Bill Deegan
2018-01-19 20:56:18 UTC
Permalink
Evgenii,

Any chance you could make a pull request with a test to cover this new
functionality?

-Bill
Post by E.Z. Evgenii
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.
swigflags = env.subst("$SWIGFLAGS", target=target, source=source)
flags = SCons.Util.CLVar(swigflags)
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*
# 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
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
E.Z. Evgenii
2018-01-21 07:46:44 UTC
Permalink
I can file a bug report, with this code piece, if that's what you mean.

I am new here and don't know what pull request is.

I also haven't tried the test set up. I suppose I could write a test for this, but it would take time to learn, and I don't have much spare time.

I should write a unit test for my patch anyway...

Evgenii


________________________________
Date: Fri, 19 Jan 2018 15:56:18 -0500
From: Bill Deegan <***@baddogconsulting.com>
To: SCons users mailing list <scons-***@scons.org>
Subject: Re: [Scons-users] SWIG emitter patch
Message-ID:
<CAEyG4CE7_4kEPNWGRmvHMp3rD0xskMg8bD13Kh2VT0C31hm_=***@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Evgenii,

Any chance you could make a pull request with a test to cover this new
functionality?

-Bill
Post by E.Z. Evgenii
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.
swigflags = env.subst("$SWIGFLAGS", target=target, source=source)
flags = SCons.Util.CLVar(swigflags)
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*
# 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
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20180119/3932150a/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Scons-users mailing list
Scons-***@scons.org
https://pairlist4.pair.net/mailman/listinfo/scons-users
Scons-users Info Page - pairlist4.pair.net<https://pairlist4.pair.net/mailman/listinfo/scons-users>
pairlist4.pair.net
A general discussion list for the SCons project's end users. Questions, discussion and suggestions are all appropriate here. If you're in doubt as to whether a post ...





------------------------------

End of Scons-users Digest, Vol 74, Issue 8
******************************************
Mats Wichmann
2018-01-21 16:32:35 UTC
Permalink
Post by E.Z. Evgenii
I can file a bug report, with this code piece, if that's what you mean.
I am new here and don't know what pull request is.
I also haven't tried the test set up. I suppose I could write a test for this, but it would take time to learn, and I don't have much spare time.
I should write a unit test for my patch anyway...
Evgenii
a pull request means you leave a request on the github project page for
your change to be merged (from a branch somewhere where it is already
integrated). explaining the full mechanism is beyond a message here.
when you submit a pull requests, the tests will be automatically run, so
this helps the maintainers evaluate the correctness of the change/test
change.
Bill Deegan
2018-01-21 20:51:40 UTC
Permalink
Evgenii,

Take a look at this page:
https://github.com/SCons/scons/wiki/GitWorkflows

It has some basic instructions on how to submit a patch as a pull requests.

And:
https://github.com/SCons/scons/wiki/TestingMethodology
On testing.
Note, that you can likely look at the tests in : test/SWIG/ for some
examples.

Please don't hesitate to ask for help here or in our IRC channel #scons on
freenode.net
(there's a web base chat at :http://webchat.freenode.net/ )

Thanks,
Bill
SCons Project Co-manager.
Post by E.Z. Evgenii
Post by E.Z. Evgenii
I can file a bug report, with this code piece, if that's what you mean.
I am new here and don't know what pull request is.
I also haven't tried the test set up. I suppose I could write a test for
this, but it would take time to learn, and I don't have much spare time.
Post by E.Z. Evgenii
I should write a unit test for my patch anyway...
Evgenii
a pull request means you leave a request on the github project page for
your change to be merged (from a branch somewhere where it is already
integrated). explaining the full mechanism is beyond a message here.
when you submit a pull requests, the tests will be automatically run, so
this helps the maintainers evaluate the correctness of the change/test
change.
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Loading...