mirror of https://gitlab.com/ita1024/waf.git
UNC path fixes
This commit is contained in:
parent
14197b713f
commit
e352fb05c0
|
@ -3,6 +3,7 @@ NEW IN WAF 2.0.0
|
||||||
* Provide a new priority system to improve scalability on complex builds
|
* Provide a new priority system to improve scalability on complex builds
|
||||||
* Provide TaskGroup objects 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)
|
* 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
|
* Simplify the Task class hierarchy; TaskBase is removed
|
||||||
* New ant_glob(..., generator=True) now returns a Python generator
|
* New ant_glob(..., generator=True) now returns a Python generator
|
||||||
* Accept nested lists and generators in bld(source=...)
|
* Accept nested lists and generators in bld(source=...)
|
||||||
|
|
|
@ -3,12 +3,6 @@
|
||||||
import os, shutil
|
import os, shutil
|
||||||
from waflib import Node, Build, Utils, Logs
|
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):
|
def exists(path):
|
||||||
try:
|
try:
|
||||||
os.stat(path)
|
os.stat(path)
|
||||||
|
@ -40,6 +34,15 @@ def configure(ctx):
|
||||||
def test(ctx):
|
def test(ctx):
|
||||||
bld = Build.BuildContext()
|
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
|
# 1. absdir is wrong, keep the drive letter
|
||||||
# 2. split should use os.sep
|
# 2. split should use os.sep
|
||||||
|
@ -119,7 +122,7 @@ def test(ctx):
|
||||||
nf.write("aha")
|
nf.write("aha")
|
||||||
nf.get_bld_sig()
|
nf.get_bld_sig()
|
||||||
tt('find_resource src/abc', bld.srcnode.find_resource(['abc']), nf)
|
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('src.get_bld()', bld.srcnode.get_bld(), bld.bldnode)
|
||||||
tt('bld.get_src()', bld.bldnode.get_src(), bld.srcnode)
|
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)
|
tt("ant_glob ->", len(bld.srcnode.ant_glob('*.txt', flat=False)), 1)
|
||||||
#print("ant_glob src ->", bld.srcnode.ant_glob('*.txt'))
|
#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 ^^')
|
||||||
|
|
||||||
|
|
|
@ -340,6 +340,11 @@ class Node(object):
|
||||||
if isinstance(lst, str):
|
if isinstance(lst, str):
|
||||||
lst = [x for x in Utils.split_path(lst) if x and x != '.']
|
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
|
cur = self
|
||||||
for x in lst:
|
for x in lst:
|
||||||
if x == '..':
|
if x == '..':
|
||||||
|
|
|
@ -461,14 +461,16 @@ def split_path_cygwin(path):
|
||||||
re_sp = re.compile('[/\\\\]+')
|
re_sp = re.compile('[/\\\\]+')
|
||||||
def split_path_win32(path):
|
def split_path_win32(path):
|
||||||
if path.startswith('\\\\'):
|
if path.startswith('\\\\'):
|
||||||
ret = re_sp.split(path)[2:]
|
ret = re_sp.split(path)[1:]
|
||||||
ret[0] = '\\' + ret[0]
|
ret[0] = '\\\\' + ret[0]
|
||||||
|
if ret[0] == '\\\\?':
|
||||||
|
return ret[1:]
|
||||||
return ret
|
return ret
|
||||||
return re_sp.split(path)
|
return re_sp.split(path)
|
||||||
|
|
||||||
msysroot = None
|
msysroot = None
|
||||||
def split_path_msys(path):
|
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
|
# msys paths can be in the form /usr/bin
|
||||||
global msysroot
|
global msysroot
|
||||||
if not msysroot:
|
if not msysroot:
|
||||||
|
|
|
@ -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]
|
|
||||||
|
|
Loading…
Reference in New Issue