assert len(source) == 1
srcf = str(source[0])
dstf = str(target[0])
with open(srcf, 'r') as f:
    contents = f.read()
for old, new in env['REPLST']:
    contents = re.sub(old, new, contents)
with open(dstf, 'w') as outf:
    outf.write(contents)
replace_builder = Builder(action=replace_action)
env = Environment(ENV=os.environ)
env.Append(BUILDERS={'Replace': replace_builder})
b = env.Replace('somefile', ['somefile.tmpl'], REPLST=[('A', 'b')])
lib = env.SharedLibrary('lib', object + [b], extra_libs)
SCons: How to call a self defined python function in scons script and make right dependency