Search code examples
pythonscons

Scons: How to pass object files of main program to SConscript without having to create a library?


I have a main directory which is a main program and I have a test directory where I want to unit test it. I would like to pass all the object files on main to test so that I can link them

SConstruct file:

env = Enviornment
log = 'src/config/log'
main_xsd = 'src/config/schema/main.xsd'
xml = 'src/config/xml_manager'
main = 'src/main'

subpackages = [log, xml, main]

objects = []
for package in subpackages:
    pack_objects = env.SConscript(os.path.join(package,"SConscript"),
        dirs=package, variant_dir = 'build/' + package, duplicate=0,
        exports = 'env')

objects.append(pack_objects)
main_program = env.Program("antik", objects)
test = env.SConscript("test/SConscript",
        dirs='test', variant_dir = 'build/test', duplicate=0,
        exports = 'env')

env.Default(env.Install(os.path.join(prefix, "bin")), main_program)
env.Default(env.Install("/etc", log_config));

SConscript file in test directory

Import('env')

test_env = env.Clone()

test_env.Append(CPPPATH = ['#/unit_test'])

sources = ['unit_test/xml_validate_test.c', 'main.c']

program = test_env.Program(sources)
Return('program')

How do I pass the object files to Sconscript?


Solution

  • Please check the UserGuide of SCons at http://scons.org/doc/production/HTML/scons-user.html . In section 14.5 "Sharing Environments (and Other Variables) Between SConscript Files", you'll find examples for the usage of the methods Export() and Import().