wafsamba/samba_utils.py: override symlink to allow force link
authorJoe Guo <joeg@catalyst.net.nz>
Tue, 12 Feb 2019 06:16:06 +0000 (19:16 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 13 Feb 2019 03:15:15 +0000 (04:15 +0100)
if bin is not empty and I have been sharing the samba tree into
a Vagrant environment and we run make, we get annoying linking error like this:

     File "~/samba/lib/tevent/wscript", line 130, in build
        installdir='python')
      File "./buildtools/wafsamba/wafsamba.py", line 745, in SAMBA_SCRIPT
        os.symlink(link_src, link_dst)
    FileExistsError: [Errno 17] File exists: '~/samba/lib/tevent/tevent.py' -> '~/samba/bin/default/../python/tevent.py'
    Makefile:7: recipe for target 'all' failed

Override the symlink method to allow force linking.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
buildtools/wafsamba/samba_utils.py
buildtools/wafsamba/wafsamba.py

index 93ce317f114504ddced550e8ad99884f01e17e8a..ad97de1859ba24c4afd5106b4f9694b0dc855643 100644 (file)
@@ -1,6 +1,7 @@
 # a waf tool to add autoconf-like macros to the configure section
 # and for SAMBA_ macros for building libraries, binaries etc
 
+import errno
 import os, sys, re, fnmatch, shlex, inspect
 from optparse import SUPPRESS_HELP
 from waflib import Build, Options, Utils, Task, Logs, Configure, Errors, Context
@@ -289,6 +290,18 @@ def recursive_dirlist(dir, relbase, pattern=None):
     return ret
 
 
+def symlink(src, dst, force=True):
+    """Can create symlink by force"""
+    try:
+        os.symlink(src, dst)
+    except OSError as exc:
+        if exc.errno == errno.EEXIST and force:
+            os.remove(dst)
+            os.symlink(src, dst)
+        else:
+            raise
+
+
 def mkdir_p(dir):
     '''like mkdir -p'''
     if not dir:
index 9d8251d60bf648e3958393f59f8779710efeb003..70ab736e2a78606133559a81846d7c1baa700c32 100644 (file)
@@ -10,6 +10,7 @@ TaskGen.task_gen.apply_verif = Utils.nada
 
 # bring in the other samba modules
 from samba_utils import *
+from samba_utils import symlink
 from samba_version import *
 from samba_autoconf import *
 from samba_patterns import *
@@ -61,7 +62,7 @@ def SAMBA_BUILD_ENV(conf):
     for (source, target) in [('shared', 'shared'), ('modules', 'modules'), ('python', 'python')]:
         link_target = os.path.join(conf.env.BUILD_DIRECTORY, 'default/' + target)
         if not os.path.lexists(link_target):
-            os.symlink('../' + source, link_target)
+            symlink('../' + source, link_target)
 
     # get perl to put the blib files in the build directory
     blib_bld = os.path.join(conf.env.BUILD_DIRECTORY, 'default/pidl/blib')
@@ -742,7 +743,7 @@ def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
         if os.path.exists(link_dst):
             os.unlink(link_dst)
         Logs.info("symlink: %s -> %s/%s" % (s, installdir, iname))
-        os.symlink(link_src, link_dst)
+        symlink(link_src, link_dst)
 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT