build: Remove workaround for missing os.path.relpath in Python < 2.6
authorAndrew Bartlett <abartlet@samba.org>
Mon, 4 Nov 2019 04:07:44 +0000 (17:07 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 13 Nov 2019 08:42:30 +0000 (08:42 +0000)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: David Mulder <dmulder@suse.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
13 files changed:
buildtools/wafsamba/samba3.py
buildtools/wafsamba/samba_autoproto.py
buildtools/wafsamba/samba_deps.py
buildtools/wafsamba/samba_dist.py
buildtools/wafsamba/samba_headers.py
buildtools/wafsamba/samba_utils.py
buildtools/wafsamba/samba_wildcard.py
buildtools/wafsamba/symbols.py
buildtools/wafsamba/wafsamba.py
buildtools/wafsamba/wscript
ctdb/wscript
dynconfig/wscript
testsuite/headers/wscript_build

index 5aab2509b2490ae1ac65afb90314e1b6db1c347e..818bfc041c5bd7aa1e16ef91e992ae32d1e12c48 100644 (file)
@@ -3,7 +3,7 @@
 
 import os
 from waflib import Build
-from samba_utils import os_path_relpath, TO_LIST
+from samba_utils import TO_LIST
 from samba_autoconf import library_flags
 
 def SAMBA3_IS_STATIC_MODULE(bld, module):
@@ -31,7 +31,7 @@ def s3_fix_kwargs(bld, kwargs):
     '''fix the build arguments for s3 build rules to include the
     necessary includes, subdir and cflags options '''
     s3dir = os.path.join(bld.env.srcdir, 'source3')
-    s3reldir = os_path_relpath(s3dir, bld.path.abspath())
+    s3reldir = os.path.relpath(s3dir, bld.path.abspath())
 
     # the extra_includes list is relative to the source3 directory
     extra_includes = [ '.', 'include', 'lib' ]
index ace434f3c6bdf77526af24bae2c3b654f81f328f..87fb8ef25c57c75e945864028f20fe1a3ee06f8a 100644 (file)
@@ -2,12 +2,12 @@
 
 import os
 from waflib import Build
-from samba_utils import SET_TARGET_TYPE, os_path_relpath
+from samba_utils import SET_TARGET_TYPE
 
 def SAMBA_AUTOPROTO(bld, header, source):
     '''rule for samba prototype generation'''
     bld.SET_BUILD_GROUP('prototypes')
-    relpath = os_path_relpath(bld.path.abspath(), bld.srcnode.abspath())
+    relpath = os.path.relpath(bld.path.abspath(), bld.srcnode.abspath())
     name = os.path.join(relpath, header)
     SET_TARGET_TYPE(bld, name, 'PROTOTYPE')
     t = bld(
index f400e1833a2c539ec836637540dfe5f4a68a1f11..29bebc349c4264154c1a4f609ad2bf6dfbb1d267 100644 (file)
@@ -8,7 +8,7 @@ from waflib.Configure import conf
 from waflib import ConfigSet
 
 from samba_bundled import BUILTIN_LIBRARY
-from samba_utils import LOCAL_CACHE, TO_LIST, get_tgt_list, unique_list, os_path_relpath
+from samba_utils import LOCAL_CACHE, TO_LIST, get_tgt_list, unique_list
 from samba_autoconf import library_flags
 
 @conf
@@ -172,7 +172,7 @@ def build_includes(self):
 
     mypath = self.path.abspath(bld.env)
     for inc in inc_abs:
-        relpath = os_path_relpath(inc, mypath)
+        relpath = os.path.relpath(inc, mypath)
         includes.append(relpath)
 
     if getattr(self, 'local_include', True) and not getattr(self, 'local_include_first', True):
@@ -188,7 +188,7 @@ def build_includes(self):
             includes_top.append(i)
             continue
         absinc = os.path.join(self.path.abspath(), i)
-        relinc = os_path_relpath(absinc, self.bld.srcnode.abspath())
+        relinc = os.path.relpath(absinc, self.bld.srcnode.abspath())
         includes_top.append('#' + relinc)
 
     self.includes = unique_list(includes_top)
@@ -267,7 +267,7 @@ def check_duplicate_sources(bld, tgt_list):
 
     for t in tgt_list:
         source_list = TO_LIST(getattr(t, 'source', ''))
-        tpath = os.path.normpath(os_path_relpath(t.path.abspath(bld.env), t.env.BUILD_DIRECTORY + '/default'))
+        tpath = os.path.normpath(os.path.relpath(t.path.abspath(bld.env), t.env.BUILD_DIRECTORY + '/default'))
         obj_sources = set()
         for s in source_list:
             if not isinstance(s, str):
index 6af7bb4eaff7cca61e933a7cff6f0518005c9181..c211a94d3db3f65ada08aa1c431f5015e7c2b669 100644 (file)
@@ -4,7 +4,7 @@
 import os, sys, tarfile
 from waflib import Utils, Scripting, Logs, Options
 from waflib.Configure import conf
-from samba_utils import os_path_relpath, get_string
+from samba_utils import get_string
 from waflib import Context
 
 dist_dirs = None
@@ -111,7 +111,7 @@ def vcs_dir_contents(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) ]
+                             os.path.relpath(path, repo) ]
             cwd = None
             env = dict(os.environ)
             env["GIT_DIR"] = os.path.join(repo, ".git")
index a268c011c5d8e406e0d763554c55668cfb5388bc..3313960f5f833a82918b6893d498d2af261edab4 100644 (file)
@@ -2,7 +2,7 @@
 
 import os, re, sys, fnmatch
 from waflib import Build, Logs, Utils, Errors
-from samba_utils import TO_LIST, os_path_relpath
+from samba_utils import TO_LIST
 
 
 def header_install_path(header, header_path):
@@ -42,7 +42,7 @@ def create_public_header(task):
     if os.path.exists(tgt):
         os.unlink(tgt)
 
-    relsrc = os_path_relpath(src, task.env.TOPDIR)
+    relsrc = os.path.relpath(src, task.env.TOPDIR)
 
     infile  = open(src, mode='r')
     outfile = open(tgt, mode='w')
@@ -149,8 +149,8 @@ def PUBLIC_HEADERS(bld, public_headers, header_path=None, public_headers_install
             h_name =  h
             inst_name = os.path.basename(h)
         curdir = bld.path.abspath()
-        relpath1 = os_path_relpath(bld.srcnode.abspath(), curdir)
-        relpath2 = os_path_relpath(curdir, bld.srcnode.abspath())
+        relpath1 = os.path.relpath(bld.srcnode.abspath(), curdir)
+        relpath2 = os.path.relpath(curdir, bld.srcnode.abspath())
         targetdir = os.path.normpath(os.path.join(relpath1, bld.env.build_public_headers, inst_path))
         if not os.path.exists(os.path.join(curdir, targetdir)):
             raise Errors.WafError("missing source directory %s for public header %s" % (targetdir, inst_name))
index ad97de1859ba24c4afd5106b4f9694b0dc855643..4a5a34abae7a7aa561d6167e232bbb5697d5d961 100644 (file)
@@ -205,24 +205,6 @@ def process_depends_on(self):
                   self.includes += " " + y.more_includes
 
 
-os_path_relpath = getattr(os.path, 'relpath', None)
-if os_path_relpath is None:
-    # Python < 2.6 does not have os.path.relpath, provide a replacement
-    # (imported from Python2.6.5~rc2)
-    def os_path_relpath(path, start):
-        """Return a relative version of a path"""
-        start_list = os.path.abspath(start).split("/")
-        path_list = os.path.abspath(path).split("/")
-
-        # Work out how much of the filepath is shared by start and path.
-        i = len(os.path.commonprefix([start_list, path_list]))
-
-        rel_list = ['..'] * (len(start_list)-i) + path_list[i:]
-        if not rel_list:
-            return start
-        return os.path.join(*rel_list)
-
-
 def unique_list(seq):
     '''return a uniquified list in the same order as the existing list'''
     seen = {}
@@ -286,7 +268,7 @@ def recursive_dirlist(dir, relbase, pattern=None):
         else:
             if pattern and not fnmatch.fnmatch(f, pattern):
                 continue
-            ret.append(os_path_relpath(f2, relbase))
+            ret.append(os.path.relpath(f2, relbase))
     return ret
 
 
@@ -476,7 +458,7 @@ def RECURSE(ctx, directory):
         # already done it
         return
     visited_dirs.add(key)
-    relpath = os_path_relpath(abspath, ctx.path.abspath())
+    relpath = os.path.relpath(abspath, ctx.path.abspath())
     if ctxclass in ['tmp', 'OptionsContext', 'ConfigurationContext', 'BuildContext']:
         return ctx.recurse(relpath)
     if 'waflib.extras.compat15' in sys.modules:
index 6173ce8a9f9ac6db0ce5bb21b72ff3fe2faf4838..5d85ec0f2ac9a15f49a7237f8e4a6320769c6b77 100644 (file)
@@ -3,7 +3,7 @@
 import os, datetime, fnmatch
 from waflib import Scripting, Utils, Options, Logs, Errors
 from waflib import ConfigSet, Context
-from samba_utils import LOCAL_CACHE, os_path_relpath
+from samba_utils import LOCAL_CACHE
 
 def run_task(t, k):
     '''run a single build task'''
@@ -24,7 +24,7 @@ def run_named_build_task(cmd):
 
     # cope with builds of bin/*/*
     if os.path.islink(cmd):
-        cmd = os_path_relpath(os.readlink(cmd), os.getcwd())
+        cmd = os.path.relpath(os.readlink(cmd), os.getcwd())
 
     if cmd[0:12] == "bin/default/":
         cmd = cmd[12:]
index 3eca3d46bd71cf0780b3c8e36a26b96bd3aa3b83..d3bf9ac1c6b72c35c4694cb43a937d76d928c708 100644 (file)
@@ -4,7 +4,7 @@
 import os, re, subprocess
 from waflib import Utils, Build, Options, Logs, Errors
 from waflib.Logs import debug
-from samba_utils import TO_LIST, LOCAL_CACHE, get_tgt_list, os_path_relpath
+from samba_utils import TO_LIST, LOCAL_CACHE, get_tgt_list
 
 # these are the data structures used in symbols.py:
 #
@@ -617,7 +617,7 @@ def symbols_dupcheck(task, fail_on_error=False):
     build_library_dict(bld, tgt_list)
     for t in tgt_list:
         if t.samba_type == 'BINARY':
-            binname = os_path_relpath(t.link_task.outputs[0].abspath(bld.env), os.getcwd())
+            binname = os.path.relpath(t.link_task.outputs[0].abspath(bld.env), os.getcwd())
             symbols_dupcheck_binary(bld, binname, fail_on_error)
 
 
index 205d5b4ac32c81e01831849a4b66a9314f2e016d..48e564934898a8b2892cdde7b190d19661205eb3 100644 (file)
@@ -858,7 +858,7 @@ def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
     if trim_path:
         files2 = []
         for f in files:
-            files2.append(os_path_relpath(f, trim_path))
+            files2.append(os.path.relpath(f, trim_path))
         files = files2
 
     if exclude:
index 8d0a89a0ee3dc316d2ff5a350da02ec1aecae669..b601dd2596dc4ae3c5181371d4edd327c8c0c826 100644 (file)
@@ -5,7 +5,6 @@
 import os, sys
 from waflib import Configure, Logs, Options, Utils, Context, Errors
 import wafsamba
-from samba_utils import os_path_relpath
 from samba_utils import symlink
 from optparse import SUPPRESS_HELP
 
@@ -612,7 +611,7 @@ def build(bld):
     # give a more useful message if the source directory has moved
     curdir = bld.path.abspath()
     srcdir = bld.srcnode.abspath()
-    relpath = os_path_relpath(curdir, srcdir)
+    relpath = os.path.relpath(curdir, srcdir)
     if relpath.find('../') != -1:
         Logs.error('bld.path %s is not a child of %s' % (curdir, srcdir))
         raise Errors.WafError('''The top source directory has moved. Please run distclean and reconfigure''')
index daf3e1e9b2bba8721e20b85a88ad377ff9ce8983..dae25e725dce11640c7945ea20a5e5af0f8f51b0 100644 (file)
@@ -769,7 +769,7 @@ def build(bld):
                 continue
             mode = os.lstat(fl).st_mode & MODE_777
             if arg['trim_path']:
-                fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
+                fl = samba_utils.os.path.relpath(fl, arg['trim_path'])
             arg['file_list'].append([fl, mode])
 
     def SUBDIR_MODE(path, trim_path=None):
index 440ecd7f1b4a547b6e61165d1a4093cea07b7768..f455699f06291bc14352b485d68c62b171fa9082 100644 (file)
@@ -5,7 +5,7 @@ import os
 import optparse
 import textwrap
 from waflib import Logs, Errors, Options, Build, Context
-from samba_utils import EXPAND_VARIABLES, os_path_relpath
+from samba_utils import EXPAND_VARIABLES
 
 class SambaIndentedHelpFormatter (optparse.IndentedHelpFormatter):
     """Format help with indented section bodies.
@@ -425,7 +425,7 @@ def build(bld):
     bld.SAMBA_SUBSYSTEM('DYNCONFIG',
                         'dynconfig.c',
                         deps='replace',
-                        public_headers=os_path_relpath(os.path.join(Context.launch_dir, version_header), bld.path.abspath()),
+                        public_headers=os.path.relpath(os.path.join(Context.launch_dir, version_header), bld.path.abspath()),
                         header_path='samba',
                         cflags=cflags)
 
index 477a977e11bb33c333176201f8eb51eefd0346af..190fe69681057a2219b2c4c2cce04549e27436cc 100644 (file)
@@ -1,5 +1,4 @@
 import os
-from samba_utils import os_path_relpath
 
 def build_test_headers(task):
     '''symlink a header in the build tree'''
@@ -13,7 +12,7 @@ def build_test_headers(task):
         f.write('#include "%s"\n' % os.path.normpath(h))
     f.close()
 
-relpath1 = os_path_relpath(bld.srcnode.abspath(), bld.path.abspath())
+relpath1 = os.path.relpath(bld.srcnode.abspath(), bld.path.abspath())
 public_headers = []
 for h in bld.env.public_headers_list:
     public_headers.append(os.path.join(relpath1, bld.env.build_public_headers, h))