In scons, I am attempting to make a UnitTest system (see code below), based on the great example from here: http://spacepants.org/blog/scons-unit-test
However due to a problem in recent scons 2.0.1 and newer, this cases a dependency cycle, as documented here: http://old.nabble.com/AddPostAction-executes-on-first-build-but-not-subsequent-td18360675.html (and elsewhere).
Does anyone know of a good work-around or replacement solution to this problem?
Code:
def UnitTest(env, target, source, **kwargs):
curTest = env.Program(target, source, **kwargs)
env.AddPostAction(curTest, curTest[0].abspath)
env.Alias('unit_tests', curTest)
env.AlwaysBuild(curTest)
return curTest
SConsEnvironment.UnitTest = UnitTest
mandolineTest = env.UnitTest(target='./codeTest',
source = mix(['test.cc', 'base.cc'),
LIBS = default_libs + ['bgl',],
LIBPATH = default_libs_path,
CPPPATH = default_includes )
I found a workaround for this problem. By using:
env.AddPostAction(curTest, curTest[0].abspath)
it appears that SCons tries to be clever and add a build dependency for curTest[0].abspath
to itself, causing this circular dependency problem. The solution is to "hide" the execution of the command from SCons so it can't figure out what you are doing:
env.AddPostAction(curTest, lambda *_, **__: os.system(curTest[0].abspath))
For my unit test system (which is slightly different from yours but had the same problem), this has the desired effect of running the unit test whenever any of its dependencies changes, and not running it if nothing relevant has changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With