[Scons-users] Builder

Neven Klacar nklacar at gmail.com
Wed Nov 27 15:45:58 EST 2013


The use case is to take a source c file, pass it to my builder, and my
builder will then pass it on to another builder which will pre-process the
file using a pre-processor which will create a new c file.
After this I will run a python script to replace certain tags in the new
file. Once finished my builder will return and the newly created file is
sent to Env.Object.

So flow is src file a.c -> My builder -> PreProcess(target, src)
My emitter modifies the target file to be a_altered.c

The input file is a normal c file, for now it just has a function
#include <stdio.h>
void a(void)
{
printf("Hello");
}

Scons file:

env.VariantDir('build', 'project', duplicate=0)

newfile=MyBuilder("build/a.c")
object=env.Object(newFile)
env.Library(object)
...

*My builder: *

*Builder*

def replace_tags(target)
<NOT IMPLEMENTED YET, will open file, and do a replace on certain
keywords

def my_builder(target, source, env)
for s, t in zip(source,target):
env.PreProcess(t,s, cmd)
replace_tags(t)

return None

def generate(env):
my_bld = env.Builder(action = SCons.Action.Action(my_builder)
,
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):

altered_targets=[]

for t in target:

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

altered_targets.append(fpath+'_compressed.c')



return (altered_targets,source)


---------------------------------------

The issue is with passing the target source to the next builder. Even if I
try to use the built in command builder, to just execute a command like cp
(to copy source to target) this fails as well.

I believe is that the sources field of the target node is pointing to a
non-existent file in the variant directory. Below is a dump of the nodes.
The save_str in mem0 is pointing to correct place but the absolute tpath
and others are pointing to the variant directory.

I believe I need to set duplicate to 1, so that the file gets duplicated in
the variant folder. This should probably fix my problem.

~Neven


I removed the leading file paths and replaced with ...
Target node:
(Pdb) pp tlist[0].__dict__
{'_local': 0,
'_memo': {'_save_str': '.../project/build/a_altered.c',
'children_get': [<SCons.Node.FS.File object at 0x2bf6650>],
'exists': False,
'get_build_env': <SCons.Script.SConscript.SConsEnvironment
object at 0x2e86150>,
'get_stored_info': <SCons.SConsign.SConsignEntry object at
0x4608950>,
'rfile': <SCons.Node.FS.File object at 0x2bf69d0>,
'stat': None},
'_proxy': <SCons.Node.FS.EntryProxy object at 0x3f90d90>,
'_specific_sources': False,
'abspath': '.../project/build/a_altered.c',
'always_build': None,
'attributes': <SCons.Node.Attrs object at 0x2bf65d0>,
'binfo': <SCons.Node.FS.FileBuildInfo object at 0x3657350>,
'builder': <SCons.Builder.BuilderBase object at 0x2bf4f90>,
'changed_since_last_build': <bound method File.decide_target of
<SCons.Node.FS.File object at 0x2bf69d0>>,
'cwd': <SCons.Node.FS.Dir object at 0x2fa2f10>,
'depends': [],
'depends_set': set(),
'dir': <SCons.Node.FS.Dir object at 0x2bf4c90>,
'duplicate': 0,
'env': <SCons.Script.SConscript.SConsEnvironment object at 0x2e86150>,
'executor': <SCons.Executor.Executor object at 0x2bf6b50>,
'fs': <SCons.Node.FS.FS object at 0x232f6d0>,
'ignore': [],
'ignore_set': set(),
'implicit': [],
'implicit_set': set(),
'includes': None,
'is_explicit': 1,
'labspath': '.../project/build/a_altered.c',
'linked': 0,
'name': 'a_altered.c',
'nocache': 0,
'noclean': 0,
'path': '.../project/build/a_altered.c',
'path_elements': [<SCons.Node.FS.RootDir object at 0x232f750>,
<SCons.Node.FS.Dir object at 0x232fbd0>,
<SCons.Node.FS.Dir object at 0x232fd90>,
<SCons.Node.FS.Dir object at 0x232fed0>,
<SCons.Node.FS.Dir object at 0x2336090>,
<SCons.Node.FS.Dir object at 0x23361d0>,
<SCons.Node.FS.Dir object at 0x2336310>,
<SCons.Node.FS.Dir object at 0x2336450>,
<SCons.Node.FS.Dir object at 0x2336590>,
<SCons.Node.FS.Dir object at 0x23366d0>,
<SCons.Node.FS.Dir object at 0x2336810>,
<SCons.Node.FS.Dir object at 0x249ead0>,
<SCons.Node.FS.Dir object at 0x24bbcd0>,
<SCons.Node.FS.Dir object at 0x2fa2d90>,
<SCons.Node.FS.Dir object at 0x2fa2f10>,
<SCons.Node.FS.Dir object at 0x2bf4b90>,
<SCons.Node.FS.Dir object at 0x2bf4410>,
<SCons.Node.FS.Dir object at 0x2bf4c90>,
<SCons.Node.FS.File object at 0x2bf69d0>],
'precious': None,
'prerequisites': [],
'ref_count': 0,
'sbuilder': None,
'scanner_paths': {},
'side_effect': 0,
'side_effects': [],
'sources': [<SCons.Node.FS.File object at 0x2bf6650>],
'sources_set': set([<SCons.Node.FS.File object at 0x2bf6650>]),
'state': 2,
'suffix': '.c',
'tpath': '.../project/build/a_altered.c',
'waiting_parents': set([<SCons.Node.FS.File object at 0x2bf6750>]),
'waiting_s_e': set(),
'wkids': None}


(Pdb) pp tlist[0].sources[0].__dict__
{'_local': 0,
'_memo': {'_save_str': '.../project/a.c',
'exists': False,
'get_size': 875,
'get_stored_info': <SCons.SConsign.SConsignEntry object at
0x46089d0>,
'get_timestamp': 1385071004,
'rfile': <SCons.Node.FS.File object at 0x2bf6c50>,
'stat': None},
'_specific_sources': False,
'abspath': '.../project/build/a.c',
'always_build': None,
'attributes': <SCons.Node.Attrs object at 0x2bf6b10>,
'binfo': <SCons.Node.FS.FileBuildInfo object at 0x3653f10>,
'builder': None,
'cwd': None,
'depends': [],
'depends_set': set(),
'dir': <SCons.Node.FS.Dir object at 0x2bf4c90>,
'duplicate': 0,
'env': None,
'executor': <SCons.Executor.Null object at 0x453b1d0>,
'fs': <SCons.Node.FS.FS object at 0x232f6d0>,
'ignore': [],
'ignore_set': set(),
'implicit': None,
'includes': None,
'labspath': '.../project/build/a.c',
'linked': 0,
'name': 'a.c',
'ninfo': <SCons.Node.FS.FileNodeInfo object at 0x2bf6250>,
'nocache': 0,
'noclean': 0,
'path': '.../project/build/a.c',
'path_elements': [<SCons.Node.FS.RootDir object at 0x232f750>,
<SCons.Node.FS.Dir object at 0x232fbd0>,
<SCons.Node.FS.Dir object at 0x232fd90>,
<SCons.Node.FS.Dir object at 0x232fed0>,
<SCons.Node.FS.Dir object at 0x2336090>,
<SCons.Node.FS.Dir object at 0x23361d0>,
<SCons.Node.FS.Dir object at 0x2336310>,
<SCons.Node.FS.Dir object at 0x2336450>,
<SCons.Node.FS.Dir object at 0x2336590>,
<SCons.Node.FS.Dir object at 0x23366d0>,
<SCons.Node.FS.Dir object at 0x2336810>,
<SCons.Node.FS.Dir object at 0x249ead0>,
<SCons.Node.FS.Dir object at 0x24bbcd0>,
<SCons.Node.FS.Dir object at 0x2fa2d90>,
<SCons.Node.FS.Dir object at 0x2fa2f10>,
<SCons.Node.FS.Dir object at 0x2bf4b90>,
<SCons.Node.FS.Dir object at 0x2bf4410>,
<SCons.Node.FS.Dir object at 0x2bf4c90>,
<SCons.Node.FS.File object at 0x2bf6650>],
'precious': None,
'prerequisites': [],
'ref_count': 0,
'sbuilder': None,
'scanner_paths': {},
'side_effect': 0,
'side_effects': [],
'sources': [],
'sources_set': set(),
'state': 3,
'suffix': '.c',
'tpath': '.../project/build/a.c',
'waiting_parents': set(),
'waiting_s_e': set(),
'wkids': None}


(Pdb) pp slist[0].__dict__
{'_local': 0,
'_memo': {'_save_str': '.../project/a.c',
'exists': True,
'stat': posix.stat_result(st_mode=33252, st_ino=3022497,
st_dev=2054L, st_nlink=1, st_uid=65330, st_gid=200, st_size=875,
st_atime=1385523208, st_mtime=1385071004, st_ctime=1385097000)},
'_specific_sources': False,
'abspath': '.../project/a.c',
'always_build': None,
'attributes': <SCons.Node.Attrs object at 0x2bf6b10>,
'builder': None,
'cwd': None,
'depends': [],
'depends_set': set(),
'dir': <SCons.Node.FS.Dir object at 0x2fa2d90>,
'duplicate': 0,
'env': None,
'fs': <SCons.Node.FS.FS object at 0x232f6d0>,
'ignore': [],
'ignore_set': set(),
'implicit': None,
'includes': None,
'labspath': '.../project/a.c',
'linked': 0,
'name': 'a.c',
'ninfo': <SCons.Node.FS.FileNodeInfo object at 0x2bf6c10>,
'nocache': 0,
'noclean': 0,
'path': '.../project/a.c',
'path_elements': [<SCons.Node.FS.RootDir object at 0x232f750>,
<SCons.Node.FS.Dir object at 0x232fbd0>,
<SCons.Node.FS.Dir object at 0x232fd90>,
<SCons.Node.FS.Dir object at 0x232fed0>,
<SCons.Node.FS.Dir object at 0x2336090>,
<SCons.Node.FS.Dir object at 0x23361d0>,
<SCons.Node.FS.Dir object at 0x2336310>,
<SCons.Node.FS.Dir object at 0x2336450>,
<SCons.Node.FS.Dir object at 0x2336590>,
<SCons.Node.FS.Dir object at 0x23366d0>,
<SCons.Node.FS.Dir object at 0x2336810>,
<SCons.Node.FS.Dir object at 0x249ead0>,
<SCons.Node.FS.Dir object at 0x24bbcd0>,
<SCons.Node.FS.Dir object at 0x2fa2d90>,
<SCons.Node.FS.File object at 0x2bf6c50>],
'precious': None,
'prerequisites': [],
'ref_count': 0,
'scanner_paths': {},
'side_effect': 0,
'side_effects': [],
'sources': [],
'sources_set': set(),
'state': 0,
'suffix': '.c',
'tpath': '.../project/a.c',
'waiting_parents': set(),
'waiting_s_e': set(),
'wkids': None}





On Wed, Nov 27, 2013 at 9:48 AM, Dirk Bächle <tshortik at gmx.de> wrote:


> On 27.11.2013 09:32, Neven Klacar wrote:

>

>>

>> I was trying to leverage on another builder that someone made in my

>> environment to do some of the work.

>>

>> Didn't realize its not supported .

>>

>> Is there no way to trick it by creating fresh nodes for the target file

>> so it doesn't have associated sources ?

>>

>>

> There might be something like a trick, but this is impossible to tell

> without getting some more info about what you're actually up to. Can you

> please provide us with a basic use case and some actual command lines? They

> should ideally demonstrate how your input files look, which dependencies

> they have, and which commands should get executed to create your final

> targets.

> Then we can talk about what would be the best approach...Builders,

> pseudo-Builders, source-Builders,... ;)

>

> Thanks a lot in advance,

>

> Dirk

>

>

> _______________________________________________

> 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/20131127/34181c7a/attachment.htm


More information about the Scons-users mailing list