Archives

SCons provides Builder objects for creating two different types of archive files.

The Tar Builder

The Tar Builder object uses the tar utility to create archives of files and/or directory trees:

        env = Environment()
        env.Tar('out1.tar', ['file1', 'file2'])
        env.Tar('out2', 'directory')
      

        % scons .
        tar -c -f out1.tar file1 file2
        tar -c -f out2.tar directory
      

One common requirement when creating a tar archive is to create a compressed archive using the -z option. This is easily handled by specifying the value of the TARFLAGS variable when you create the construction environment. Note, however, that the -c used to to instruct tar to create the archive is part of the default value of TARFLAGS, so you need to set it both options:

        env = Environment(TARFLAGS = '-c -z')
        env.Tar('out.tar.gz', 'directory')
      

        % scons .
        tar -c -z -f out.tar.gz directory
      

you may also wish to set the value of the TARSUFFIX construction variable to your desired suffix for compress tar archives, so that SCons can append it to the target file name without your having to specify it explicitly:

        env = Environment(TARFLAGS = '-c -z',
                          TARSUFFIX = '.tgz')
        env.Tar('out', 'directory')
      

        % scons .
        tar -c -z -f out.tgz directory
      

The Zip Builder

The Zip Builder object creates archives of files and/or directory trees in the ZIP file format. Python versions 1.6 or later contain an internal zipfile module that SCons will use. In this case, given the following SConstruct file:

        env = Environment()
        env.Zip('out', ['file1', 'file2'])
      

Your output will reflect the fact that an internal Python function is being used to create the output ZIP archive:

        % scons .
        zip("out.zip", ["file1", "file2"])
      

If you're using Python version 1.5.2 to run SCons, then SCons will try to use an external zip program as follows:

        % scons .
        zip /home/my/project/zip.out file1 file2