Scons

35 views
Skip to first unread message

rd...@iinet.net.au

unread,
May 14, 2013, 10:15:44 AM5/14/13
to rt-thre...@googlegroups.com
Any Scons gurus here?
 
I have a custom builder that I create in a SConscript file which builds an object file (.o) from a source. If I call the builder from the SConscript file the object file is built but it is not linked into the executable. If I instead return a group from the SConscript file using DefineGroup that lists the source files I get an error that scons doesn't know how to build from a source file with that suffix. I am exporting the construction environment from the main SConstruct file which the SConscript file imports and appends my builder, so I thought it would know to call my builder for that suffix.
 
What am I missing? How do I get scons to use my builder for source files of a specific suffix? Or, how do I add the object file to the list of files to be linked?
 
Regards,
Rob
 

bernard

unread,
May 14, 2013, 10:28:45 AM5/14/13
to rt-thre...@googlegroups.com
Hi Rob, 
well,could you provide your SConscript file? How do you write your SConscript? 





Regards, 
Bernard 


2013/5/14 <rd...@iinet.net.au>
 

--
--
You received this message because you are subscribed to the Google
Groups "rt-thread-users" group.
To post to this group, send email to rt-thre...@googlegroups.com
To unsubscribe from this group, send email to
rt-thread-use...@googlegroups.com
 
---
You received this message because you are subscribed to the Google Groups "rt-thread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rt-thread-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

rd...@iinet.net.au

unread,
May 14, 2013, 11:39:08 AM5/14/13
to rt-thre...@googlegroups.com
I noticed an error in one of my paths but it didn't seem to be causing any problem. The line added to the SConstruct file should read:
 
objs = objs + SConscript('/xyz/SConscript', variant_dir='build/res', exports='env', duplicate=0)
 
It still managed to find the SConscript file even with the wrong path.
 

rd...@iinet.net.au

unread,
May 14, 2013, 11:43:23 AM5/14/13
to rt-thre...@googlegroups.com
For some reason my post with the code was deleted. I'll try posting it again.
 
SConstruct
------------------
objs = objs + SConscript('/xyz/SConscript', variant_dir='build/xyz', exports='env', duplicate=0)

SConscript
------------------
import rtconfig
from building import *
 
Import('env')
 
EXEC_PATH = rtconfig.EXEC_PATH
PREFIX = rtconfig.PREFIX
 
OBJCPY = '"' + EXEC_PATH + '/' + PREFIX + 'objcopy.exe"'
mybld = Builder(action = OBJCPY + ' --input-target binary --output-target elf32-littlearm --binary-architecture arm $SOURCE $TARGET',
            single_source = 1,
            suffix = '.o',
            src_suffix = '.xyz')
 
env['BUILDERS']['myBuild'] = mybld
 
files = Glob('*.xyz')
CPPPATH = [GetCurrentDir()]
group = DefineGroup('Custom', files, depend = [''], CPPPATH = CPPPATH)
 
Return('group')
 
 

rd...@iinet.net.au

unread,
May 14, 2013, 11:56:16 AM5/14/13
to rt-thre...@googlegroups.com
If I add
 
objs = env.myBuild(files)
 
before the Return in the SConscript file the object files are built and objs contains a list of the object files, so the builder is working but the object files don't get linked into the executable.
 
I just need to get scons to call my builder for files with the specified suffix.

rd...@iinet.net.au

unread,
May 14, 2013, 12:25:05 PM5/14/13
to rt-thre...@googlegroups.com
I've managed to get it to work by explicitly calling my builder in the SConstruct file and the SConscript file returns a list of source files without calling DefineGroup, but it's not the way I would expect it to work.
 
SConstruct  (inserted just before env.Program(TARGET, objs))
------------------
 
files = SConscript('/xyz/SConscript', variant_dir='build/xyz', exports='env', duplicate=0)
objs = objs + env.myBuild(files)
 

SConscript
------------------
import rtconfig
from building import *
 
Import('env')
 
EXEC_PATH = rtconfig.EXEC_PATH
PREFIX = rtconfig.PREFIX
 
OBJCPY = '"' + EXEC_PATH + '/' + PREFIX + 'objcopy.exe"'
mybld = Builder(action = OBJCPY + ' --input-target binary --output-target elf32-littlearm --binary-architecture arm $SOURCE $TARGET',
            single_source = 1,
            suffix = '.o',
            src_suffix = '.xyz')
 
env['BUILDERS']['myBuild'] = mybld
 
files = Glob('*.xyz')
Return('files')
 
Now I can see the objects get built and are passed to the linker and the expected symbols now appear in the map file.
 
Any ideas how to get scons to call my builder?
 
Regards,
Rob
 
Message has been deleted

rd...@iinet.net.au

unread,
May 14, 2013, 2:25:06 PM5/14/13
to rt-thre...@googlegroups.com
It would be nice to know why my posts get deleted.
 
After more reading and examining code I see that DefineGroup calls Env.Object to build the object files. I was under the impression that would search for a builder that could build the source file according to it's suffix. Now I understand that "Object" is a builder that only builds C,C++,D or Fortran source files. So it seems the only way for me to get this to work is to explicitly call my builder. So I'm not sure why you would add it to the environment unless another SConscript file needed access to it. I guess searching for an appropriate builder is an exercise for the user.
 
Anyway, here is the code that I now have working:
 
SConstruct
------------------
objs = objs + SConscript('/xyz/SConscript', variant_dir='build/xyz', duplicate=0)
 

SConscript
------------------
import rtconfig
from building import *
 
global Env

EXEC_PATH = rtconfig.EXEC_PATH
PREFIX = rtconfig.PREFIX
 
OBJCPY = '"' + EXEC_PATH + '/' + PREFIX + 'objcopy.exe"'
mybld = Builder(action = OBJCPY + ' --input-target binary --output-target elf32-littlearm --binary-architecture arm $SOURCE $TARGET',
            single_source = 1,
            suffix = '.o',
            src_suffix = '.xyz')
 
Env['BUILDERS']['myBuild'] = mybld
 
files = Glob('*.xyz')
objs = Env.myBuild(files)
 
Return('objs')
 
Regards,
Rob

 

bernard

unread,
May 14, 2013, 10:52:57 PM5/14/13
to rt-thre...@googlegroups.com
Hi Rob, 
What's your builder meaning? Does it convert the *.o to another file? And should each of *.o be converted to *.xyz? 
If that, you have wrote your builder according to scons manual. 

And another, I don't know why do you add your builder in SConscript file. It's better to implement your builder in another Python source file and add it in SConstruct file. 



Regards, 
Bernard 



2013/5/15 <rd...@iinet.net.au>
 
Regards,
Rob

 

--

rd...@iinet.net.au

unread,
May 17, 2013, 9:35:42 AM5/17/13
to rt-thre...@googlegroups.com
My two deleted posts arrived today by email, 2 days later. No idea what that was all about.
 
The source files for the builder can be any of several types I just used .xyz as the actual file type is not important. The builder uses the standard ObjCopy program to generate a .o file that contains the .xyz file as a binary data object. Instead of converting the file to a C array and compiling it. This allows me to easily include resource files (ie. png, bmp, jpg, txt, html etc. files) into my build without the unnecessary intermediate C source files and compilation. 
 
Why would it be better to put the builder in another python source? I assume you mean module? It is only used by that SConscript file to build the files in that subdirectory so I thought I would keep it all together. That way I only need to include the SConscript from another or from the SConstruct script to include it in the build. Also makes it easy to copy it to another project. Besides, it is only a single line.
 
The problem I was having was getting Scons to call my builder automatically but it appears that it isn't intended to work that way. I just call it explicitly and everything is working fine.
 
Regards,
Rob

bernard

unread,
May 17, 2013, 6:30:17 PM5/17/13
to rt-thre...@googlegroups.com
It's caused by Google Group policy. 

Everything is working fine, that is OK. 


2013/5/17 <rd...@iinet.net.au>
--
Reply all
Reply to author
Forward
0 new messages