mirror of
https://git.rtems.org/rtems-source-builder
synced 2024-10-09 07:15:10 +08:00
Windows fixes to build with MSYS2.
The path handling has been cleaned up and support for file names longer than 256 characters.
This commit is contained in:
parent
dbb78dc854
commit
a84249d261
@ -26,6 +26,7 @@
|
|||||||
import log
|
import log
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import stat
|
||||||
import string
|
import string
|
||||||
|
|
||||||
import error
|
import error
|
||||||
@ -36,17 +37,25 @@ def host(path):
|
|||||||
if path is not None:
|
if path is not None:
|
||||||
while '//' in path:
|
while '//' in path:
|
||||||
path = path.replace('//', '/')
|
path = path.replace('//', '/')
|
||||||
if windows and len(path) > 2:
|
if windows:
|
||||||
if path[0] == '/' and path[2] == '/' and \
|
if len(path) > 2 and \
|
||||||
|
path[0] == '/' and path[2] == '/' and \
|
||||||
(path[1] in string.ascii_lowercase or \
|
(path[1] in string.ascii_lowercase or \
|
||||||
path[1] in string.ascii_uppercase):
|
path[1] in string.ascii_uppercase):
|
||||||
path = ('%s:%s' % (path[1], path[2:])).replace('/', '\\')
|
path = '%s:%s' % (path[1], path[2:])
|
||||||
|
path = path.replace('/', '\\')
|
||||||
|
if not path.startswith('\\\\?\\') and len(path) > 254:
|
||||||
|
path = '\\\\?\\' + path
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def shell(path):
|
def shell(path):
|
||||||
if path is not None:
|
if path is not None:
|
||||||
if windows and len(path) > 1 and path[1] == ':':
|
if windows:
|
||||||
path = ('/%s%s' % (path[0], path[2:])).replace('\\', '/')
|
if path.startswith('\\\\?\\'):
|
||||||
|
path = path[4:]
|
||||||
|
if len(path) > 1 and path[1] == ':':
|
||||||
|
path = '/%s%s' % (path[0], path[2:])
|
||||||
|
path = path.replace('\\', '/')
|
||||||
while '//' in path:
|
while '//' in path:
|
||||||
path = path.replace('//', '/')
|
path = path.replace('//', '/')
|
||||||
return path
|
return path
|
||||||
@ -125,22 +134,26 @@ def mkdir(path):
|
|||||||
raise error.general('cannot make directory: %s' % (path))
|
raise error.general('cannot make directory: %s' % (path))
|
||||||
|
|
||||||
def removeall(path):
|
def removeall(path):
|
||||||
|
#
|
||||||
def _onerror(function, path, excinfo):
|
# Perform the removal of the directory tree manually so we can
|
||||||
import stat
|
# make sure on Windows the files and correctly encoded to avoid
|
||||||
if windows:
|
# the size limit.
|
||||||
path = "\\\\?\\" + path
|
#
|
||||||
if not os.access(path, os.W_OK):
|
|
||||||
# Is the error an access error ?
|
|
||||||
os.chmod(path, stat.S_IWUSR)
|
|
||||||
function(path)
|
|
||||||
else:
|
|
||||||
print 'removeall error: %s' % (path)
|
|
||||||
raise
|
|
||||||
|
|
||||||
path = host(path)
|
path = host(path)
|
||||||
shutil.rmtree(path, onerror = _onerror)
|
for root, dirs, files in os.walk(path, topdown = False):
|
||||||
return
|
for name in files:
|
||||||
|
file = host(os.path.join(root, name))
|
||||||
|
if not os.access(file, os.W_OK):
|
||||||
|
os.chmod(file, stat.S_IWUSR)
|
||||||
|
os.unlink(file)
|
||||||
|
for name in dirs:
|
||||||
|
dir = host(os.path.join(root, name))
|
||||||
|
if not os.access(dir, os.W_OK):
|
||||||
|
os.chmod(dir, stat.S_IWUSR)
|
||||||
|
os.rmdir(dir)
|
||||||
|
if not os.access(path, os.W_OK):
|
||||||
|
os.chmod(path, stat.S_IWUSR)
|
||||||
|
os.rmdir(path)
|
||||||
|
|
||||||
def expand(name, paths):
|
def expand(name, paths):
|
||||||
l = []
|
l = []
|
||||||
@ -173,8 +186,8 @@ def copy_tree(src, dst):
|
|||||||
os.makedirs(hdst)
|
os.makedirs(hdst)
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
srcname = os.path.join(hsrc, name)
|
srcname = host(os.path.join(hsrc, name))
|
||||||
dstname = os.path.join(hdst, name)
|
dstname = host(os.path.join(hdst, name))
|
||||||
try:
|
try:
|
||||||
if os.path.islink(srcname):
|
if os.path.islink(srcname):
|
||||||
linkto = os.readlink(srcname)
|
linkto = os.readlink(srcname)
|
||||||
@ -182,7 +195,7 @@ def copy_tree(src, dst):
|
|||||||
if os.path.islink(dstname):
|
if os.path.islink(dstname):
|
||||||
dstlinkto = os.readlink(dstname)
|
dstlinkto = os.readlink(dstname)
|
||||||
if linkto != dstlinkto:
|
if linkto != dstlinkto:
|
||||||
log.warning('copying tree: update of link does not match: %s -> %s' % \
|
log.warning('copying tree: link does not match: %s -> %s' % \
|
||||||
(dstname, dstlinkto))
|
(dstname, dstlinkto))
|
||||||
os.remove(dstname)
|
os.remove(dstname)
|
||||||
else:
|
else:
|
||||||
@ -194,10 +207,7 @@ def copy_tree(src, dst):
|
|||||||
elif os.path.isdir(srcname):
|
elif os.path.isdir(srcname):
|
||||||
copy_tree(srcname, dstname)
|
copy_tree(srcname, dstname)
|
||||||
else:
|
else:
|
||||||
if windows:
|
shutil.copy2(host(srcname), host(dstname))
|
||||||
shutil.copy2("\\\\?\\" + srcname, dstname)
|
|
||||||
else:
|
|
||||||
shutil.copy2(srcname, dstname)
|
|
||||||
except shutil.Error, err:
|
except shutil.Error, err:
|
||||||
raise error.general('copying tree: %s -> %s: %s' % \
|
raise error.general('copying tree: %s -> %s: %s' % \
|
||||||
(hsrc, hdst, str(err)))
|
(hsrc, hdst, str(err)))
|
||||||
@ -227,4 +237,4 @@ if __name__ == '__main__':
|
|||||||
print shell('w:/x/y/z')
|
print shell('w:/x/y/z')
|
||||||
print basename('x:/sd/df/fg/me.txt')
|
print basename('x:/sd/df/fg/me.txt')
|
||||||
print dirname('x:/sd/df/fg/me.txt')
|
print dirname('x:/sd/df/fg/me.txt')
|
||||||
print join('s:/d/', '/g', '/tyty/fgfg')
|
print join('s:/d/e\\f/g', '/h', '/tyty/zxzx', '\\mm\\nn/p')
|
||||||
|
@ -67,6 +67,9 @@ def load():
|
|||||||
else:
|
else:
|
||||||
ncpus = '1'
|
ncpus = '1'
|
||||||
|
|
||||||
|
if os.environ.has_key('MSYSTEM'):
|
||||||
|
os.environ.pop('NUMBER_OF_PROCESSORS')
|
||||||
|
|
||||||
version = uname[2]
|
version = uname[2]
|
||||||
defines = {
|
defines = {
|
||||||
'_ncpus': ('none', 'none', ncpus),
|
'_ncpus': ('none', 'none', ncpus),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user