Search code examples
sconssymlink

How to create a symbolic link with SCons?


I'm using SCons for building a project and need to add a symbolic link to a file it is installing via env.Install. What command(s) will make a link that's the equivalent of running ln -s on the command line?


Solution

  • SCons doesn't have a dedicated symbolic link command, but you can use os.symlink(src, dst) from Python's os module:

    import os
    env = Environment()
    def SymLink(target, source, env):
        os.symlink(os.path.abspath(str(source[0])), os.path.abspath(str(target[0])))
    env.Command("file.out", "file.in", SymLink)
    

    This may not work correctly on Windows, I've only tried it on Linux.