s4-waf: added 'waf dist' to build the tarball
authorAndrew Tridgell <tridge@samba.org>
Sat, 3 Apr 2010 23:57:33 +0000 (09:57 +1000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 6 Apr 2010 10:27:24 +0000 (20:27 +1000)
buildtools/wafsamba/samba_dist.py [new file with mode: 0644]
buildtools/wafsamba/wscript
lib/talloc/wscript
source4/wscript

diff --git a/buildtools/wafsamba/samba_dist.py b/buildtools/wafsamba/samba_dist.py
new file mode 100644 (file)
index 0000000..88268b5
--- /dev/null
@@ -0,0 +1,67 @@
+# customised version of 'waf dist' for Samba tools
+# uses git ls-files to get file lists
+
+import Utils, os, sys, tarfile, stat
+from samba_utils import *
+
+def add_tarfile(tar, fname, abspath):
+    '''add a file to the tarball'''
+    tinfo = tar.gettarinfo(name=abspath, arcname=fname)
+    tinfo.uid   = 0
+    tinfo.gid   = 0
+    tinfo.uname = 'root'
+    tinfo.gname = 'root'
+    fh = open(abspath)
+    tar.addfile(tinfo, fileobj=fh)
+    fh.close()
+
+
+def dist(appname='', version=''):
+
+    if not appname: appname = Utils.g_module.APPNAME
+    if not version: version = Utils.g_module.VERSION
+
+    env = LOAD_ENVIRONMENT()
+    srcdir = os.path.normpath(os.path.join(os.path.dirname(Utils.g_module.root_path), Utils.g_module.srcdir))
+
+    if not env.DIST_DIRS:
+        print('You must use conf.DIST_DIRS() to set which directories to package')
+        sys.exit(1)
+
+    if not env.GIT:
+        print('You need git installed to run waf dist')
+        sys.exit(1)
+
+    dist_base = '%s-%s' % (appname, version)
+    dist_name = '%s.tar.gz' % (dist_base)
+
+    tar = tarfile.open(dist_name, 'w:gz')
+
+    for dir in env.DIST_DIRS.split():
+        if dir.find(':') != -1:
+            destdir=dir.split(':')[1]
+            dir=dir.split(':')[0]
+        else:
+            destdir = '.'
+        absdir = os.path.join(srcdir, dir)
+        git_cmd = [ env.GIT, 'ls-files', '--full-name', absdir ]
+        files = Utils.cmd_output(git_cmd).split()
+        for f in files:
+            abspath = os.path.join(srcdir, f)
+            if dir != '.':
+                f = f[len(dir)+1:]
+            if destdir != '.':
+                f = destdir + '/' + f
+            fname = dist_base + '/' + f
+            add_tarfile(tar, fname, abspath)
+
+    tar.close()
+
+    print('Created %s' % dist_name)
+
+
+@conf
+def DIST_DIRS(conf, dirs):
+    '''set the directories to package, relative to top srcdir'''
+    if not conf.env.DIST_DIRS:
+        conf.env.DIST_DIRS = dirs
index 89046f578f806de61cbf4540952df8e7d027b4ac..9bef9b63b01531c089c25819243feea0369738a5 100644 (file)
@@ -76,6 +76,9 @@ def configure(conf):
 
     conf.check_tool('compiler_cc')
 
+    # we need git for 'waf dist'
+    conf.find_program('git', var='GIT')
+
     if Options.options.enable_gccdeps:
         # don't enable gccdeps by default as it needs a very recent version gcc
         conf.check_tool('gccdeps', tooldir=conf.srcdir + "/buildtools/wafsamba")
index e61d8344d6f1ef2391ff7a33e046cd6c27b830d7..4cc21c94d30b9b1a1f62d62595c48cb56ce0ea79 100644 (file)
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+APPNAME = 'talloc'
 VERSION = '2.0.2'
 
 srcdir = '../..'
@@ -9,7 +10,7 @@ LIBREPLACE_DIR= srcdir + '/lib/replace'
 
 import sys
 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
-import wafsamba
+import wafsamba, samba_dist
 
 def set_options(opt):
     opt.BUILTIN_DEFAULT('replace')
@@ -17,6 +18,7 @@ def set_options(opt):
     opt.recurse(LIBREPLACE_DIR)
 
 def configure(conf):
+    conf.DIST_DIRS('lib/talloc:. buildtools:buildtools')
     conf.sub_config(LIBREPLACE_DIR)
 
     if conf.CHECK_BUNDLED_SYSTEM('talloc', minversion=VERSION,
@@ -50,3 +52,8 @@ def build(bld):
         bld.env.TALLOC_VERSION = VERSION
         bld.PKG_CONFIG_FILES('talloc.pc', vnum=VERSION)
 
+
+def dist():
+    '''makes a tarball for distribution'''
+    samba_dist.dist()
+
index b0e2368547748ef9e98f7fce5540332920a84eaf..816093e293898af063d7e71a7440744cc2f8dead 100644 (file)
@@ -3,9 +3,12 @@
 srcdir = '..'
 blddir = 'bin'
 
+APPNAME='samba'
+VERSION='4.0.0-alpha13'
+
 import sys, os
 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
-import wafsamba, Options
+import wafsamba, Options, samba_dist
 
 # install in /usr/local/samba by default
 Options.default_prefix = '/usr/local/samba'
@@ -36,6 +39,7 @@ def configure(conf):
     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
     conf.DEFINE('_SAMBA_BUILD_', 4, add_to_cflags=True)
     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
+    conf.DIST_DIRS('.')
 
     if Options.options.developer:
         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
@@ -120,3 +124,9 @@ def wafdocs(ctx):
         cmd += ' --add-module %s' % f
     print "Running: %s" % cmd
     os.system(cmd)
+
+
+def dist():
+    '''makes a tarball for distribution'''
+    samba_dist.dist()
+