Welcome to I3dea.Build

I3dea.Build is a Python module that I use with SCons in order to customize the build. Many of them are based on recipes from the SCons wiki. For example:

  • The TestCase? builder runs a program if any of its sources have been modified since the last time it ran and without error. The programs return code is used to determine if an error occurred -- a value of zero means the test passed.
  • The Installer? class has functions to install all the headers files in a folder recursively, and change their permissions.

Usage

Create a project, and then add this module as an svn external.

I recommend you keep you svn externals in a text file, so that you can edit them easily when you have more than one external.

my_project/externals.txt:

build    http://bugx.i3dea.asu.edu/svn/build/trunk/build/src/build

console:

$> cd my_project
$> svn ps svn:externals -F externals.txt
$> svn ci -F externals.txt
$> svn up

You now have a folder named 'build' in your working copy, which is actually a reference to another version controlled project. When you update, you will get the latest changes to the build project. Google svn:externals if you want to lock in on a certain revision.

Here is an example SConstruct :

from build import *

#------------------------------------------------------------------------------
# Options to control the build

env = Environment(  tools=['mingw'],
                    CPPPATH=['#include', 
                             '$i3dea/include'],
                    LIBPATH=['$i3dea/lib']
                    )
vars = Variables('options.py')
vars.AddVariables(ListVariable('variant', 
                               'Build variant', 
                               ['release'], 
                               ['release',
                                'debug' ]), 
                  PathVariable('i3dea', 
                               'Location of the I3DEA libraries',
                               '/i3dea')                                   
                  )


#Add the installer options
installer.AddOptions(vars)
vars.Update(env)
vars.Save('options.py', env)
env.Help(vars.GenerateHelpText(env))


#create the installer
install = Installer(env)

#Make sure sconscripts have access
env.Export({'install':install});

#------------------------------------------------------------------------------
# Debug configuration
if 'debug' in env['variant']:
    dbg = env.Clone()
    #The SConscripts assume a single variant is being build.
    dbg['variant'] = ['debug']
    dbg.AppendUnique(CPPDEFINES={'DEBUG':1},
                     CCFLAGS=['-g'],
                     BOOST_SUFFIX='-mt-d',
                     STAGE='#stage/debug')
    dbg.Export({'env':dbg})
    dbg.SConscript('SConscript',
                   variant_dir='#stage/debug',
                   src_dir='#src')
    

#------------------------------------------------------------------------------
# Release configuration
if 'release' in env['variant']:
    rls = env.Clone()
    #The SConscripts assume a single variant is being build.
    rls['variant'] = ['release']
    rls.AppendUnique(CPPDEFINES={'NDEBUG':1},
                     CCFLAGS=['-O3'],
                     BOOST_SUFFIX='-mt',
                     STAGE='#stage/release')
    rls.Export({'env':rls})
    rls.SConscript('SConscript',
                   variant_dir='#stage/release',
                   src_dir='#src')
    
    install.AddHeaders(parent='#include', 
                       pattern='[!._]*.[hi]pp', 
                       recursive=True)
    
    #Make sure all tests pass before we install
    env.Depends('install', 'test')

And here is an example SConscript that runs tests:

Import('*')

#Every filename that starts with 'test_' is run as a standalone unit test.
for f in env.Glob('test_*.cpp'):
    env.TestCase(f)

Here is a sconscript that installs a file:

Import('*')

foo = env.Program('foo.cpp')
if 'release' in env['variant']:
    install.AddProgram(foo);

For a complete list of local wiki pages, see TitleIndex.