[Scons-users] Tech question

Bill Deegan bill at baddogconsulting.com
Thu Jan 24 18:07:10 EST 2013


Daniel,

On Thu, Jan 24, 2013 at 2:14 PM, <nileiqi at optusnet.com.au> wrote:


> Hi,

>

>

> I am new to Scons and Python, and currently spend quite amount time to

> learn other people's code and Scons user guide. Please allow me ask some

> general and tech quesitons.

>

> Tech question

> (1) Whta is the main difference between generator and action ? For

> example, I have two pieces of code

>

> ****************** piece 1****************************

> bld=Builder(action = Action(function_name))

> env.Append(Builders= { 'foo':bld})

> *********************************************************

> ****************** piece 2****************************

> bld=Builder(generator = function_name)

> env.Append(Builders= { 'foo':bld})

> **********************************************************

> when run them, what is the different ?

>


I'd advise you do a thorough read of the manpage. It delves more into the
depths than the users guide.
http://www.scons.org/doc/production/HTML/scons-man.html


>From the manpage:


generator

A function that returns a list of actions that will be executed to build
the target(s) from the source(s). The returned action(s) may be an Action
object, or anything that can be converted into an Action object (see the
next section).

The generator function takes four arguments: *source* - a list of source
nodes, *target* - a list of target nodes, *env* - the construction
environment,*for_signature* - a Boolean value that specifies whether the
generator is being called for generating a build signature (as opposed to
actually executing the command). Example:


def g(source, target, env, for_signature):
return [["gcc", "-c", "-o"] + target + source]

b = Builder(generator=g)



The *generator* and *action* arguments must not both be used for the same
Builder.



A function that returns a list of actions that will be executed to build
the target(s) from the source(s). The returned action(s) may be an Action
object, or anything that can be converted into an Action object (see the
next section).

The generator function takes four arguments: *source* - a list of source
nodes, *target* - a list of target nodes, *env* - the construction
environment,*for_signature* - a Boolean value that specifies whether the
generator is being called for generating a build signature (as opposed to
actually executing the command). Example:


def g(source, target, env, for_signature):
return [["gcc", "-c", "-o"] + target + source]

b = Builder(generator=g)



The *generator* and *action* arguments must not both be used for the same
Builder.





> (2) For above piece 1 code, I realize it never execute until at the end of

> the code, when function Default() is called, why is that ?

>


SCons builds up information about the dependencies and what to do with them
from the SConstruct/SConscripts (and any other logic you may be pulling in).
Then it will scan the source tree, figure out the dependencies, and then
execute the builders logic.

Hope that helps!
-Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20130124/83d203fc/attachment.htm>


More information about the Scons-users mailing list