SCons delete $TARGET on failure of any Action -


is there way emulate make's .delete_on_failure behavior? if have builder executes series of actions produce target, expect them operate atomically. if earlier action produces (incomplete) file, , later action fails modify it, target file deleted, instead of remaining in incomplete state.

consider sconstruct file:

def example(target, source, env):     raise exception('failure')     # more processing never happens...  action_list = [     copy('$target', '$source'),     chmod('$target', 0755),     example, ]  command(     action = action_list,     target = 'foo.out',     source = 'foo.in', ) 

if example action fails, foo.out still exists, because first 2 actions successful. however, incomplete.

interestingly, running scons again causes again retry build foo.out, though exists in filesystem.

yes, looking getbuildfailures.

expanding on example include feature...

import atexit import os  def delete_on_failure():     scons.script import getbuildfailures     bf in getbuildfailures():         if os.path.isfile(bf.node.abspath):             print 'removing %s' % bf.node.path             os.remove(bf.node.abspath) atexit.register(delete_on_failure)  def example(target, source, env):     raise exception('failure')     # more processing never happens...  action_list = [     copy('$target', '$source'),     chmod('$target', 0755),     example, ]  command(     action = action_list,     target = 'foo.out',     source = 'foo.in', ) 

which when run produces following...

>> scons --version scons steven knight et al.:     script: v2.3.4, 2014/09/27 12:51:43, garyo on lubuntu     engine: v2.3.4, 2014/09/27 12:51:43, garyo on lubuntu     engine path: ['/usr/lib/scons/scons'] copyright (c) 2001 - 2014 scons foundation  >> tree  . ├── foo.in └── sconstruct  0 directories, 2 files  >> scons scons: reading sconscript files ... scons: done reading sconscript files. scons: building targets ... copy("foo.out", "foo.in") chmod("foo.out", 0755) example(["foo.out"], ["foo.in"]) scons: *** [foo.out] exception : failure traceback (most recent call last):   file "/usr/lib/scons/scons/action.py", line 1065, in execute     result = self.execfunction(target=target, source=rsources, env=env)   file "/path/to/sconstruct", line 13, in example     raise exception('failure') exception: failure scons: building terminated because of errors. removing foo.out  >> tree . ├── foo.in └── sconstruct  0 directories, 2 files 

Popular posts from this blog