build: fixed a typo that prevented --bundled-libraries from working correctly
[samba.git] / buildtools / wafsamba / samba_dist.py
index b4a6cbb2405e1b8d9685b5b4792ceeeec73ae3a2..05865508149375c73107313dfe2d1167f2aac6e3 100644 (file)
@@ -1,14 +1,66 @@
 # customised version of 'waf dist' for Samba tools
 # uses git ls-files to get file lists
 
-import Utils, os, sys, tarfile, stat, Scripting
+import Utils, os, sys, tarfile, stat, Scripting, Logs
 from samba_utils import *
 
 dist_dirs = None
 
-def add_tarfile(tar, fname, abspath):
-    '''add a file to the tarball'''
+def add_symlink(tar, fname, abspath, basedir):
+    '''handle symlinks to directories that may move during packaging'''
+    if not os.path.islink(abspath):
+        return False
     tinfo = tar.gettarinfo(name=abspath, arcname=fname)
+    tgt = os.readlink(abspath)
+
+    if dist_dirs:
+        # we need to find the target relative to the main directory
+        # this is here to cope with symlinks into the buildtools
+        # directory from within the standalone libraries in Samba. For example,
+        # a symlink to ../../builtools/scripts/autogen-waf.sh needs
+        # to be rewritten as a symlink to buildtools/scripts/autogen-waf.sh
+        # when the tarball for talloc is built
+
+        # the filename without the appname-version
+        rel_fname = '/'.join(fname.split('/')[1:])
+
+        # join this with the symlink target
+        tgt_full = os.path.join(os.path.dirname(rel_fname), tgt)
+
+        # join with the base directory
+        tgt_base = os.path.normpath(os.path.join(basedir, tgt_full))
+
+        # see if this is inside one of our dist_dirs
+        for dir in dist_dirs.split():
+            if dir.find(':') != -1:
+                destdir=dir.split(':')[1]
+                dir=dir.split(':')[0]
+            else:
+                destdir = '.'
+            if dir == basedir:
+                # internal links don't get rewritten
+                continue
+            if dir == tgt_base[0:len(dir)] and tgt_base[len(dir)] == '/':
+                new_tgt = destdir + tgt_base[len(dir):]
+                tinfo.linkname = new_tgt
+                break
+
+    tinfo.uid   = 0
+    tinfo.gid   = 0
+    tinfo.uname = 'root'
+    tinfo.gname = 'root'
+    tar.addfile(tinfo)
+    return True
+
+def add_tarfile(tar, fname, abspath, basedir):
+    '''add a file to the tarball'''
+    if add_symlink(tar, fname, abspath, basedir):
+        return
+    try:
+        tinfo = tar.gettarinfo(name=abspath, arcname=fname)
+    except OSError:
+        Logs.error('Unable to find file %s - missing from git checkout?' % abspath)
+        sys.exit(1)
     tinfo.uid   = 0
     tinfo.gid   = 0
     tinfo.uname = 'root'
@@ -29,7 +81,7 @@ def dist(appname='',version=''):
     srcdir = os.path.normpath(os.path.join(os.path.dirname(Utils.g_module.root_path), Utils.g_module.srcdir))
 
     if not dist_dirs:
-        print('You must use samba_dist.DIST_DIRS() to set which directories to package')
+        Logs.error('You must use samba_dist.DIST_DIRS() to set which directories to package')
         sys.exit(1)
 
     dist_base = '%s-%s' % (appname, version)
@@ -48,7 +100,7 @@ def dist(appname='',version=''):
         try:
             files = Utils.cmd_output(git_cmd).split()
         except:
-            print('git command failed: %s' % ' '.join(git_cmd))
+            Logs.error('git command failed: %s' % ' '.join(git_cmd))
             sys.exit(1)
         for f in files:
             abspath = os.path.join(srcdir, f)
@@ -57,11 +109,11 @@ def dist(appname='',version=''):
             if destdir != '.':
                 f = destdir + '/' + f
             fname = dist_base + '/' + f
-            add_tarfile(tar, fname, abspath)
+            add_tarfile(tar, fname, abspath, dir)
 
     tar.close()
 
-    print('Created %s' % dist_name)
+    Logs.info('Created %s' % dist_name)
     return dist_name