Search code examples
pythoncachingsconsbuild-systemhardlink

Overriding SCons Cache Copy Function


I'm trying to figure out how to override the behaviour when SCons copies artifacts from the cache directory (given by CacheDir) to used hard-links.

My current try

def link_or_copy_file(class_instance, src, dst):
    # do hardlinking instead...

SCons.Defaults.DefaultEnvironment()._copy_from_cache = link_or_copy_file
SCons.Defaults.DefaultEnvironment()._copy2_from_cache = link_or_copy_file

env = Environment()

env._copy_from_cache = link_or_copy_file
env._copy2_from_cache = link_or_copy_file

has no effect on subsequent usage of env. The function link_or_copy_file is never called. What is wrong?

Isn't it possible to override a Python class member function in this way.

Update: Also note that I'm doing this after env.Decider() has been called as this function possibly overrides the members _copy_from_cache and _copy2_from_cache.


Solution

  • We finally figured out that

    import SCons.Environment
    SCons.Environment.Environment._copy_from_cache = link_or_copy_file
    SCons.Environment.Environment._copy2_from_cache = link_or_copy_file
    

    worked.