[Scons-users] Custom Builder

William Roberts bill.c.roberts at gmail.com
Fri Sep 7 19:29:05 EDT 2012


Dirk,

Wasn't sure how to just do a reply from this mailing list as I get the
archived one. The miniat custom builder looks like:

Relevant parts of the builder:

import os;

class MiniatBuilder(object):

def __init__(self, rootdir, libdir, exedir, env, variant_dir):
self._rootdir = rootdir
self._libdir = libdir
self._exedir = exedir
self._variant_dir = variant_dir
self._env = env
self._env.Append(LIBPATH = libdir)
self._env.Append(CPPPATH = '#/vm/inc')

bld = self._env.Builder(action = 'flex -i -o $TARGET $SOURCE',
src_suffix = '.flex')
self._env.Append(BUILDERS = {'Flex' : bld})

bld = self._env.Builder(action = '0x1_lemon $SOURCE.file',
src_suffix = '.flex', chdir=1)
self._env.Append(BUILDERS = {'Lemon' : bld})

def flex(self, NAME=None, SRC=None):
return self._env.Flex(NAME, SRC)

def lemon(self, SRC=None):
return self._env.Lemon(SRC)

to reproduce do something like:

1. Have a SConstruct file that exports a class defined in another
file, like foo.py

2. foo.py constructor should have a env variable (env = Environment()
) set in the constructor in the SConstruct such as: foo(env)
the constructor should also add a custom Builder, such as in the
code above. The foo.py should also define a method in the class
that calls the custom builder.

3. Have the SContruct file export that variable to a SConscript file

4. Have a SConscript file Import that variable

5. Call the custom builder.


You can look at the code directly if you want to go to miniat.bitbucket.org

I really appreciate your help, trying to switch from Make to SCons is
anew thing for me.

Bill

Message: 4
Date: Fri, 07 Sep 2012 18:20:06 +0200
From: Dirk B?chle <tshortik at gmx.de>
Subject: Re: [Scons-users] Custom builder
To: scons-users at scons.org
Message-ID: <504A1EB6.60507 at gmx.de>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi Bill,

On 07.09.2012 11:00, William Roberts wrote:

> I am having issues wrapping a custom builder in a custom class.

>

> Suppose I have the following SConstruct file that calls a SConscript file:

>

> #Miniat is my custom wrapper for building

> miniat = MiniatBuilder(rootdir, libdir, exedir, env, q)

> SConscript(script, variant_dir=q, duplicate=1, exports=[ 'miniat' ] )

>

> Then in the SConscript file, I do something like:

>

> f = miniat.flex('src/lex.yy.c', 'src/0x1_assembler.lex')


what exactly does MiniatBuilder::flex() look like? Is it calling
self._env.Flex()?

A simple but complete test case would be nice, such that I can try to
reproduce the problem on my side.

Best regards,

Dirk

--
Respectfully,

William C Roberts


More information about the Scons-users mailing list