[Scons-users] Builder

Bill Deegan bill at baddogconsulting.com
Wed Nov 27 02:10:50 EST 2013


Neven,

Don't run another builder in a builder...
You can have actions, but not builders inside a builder.

-Bill
Co-Manager, SCons project


On Tue, Nov 26, 2013 at 9:54 PM, Neven Klacar <nklacar at gmail.com> wrote:


> Hi ,

>

> I forgot to mention, I tried DIrk's recommendation and it still had the

> same problem.

> The recommendation was to pass a string object back to the builder.

>

> emitter

> altered_targets=[]

> for t in target:

> fpath,fext=os.path.splitext(str(t))

> altered_targets.append(fpath+'_altered.c')

> return (altered_targets,source)

>

>

> I did some more investigation and narrowed it down to problem when I

> invoke another builder from my builder. In my example I didn't have exactly

> what I was trying to do. I was invoking another builder from my builder.

>

> If I declare my builder like this lets say:

> my_bld = env.Builder(action = SCons.Action.Action('cp $SOURCE $TARGET')

> ,

> source_scanner = SCons.Scanner.C.CScanner(),

> emitter = my_emitter,

> suffix = '.c2', src_suffix = '.c')

>

> I don't have any problems. I can see it executes the cp and the target

> file is created.

>

> If I however do this:

> def my_builder(target, source, env)

> env.Command(target,source, 'cp $SOURCE $TARGET')

>

> my_bld = env.Builder(action = SCons.Action.Action(my_builder)

> ,

> source_scanner = SCons.Scanner.C.CScanner(),

> emitter = my_emitter,

> suffix = '.c2', src_suffix = '.c')

>

>

> This is when I see the error message.

>

> I looked at BaseBuilder and I see it prints this in node_errors when it

> detects the sources for a target node are different from the sources that

> were passed to builder.

> elif t.sources != slist: 314 msg<http://www.scons.org/doc/HTML/scons-api/SCons.Builder-pysrc.html#>

> = "Multiple ways to build the same target were specified for: %s (from %s

> and from %s)" % (t, list(map(str, t.sources)), list(map(str, slist))) 315

> raise UserError<http://www.scons.org/doc/HTML/scons-api/SCons.Builder-pysrc.html#>

> (msg <http://www.scons.org/doc/HTML/scons-api/SCons.Builder-pysrc.html#>)

>

> In the print out of the error message the sources are the same. This is

> the string representation, so I am guessing they are two different file

> nodes and this is where the comparison is failing? It is not clear to me

> why they would be two different nodes for the source file? Is there a

> custom comparison method for the nodes or is it just doing a regular object

> comparison?

>

> Thanks,

> Neven

>

> On Tue, Nov 26, 2013 at 8:13 PM, Bill Deegan <bill at baddogconsulting.com>wrote:

>

>> Neven,

>>

>> As Dirk mentioned in the email on the dev list the .name parameter should

>> not be used for this (or in general for anything.. I've never used it and

>> I've been using SCons a long time).

>>

>> What happens if your run : scons --tree=prune ?

>>

>> -Bill

>>

>>

>> On Tue, Nov 26, 2013 at 6:56 PM, Neven Klacar <nklacar at gmail.com> wrote:

>>

>>> Hi, trying to make a builder that takes source file

>>> a.c and creates a new C file, a_altered.c using a python script or

>>> program that in this example will be preprocess lets say.

>>>

>>> Then I want to pass the altered file to be built in normal workflow

>>>

>>> newfile=MyBuilder("a.c")

>>> object=env.Object(newFile)

>>> env.Library(object)

>>> ....

>>>

>>> In the builder I created a an emitter which modifies the target files to

>>> have a different name.

>>> *Builder*

>>> def generate(env):

>>> my_bld = env.Builder(action = 'preprocess< $SOURCE > $TARGET'

>>> ,

>>> source_scanner =

>>> SCons.Scanner.C.CScanner(),

>>> emitter = my_emitter,

>>> suffix = '.c2', src_suffix = '.c')

>>>

>>> env.Append(BUILDERS = {'MyBuilder' : my_bld})

>>>

>>>

>>>

>>> def my_emitter(target, source, env):

>>>

>>> for t in target:

>>>

>>> t.name=t.name[:t.name.rfind('.')]+'_altered.c'

>>>

>>> return (target,source)

>>>

>>>

>>>

>>> The basic error I get is that there seems to be two ways to build the

>>> same file

>>>

>>> .../project/build/objects/a_altered.c failed: Multiple ways to build

>>> the same target were specified for: ...project/build/objects/a_altered.c

>>> (from ['.../project/src/a.c'] and from ['.../project/src/a.c'])

>>>

>>>

>>>

>>> Am I going about this the right way?

>>>

>>>

>>> I appreciate any help or suggestions!

>>>

>>>

>>> Thanks,

>>>

>>> Neven

>>>

>>> _______________________________________________

>>> Scons-users mailing list

>>> Scons-users at scons.org

>>> http://four.pairlist.net/mailman/listinfo/scons-users

>>>

>>>

>>

>> _______________________________________________

>> Scons-users mailing list

>> Scons-users at scons.org

>> http://four.pairlist.net/mailman/listinfo/scons-users

>>

>>

>

> _______________________________________________

> Scons-users mailing list

> Scons-users at scons.org

> http://four.pairlist.net/mailman/listinfo/scons-users

>

>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://four.pairlist.net/pipermail/scons-users/attachments/20131126/e951566d/attachment.html


More information about the Scons-users mailing list