# customised version of 'waf dist' for Samba tools
# uses git ls-files to get file lists
-import Utils, os, sys, tarfile, gzip, stat, Scripting, Logs, Options
+import Utils, os, sys, tarfile, stat, Scripting, Logs, Options
from samba_utils import *
dist_dirs = None
+dist_files = None
dist_blacklist = ""
def add_symlink(tar, fname, abspath, basedir):
fh.close()
+def vcs_dir_contents(path):
+ """Return the versioned files under a path.
+
+ :return: List of paths relative to path
+ """
+ repo = path
+ while repo != "/":
+ if os.path.isdir(os.path.join(repo, ".git")):
+ ls_files_cmd = [ 'git', 'ls-files', '--full-name',
+ os_path_relpath(path, repo) ]
+ cwd = None
+ env = dict(os.environ)
+ env["GIT_DIR"] = os.path.join(repo, ".git")
+ break
+ elif os.path.isdir(os.path.join(repo, ".bzr")):
+ ls_files_cmd = [ 'bzr', 'ls', '--recursive', '--versioned',
+ os_path_relpath(path, repo)]
+ cwd = repo
+ env = None
+ break
+ repo = os.path.dirname(repo)
+ if repo == "/":
+ raise Exception("unsupported or no vcs for %s" % path)
+ return Utils.cmd_output(ls_files_cmd, cwd=cwd, env=env).split()
+
+
def dist(appname='',version=''):
+
+ def add_files_to_tarball(tar, srcdir, srcsubdir, dstdir, dstsubdir, blacklist, files):
+ if blacklist == None:
+ blacklist = []
+ for f in files:
+ abspath = os.path.join(srcdir, f)
+
+ if srcsubdir != '.':
+ f = f[len(srcsubdir)+1:]
+
+ # Remove files in the blacklist
+ if f in blacklist:
+ continue
+ blacklisted = False
+ # Remove directories in the blacklist
+ for d in blacklist:
+ if f.startswith(d):
+ blacklisted = True
+ if blacklisted:
+ continue
+ if os.path.isdir(abspath):
+ continue
+ if dstsubdir != '.':
+ f = dstsubdir + '/' + f
+ fname = dstdir + '/' + f
+ add_tarfile(tar, fname, abspath, srcsubdir)
+
+
if not isinstance(appname, str) or not appname:
# this copes with a mismatch in the calling arguments for dist()
appname = Utils.g_module.APPNAME
else:
destdir = '.'
absdir = os.path.join(srcdir, dir)
- if os.path.isdir(os.path.join(absdir, ".git")):
- ls_files_cmd = [ 'git', 'ls-files', '--full-name', absdir ]
- elif os.path.isdir(os.path.join(absdir, ".bzr")):
- ls_files_cmd = [ 'bzr', 'ls', '--from-root', '--recursive', '-d', absdir ]
- else:
- Logs.error('unknown or no vcs for %s' % absdir)
- sys.exit(1)
try:
- files = Utils.cmd_output(ls_files_cmd).split()
- except:
- Logs.error('command failed: %s' % ' '.join(ls_files_cmd))
+ files = vcs_dir_contents(absdir)
+ except Exception, e:
+ Logs.error('unable to get contents of %s: %s' % (absdir, e))
sys.exit(1)
- for f in files:
- abspath = os.path.join(srcdir, f)
- if dir != '.':
- f = f[len(dir)+1:]
+ add_files_to_tarball(tar, srcdir, dir, dist_base, destdir, blacklist, files)
- # Remove files in the blacklist
- if f in dist_blacklist:
- continue
- blacklisted = False
- # Remove directories in the blacklist
- for d in blacklist:
- if f.startswith(d):
- blacklisted = True
- if blacklisted:
- continue
- if os.path.isdir(abspath):
- continue
- if destdir != '.':
- f = destdir + '/' + f
- fname = dist_base + '/' + f
- add_tarfile(tar, fname, abspath, dir)
+ if dist_files:
+ for file in dist_files.split():
+ if file.find(':') != -1:
+ destfile = file.split(':')[1]
+ file = file.split(':')[0]
+ else:
+ destfile = file
+
+ absfile = os.path.join(srcdir, file)
+
+ if destfile != file:
+ file = destfile
+
+ fname = dist_base + '/' + file
+ add_tarfile(tar, fname, absfile, file)
tar.close()
if Options.options.SIGN_RELEASE:
+ import gzip
try:
os.unlink(dist_name + '.asc')
except OSError:
if not dist_dirs:
dist_dirs = dirs
+@conf
+def DIST_FILES(files):
+ '''set additional files for packaging, relative to top srcdir'''
+ global dist_files
+ if not dist_files:
+ dist_files = files
+
@conf
def DIST_BLACKLIST(blacklist):
'''set the files to exclude from packaging, relative to top srcdir'''