[Scons-users] Modify CXXFile Builder
Dirk Bächle
tshortik at gmx.de
Tue Nov 18 12:07:40 EST 2014
Hi Stijn,
On 18.11.2014 10:38, Stijn De Ruyck wrote:
>
> Hello,
>
> I’m struggling to find the best way to extend the CXXFile Builder
> functionality.
>
> In short, in our make-based project we have this:
>
> file.cc: scanner.l
>
> /usr/bin/flex++ -Cfr -p -file.cc scanner.l; cat file.cc | sed
> 's/#include <FlexLexer.h>//g' > file_new.cc; mv file_new.cc file.cc
>
> What is the best way to translate this to SCons?
>
SCons already supports bison/flex out of the box, as well as replacing
text in files:
env = Environment(tools=['default','textfile'])
env.Replace(LEXFLAGS=['-Cfr','-p'])
env.Replace(LEXCOM='$LEX $LEXFLAGS -$TARGET $SOURCE')
import SCons.Tool.lex
import SCons.Builder.Builder
flexBuilder = SCons.Builder.Builder(action = SCons.Tool.lex.LexAction,
emitter =
SCons.Tool.lex.lexEmitter)
env.Append(BUILDERS={'Flex' : flexBuilder})
env.Flex('file.in','scanner.l')
env.Substfile('file.cc','file.in', SUBST_DICT = {'#include
<FlexLexer.h>' : ''})
(untested and from the top of my head, just to show the basic concept
that should be followed)
The tricky part here is, that the "lex.py" Tool doesn't add any Builder
methods to the current Environment that a user could call. It expects
you to simply say:
env.Program('foo', 'bar.l' + other_sources)
, which automatically calls (f)lex on the given file and returns the
resulting C(++) file. But for the "sed" step one needs full control, so
I grab into the lex.py Tool, pull out the required Actions/Emitters and
add a new Method to the environment.
Hope you can get it to work like this, and if you're successful...maybe
you could create a pull request for lex.py, adding the "Flex" method as
Builder that can be called explicitly anytime?
Best regards,
Dirk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20141118/989d3554/attachment-0001.html>
More information about the Scons-users
mailing list