Source

SCons-custom-sig / mydev / SConstruct

Full commit
env = Environment()
import SCons

def myDecider(dependency, target, prev_ni):
    
    # We always have to init the .ext_sig value...
    dep_ext_sig = dependency.get_ext_sig()

    if prev_ni is None:
        ## No previous record -> first time looking at this -> "changed"
        return True
    try:
        prev_ext_sig = prev_ni.ext_sig
    except AttributeError:
        ## No .ext_sig attribute -> first time looking at this (with ext_sig aware code) -> "changed"
        return True

    #Finally, compare extended signatures
    return dep_ext_sig != prev_ext_sig

env.Decider(myDecider)


def hashImportantLines(contents):

    """Takes a hash of lines that don't begin with #.  This is just an
    example! I'm not certain that '\n'.join(X.split('\n')) == X for
    all X.  Think about trailing newlines.  Also doesn't consider CRLF
    line breaks, etc...    
    """
    reduced_contents = []
    for line in contents.split('\n'):
        if len(line)==0 or line[0] != '#':
            reduced_contents.append(line)
    return SCons.Util.MD5signature('\n'.join(reduced_contents))    


def sigMaker(f):
    ninfo = f.get_ninfo()    
    #print "Executing sigMaker"
    ext_sig = hashImportantLines(f.get_contents())
    ninfo.ext_sig = ext_sig
    return ext_sig

SCons.Defaults.DefaultEnvironment().ExtSignature(sigMaker)
env.ExtSignature(sigMaker)
#print "Just set it for env %s" % repr(env)
#print "default env is %s" % repr(SCons.Defaults.DefaultEnvironment())

b=Builder(action="bash myscript.sh $SOURCE $TARGET")
env.Append(BUILDERS={'B' : b})
env.Export()

i=File('myinput.txt')
x=env.B(['myoutput.txt'],[i])
print repr(i.rfile().get_ninfo().__dict__)