Re: [Scons-dev] Possible minor bug + how to get (or assign) a builder to a file node?

2012-10-04 Thread Gary Oberbrunner
On Thu, Oct 4, 2012 at 9:31 AM, Left Right olegsivo...@gmail.com wrote:
 Builder.py:537

 def _execute(self, env, target, source, overwarn={}, executor_kw={}):
 # We now assume that target and source are lists or None.
 if self.src_builder:
 source = self.src_builder_sources(env, source, overwarn)

 Hi. I've ran into this (what seems to be a bug) while trying to find
 the builder of a created file node.

 It looks like for you this test is never true. Because if the
 src_builder was a builder object, it would be implementing a
 __nonzero__ method, which throws:
 InternalError: Do not test for the Node.builder attribute directly;
 use Node.has_builder() instead

 I ran into this eventually by trying to assign to src_builder property
 of a builder (this is something where I'm blur, but can't find any
 other way to link a file node to its builder). So that when I call
 _execute, self.src_builder exists, but can't be used inside condition.
 :|

 I'm most certain I don't quite understand yet how exactly to do what I
 need (so, I probably shouldn't even get there), just stumbled over
 this thing by accident.


 

 The question: suppose I have a generator function like this:

 def asGenerator(source, target, env, for_signature):
 print source: %s % source[0].get_path()
 print abs dir: %s % source[0].src_builder

 Suppose I have created a file node (which is source[0].get_path()) like so:

 class FlashBuilderBase(BuilderBase):
 
 An extension needed to run Flash() target with no arguments
 
 def __init__(self,  # long list of arguments...
 **overrides):
 self.fb_project_settings = None
 self.fd_project_settings = None
 return super(FlashBuilderBase, self).__init__(# same arguments
 once again...
   **overrides)

 def _execute(self, env, target, source, overwarn={}, executor_kw={}):
 # ...
 self.fb_project = # some info I need about the project file ...
 if not target:
 target = # some code to find the target ...

 if not source:
 source = target # this is the file, which later becomes
 the source[0] in asGenerator

 return super(FlashBuilderBase, self)._execute(
 env, target, source, overwarn, executor_kw)

 Now, I have to get reference this builder (FlashBuilderBase) from
 source[0] in asGenerator - how'd I do that?

You seem to be very confused, if you're that deep into the internals
and undocumented methods. :-)

Can you back up a few steps and say what you're trying to do?  (Note
that you say you're creating a File Node, but the code you show is for
a subclass of Builder, which is pretty odd.)  Have you been through
Chapter 18 of the User's Guide?
http://www.scons.org/doc/production/HTML/scons-user/c3621.html

-- 
Gary
___
Scons-dev mailing list
Scons-dev@scons.org
http://two.pairlist.net/mailman/listinfo/scons-dev


Re: [Scons-dev] Possible minor bug + how to get (or assign) a builder to a file node?

2012-10-04 Thread Left Right
Can you back up a few steps and say what you're trying to do?  (Note
that you say you're creating a File Node, but the code you show is for
a subclass of Builder, which is pretty odd.)  Have you been through
Chapter 18 of the User's Guide?
http://www.scons.org/doc/production/HTML/scons-user/c3621.html

--
Gary

Thanks for reply. I'm probably that deep because of a mismatch in
the regular way C or Java projects are built vs Flash. The thing is,
managing sources is very simple in Flash (the compiler does almost all
the job, it find the required sources by inferring from the code what
it should be looking for), but there are many configuration settings
that one should pass to compiler, which are given per project, or per
certain part of the project.

So, I'm much more interested in having a reference to the builder in
the generator function, then the source file names (I can obtain the
reference to the source files at any time, actually, and it's not very
important), but I need to somehow transfer a lot of information with
the group of files. For instance, the compiler has a concept of
modules, so it would compile a group of files, and then would compile
a module using the first group in a similar way you'd use headers in
C, when linking dynamic libraries.

Anyways, I think I can better explain my problem in terms of the code,
which isn't working quite as I'd need it to.

Step 0: I've extended BuilderBase with FlashBuilderBase and added this
builder to env[BUILDERS].
Step 1: I've overridden _execute in FlashBuilderBase in order to be
able to gather some important information about  the project (often
times Flash comes with Eclipse-style project files, so I'm parsing the
project file, and interpret the information I find in it in a way it
will be useful later during the build).
Step 2: This information is saved in a FlashBuilderBase field.
Step 3: The overriden _execute() calls super(FlashBuilderBase, self)._execute()
Step 4: BuilderBase._execute() at some point calls
self.action.batch_key(env or self.env, tlist, slist)
Step 5: batch_key() calls my generator function. In that generator
function I must have a reference to the builder which submitted the
source files, but I  can't because it is only in
Step 6: that BuilderBase._execute() calls t.builder_set(self) - and
this is too late :( because in my generator function I needed that
source.builder would give me the reference to FlashBuilderBase.

If I try to circumvent this by either calling
t.builder_set(FlashBuilderBaseInstance) before generator function is
called, it enters an infinite loop (why - I don't know yet)
Also, if I try, in FlashBuilderBase self.src_builder = [self] - this
enters infinite loop too.

I could find a solution by making generator function capture the
builder instance I need to acces in it, but this is super convoluted,
and it also means that I would need a function per builder (while it
could've been more generic).

What could've helped - is if BuilderBase._execute() called
t.builder_set(self) before it calls self.action.batch_key(env or
self.env, tlist, slist)

Sorry for a very long message!
___
Scons-dev mailing list
Scons-dev@scons.org
http://two.pairlist.net/mailman/listinfo/scons-dev


Re: [Scons-dev] Possible minor bug + how to get (or assign) a builder to a file node?

2012-10-04 Thread Gary Oberbrunner
On Thu, Oct 4, 2012 at 1:03 PM, Left Right olegsivo...@gmail.com wrote:
 Thanks for reply. I'm probably that deep because of a mismatch in
 the regular way C or Java projects are built vs Flash. The thing is,
 managing sources is very simple in Flash (the compiler does almost all
 the job, it find the required sources by inferring from the code what
 it should be looking for), but there are many configuration settings
 that one should pass to compiler, which are given per project, or per
 certain part of the project.

I don't know the details, but perhaps rather than overriding SCons
internals (which are subject to change), you could store all this
configuration in the Environment.  Use a different Environment for
each project, or part of project.  The builders can just use
$FLASH_XYZ to expand to whatever is different, because the environment
is remembered, and passed to the builder.  Perhaps this is similar to
wanting to use a different C compiler for different parts of a
project?  We do that, and just use different Environments to make it
work.
  env1.Object('foo1', foo1_sources)
  env2.Object('foo2', foo2_sources)
and so on.

In any case I don't think your step 0 is the right way to construct a
builder -- you should use the Builder() factory method.

-- 
Gary
___
Scons-dev mailing list
Scons-dev@scons.org
http://two.pairlist.net/mailman/listinfo/scons-dev