UNC path fixes

This commit is contained in:
Thomas Nagy 2017-03-02 20:45:01 +01:00
parent 14197b713f
commit e352fb05c0
No known key found for this signature in database
GPG Key ID: 49B4C67C05277AAA
5 changed files with 53 additions and 112 deletions

View File

@ -3,6 +3,7 @@ NEW IN WAF 2.0.0
* Provide a new priority system to improve scalability on complex builds
* Provide TaskGroup objects to improve scalability on complex builds
* Force new files into the build directory by default (use Node objects to bypass)
* Process support for building over UNC paths
* Simplify the Task class hierarchy; TaskBase is removed
* New ant_glob(..., generator=True) now returns a Python generator
* Accept nested lists and generators in bld(source=...)

View File

@ -3,12 +3,6 @@
import os, shutil
from waflib import Node, Build, Utils, Logs
def tt(msg, result, expected):
color = 'RED'
if result == expected:
color = 'GREEN'
Logs.pprint(color, msg.ljust(20) + " %r" % result)
def exists(path):
try:
os.stat(path)
@ -40,6 +34,15 @@ def configure(ctx):
def test(ctx):
bld = Build.BuildContext()
errors = []
def tt(msg, result, expected):
color = 'RED'
if result == expected:
color = 'GREEN'
else:
errors.append(result)
Logs.pprint(color, msg.ljust(20) + " %r" % result)
# 1. absdir is wrong, keep the drive letter
# 2. split should use os.sep
@ -119,7 +122,7 @@ def test(ctx):
nf.write("aha")
nf.get_bld_sig()
tt('find_resource src/abc', bld.srcnode.find_resource(['abc']), nf)
tt('find_or_declare src/abc', bld.srcnode.find_or_declare(['abc']), nf)
tt('find_or_declare src/abc', bld.srcnode.find_or_declare(['abc']), bld.bldnode.make_node(['abc']))
tt('src.get_bld()', bld.srcnode.get_bld(), bld.bldnode)
tt('bld.get_src()', bld.bldnode.get_src(), bld.srcnode)
@ -141,3 +144,35 @@ def test(ctx):
tt("ant_glob ->", len(bld.srcnode.ant_glob('*.txt', flat=False)), 1)
#print("ant_glob src ->", bld.srcnode.ant_glob('*.txt'))
def abspath(self):
try:
return self.cache_abspath
except AttributeError:
pass
if not self.parent:
val = ''
elif not self.parent.name:
val = self.name + '\\'
else:
val = self.parent.abspath().rstrip('\\') + '\\' + self.name
self.cache_abspath = val
return val
# the local class will be unused soon enough
old_abspath = bld.node_class.abspath
bld.node_class.abspath = abspath
unc1 = '\\\\computer\\share\\file'
lst = Utils.split_path_win32(unc1)
node = bld.root.make_node(lst)
tt('UNC head node', lst[0], '\\\\computer')
tt('UNC share path', node.abspath(), unc1)
unc2 = '\\\\?\\C:\\foo'
lst = Utils.split_path_win32(unc2)
node = bld.root.make_node(lst)
tt('UNC long path', node.abspath(), 'C:\\foo')
if errors:
bld.fatal('There are test failures ^^')

View File

@ -340,6 +340,11 @@ class Node(object):
if isinstance(lst, str):
lst = [x for x in Utils.split_path(lst) if x and x != '.']
if lst and lst[0].startswith('\\\\') and not self.parent:
node = self.ctx.root.make_node(lst[0])
node.cache_isdir = True
return node.find_node(lst[1:])
cur = self
for x in lst:
if x == '..':

View File

@ -461,14 +461,16 @@ def split_path_cygwin(path):
re_sp = re.compile('[/\\\\]+')
def split_path_win32(path):
if path.startswith('\\\\'):
ret = re_sp.split(path)[2:]
ret[0] = '\\' + ret[0]
ret = re_sp.split(path)[1:]
ret[0] = '\\\\' + ret[0]
if ret[0] == '\\\\?':
return ret[1:]
return ret
return re_sp.split(path)
msysroot = None
def split_path_msys(path):
if path.startswith(('/', '\\')) and not path.startswith(('\\', '\\\\')):
if path.startswith(('/', '\\')) and not path.startswith(('//', '\\\\')):
# msys paths can be in the form /usr/bin
global msysroot
if not msysroot:

View File

@ -1,102 +0,0 @@
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2014 (ita)
"""
This module enables automatic handling of network paths of the form \\server\share for both input
and output files. While a typical script may require the following::
import os
def build(bld):
node = bld.root.make_node('\\\\COMPUTER\\share\\test.txt')
# mark the server/share levels as folders
k = node.parent
while k:
k.cache_isdir = True
k = k.parent
# create the folder structure
if node.parent.height() > 2:
node.parent.mkdir()
# then the task generator
def myfun(tsk):
tsk.outputs[0].write("data")
bld(rule=myfun, source='wscript', target=[nd])
this tool will make the process much easier, for example::
def configure(conf):
conf.load('unc') # do not import the module directly
def build(bld):
def myfun(tsk):
tsk.outputs[0].write("data")
bld(rule=myfun, source='wscript', target='\\\\COMPUTER\\share\\test.txt')
bld(rule=myfun, source='\\\\COMPUTER\\share\\test.txt', target='\\\\COMPUTER\\share\\test2.txt')
"""
import os
from waflib import Node, Utils, Context
def find_resource(self, lst):
if isinstance(lst, str):
lst = [x for x in Utils.split_path(lst) if x and x != '.']
if lst[0].startswith('\\\\'):
if len(lst) < 3:
return None
node = self.ctx.root.make_node(lst[0]).make_node(lst[1])
node.cache_isdir = True
node.parent.cache_isdir = True
ret = node.search_node(lst[2:])
if not ret:
ret = node.find_node(lst[2:])
if ret and os.path.isdir(ret.abspath()):
return None
return ret
return self.find_resource_orig(lst)
def find_or_declare(self, lst):
if isinstance(lst, str):
lst = [x for x in Utils.split_path(lst) if x and x != '.']
if lst[0].startswith('\\\\'):
if len(lst) < 3:
return None
node = self.ctx.root.make_node(lst[0]).make_node(lst[1])
node.cache_isdir = True
node.parent.cache_isdir = True
ret = node.find_node(lst[2:])
if not ret:
ret = node.make_node(lst[2:])
if not os.path.isfile(ret.abspath()):
ret.parent.mkdir()
return ret
return self.find_or_declare_orig(lst)
def abspath(self):
"""For MAX_PATH limitations"""
ret = self.abspath_orig()
if not ret.startswith("\\"):
return "\\\\?\\" + ret
return ret
if Utils.is_win32:
Node.Node.find_resource_orig = Node.Node.find_resource
Node.Node.find_resource = find_resource
Node.Node.find_or_declare_orig = Node.Node.find_or_declare
Node.Node.find_or_declare = find_or_declare
Node.Node.abspath_orig = Node.Node.abspath
Node.Node.abspath = abspath
for k in list(Context.cache_modules.keys()):
Context.cache_modules["\\\\?\\" + k] = Context.cache_modules[k]