1 # customised version of 'waf dist' for Samba tools
2 # uses git ls-files to get file lists
4 import Utils, os, sys, tarfile, stat
5 from samba_utils import *
7 def add_tarfile(tar, fname, abspath):
8 '''add a file to the tarball'''
9 tinfo = tar.gettarinfo(name=abspath, arcname=fname)
15 tar.addfile(tinfo, fileobj=fh)
19 def dist(appname='', version=''):
21 if not appname: appname = Utils.g_module.APPNAME
22 if not version: version = Utils.g_module.VERSION
24 env = LOAD_ENVIRONMENT()
25 srcdir = os.path.normpath(os.path.join(os.path.dirname(Utils.g_module.root_path), Utils.g_module.srcdir))
28 print('You must use conf.DIST_DIRS() to set which directories to package')
32 print('You need git installed to run waf dist')
35 dist_base = '%s-%s' % (appname, version)
36 dist_name = '%s.tar.gz' % (dist_base)
38 tar = tarfile.open(dist_name, 'w:gz')
40 for dir in env.DIST_DIRS.split():
41 if dir.find(':') != -1:
42 destdir=dir.split(':')[1]
46 absdir = os.path.join(srcdir, dir)
47 git_cmd = [ env.GIT, 'ls-files', '--full-name', absdir ]
48 files = Utils.cmd_output(git_cmd).split()
50 abspath = os.path.join(srcdir, f)
55 fname = dist_base + '/' + f
56 add_tarfile(tar, fname, abspath)
60 print('Created %s' % dist_name)
64 def DIST_DIRS(conf, dirs):
65 '''set the directories to package, relative to top srcdir'''
66 if not conf.env.DIST_DIRS:
67 conf.env.DIST_DIRS = dirs