def _tar(env, name, source, **kw): """Core of the `Tar()`, `TarGz()` and `TarBz2()`""" import SCons.Util import platform target = TeXASCommon.get_auto_target(env, name, **kw) alias = TeXASCommon.get_auto_alias(name, 'alias', **kw) # Some paths are stripped from file names in the archive dirs2strip = TeXASCommon.get_strip_dirs(env, **kw) kw = _del_local_keywords(kw) if dirs2strip: kw['_dirs2strip'] = dirs2strip kw['_joinpathre'] = TeXASCommon.joinpathre if platform.system() == 'Windows': t = "--transform='s:^^\\(${_joinpathre(_dirs2strip)}\\)::S'" else: t = "--transform='s:^\\(${_joinpathre(_dirs2strip)}\\)::S'" flags = SCons.Util.CLVar(t) kw['TARFLAGS'] = TeXASCommon.append_flags(env, 'TARFLAGS', flags, **kw) target = env.Tar(target, source, **kw) if alias: env.Alias(alias, target) env.AlwaysBuild(alias) return target
def TarGz(env, name, source, **kw): """Create gzipped tar archive from source(s). This function creates gzipped TAR archive containing files listed in the ``source`` argument. The target file name may be fixed with the ``target`` argument. Otherwise, the ``out_dir``, ``name``, ``version`` and ``suffix`` are used to compose the target file path - the created archive file is ``[<out_dir>/]<name>[-<version>].tar.gz`` (``[]`` means optional part and ``<>`` stands for argument substitution). The target file extension might be changed with the ``suffix`` argument. The function also auto-generates the alias for this target, so user can build the archive with **scons <alias>**. To change the alias, provide an alternative with ``alias`` argument. If you don't wish the alias to be created at all, set ``alias=None``. Certain leading paths can be stripped out from file names during package creation. These paths are provided with the ``strip_dirs`` argument. :Parameters: env the SCons Environment object name package name (string) source source files to be included in the archive :Keywords: alias SCons alias for this target, if not provided the default alias ``<name>-tgz`` or ``<name>-<alias_suffix>`` is used, otherwise the alias is set to the value of this argument; to not create any alias set ``alias=None`` alias_suffix alias suffix to be used instead of the default ``tgz`` alias suffix out_dir output directory, where to create the archive strip_dirs directories to strip out from the paths of files in the archive, for example if ``source = ["sub1/foo.txt", "sub2/bar.txt", "sub3/geez.txt"]`` and ``strip_dirs = ["sub1", "sub3"]``, the resulting archive will contain files ``foo.txt``, ``sub2/bar.txt`` and ``geez.txt``, you may also set ``strip_dirs=True`` to strip out the current working directory suffix suffix for the target file, by default ``.tar.gz`` is used target target file name to use instead of the default auto-generated name version version of the package, used to generate the name of target file :Returns: a list of targets created (single target actually) """ kw['default_alias_suffix'] = 'tgz' kw['default_suffix'] = '.tar.gz' kw['TARFLAGS'] = TeXASCommon.append_flags(env, 'TARFLAGS', '-z', **kw) return _tar(env, name, source, **kw)