mirror of https://github.com/KLayout/klayout.git
Fix Mac OS build scripts to work with both Python 2 and Python 3
This commit is contained in:
parent
0945f7c914
commit
bdb7a7af2c
|
|
@ -18,6 +18,12 @@ import string
|
|||
import subprocess
|
||||
import shutil
|
||||
|
||||
try:
|
||||
from pathlib import Path
|
||||
Path('~').expanduser()
|
||||
except (ImportError,AttributeError): # python2
|
||||
from pathlib2 import Path
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
## To import global dictionaries of different modules
|
||||
#-------------------------------------------------------------------------------
|
||||
|
|
@ -175,6 +181,7 @@ def SetChangeLibIdentificationName( executable, relativedir ):
|
|||
|
||||
def WalkLibDependencyTree( dylibPath, depth=0, filter_regex=r'\t+/usr/local/opt'):
|
||||
NOTHINGTODO = [] # return empty list if nothing to do.
|
||||
dylibPath = str(Path(dylibPath))
|
||||
cmdNameId = XcodeToolChain['nameID']
|
||||
cmdNameChg = XcodeToolChain['nameCH']
|
||||
otoolCm = 'otool -L %s | grep -E "%s"' % (dylibPath, filter_regex)
|
||||
|
|
@ -186,7 +193,7 @@ def WalkLibDependencyTree( dylibPath, depth=0, filter_regex=r'\t+/usr/local/opt'
|
|||
if depth < 5:
|
||||
if len(deplibs) > 0:
|
||||
for idx, lib in enumerate(deplibs):
|
||||
lib = str(lib)
|
||||
lib = str(Path(lib))
|
||||
if lib != list(keys)[0]:
|
||||
deplibs[idx] = WalkLibDependencyTree(lib, depth+1, filter_regex)
|
||||
if depth == 0:
|
||||
|
|
@ -205,6 +212,7 @@ def WalkFrameworkPaths(frameworkPaths, filter_regex=r'\.(so|dylib)$', search_pat
|
|||
dependency_dict = dict()
|
||||
|
||||
for frameworkPath in frameworkPathsIter:
|
||||
frameworkPath = str(Path(frameworkPath))
|
||||
# print("Calling:", 'find %s -type f | grep -E "%s"' % (frameworkPath, filter_regex))
|
||||
find_grep_results = os.popen('find %s -type f | grep -E "%s"' % (frameworkPath, filter_regex)).read().split('\n')
|
||||
framework_files = filter(lambda x: x != '',
|
||||
|
|
@ -231,7 +239,7 @@ def WalkDictTree(dependencyDict, visited_files):
|
|||
if deplib not in visited_files:
|
||||
visited_files.append(deplib)
|
||||
elif isinstance(deplib, dict):
|
||||
dependency_list.append(next(iter(deplib)))
|
||||
dependency_list.append(str(next(iter(deplib))))
|
||||
libNameChanges.extend(WalkDictTree(deplib, visited_files))
|
||||
else:
|
||||
#raise RuntimeError("Unexpected value: %s" % deplib)
|
||||
|
|
@ -245,13 +253,16 @@ def WalkDictTree(dependencyDict, visited_files):
|
|||
visited_files.append(lib)
|
||||
return libNameChanges
|
||||
|
||||
|
||||
def FindFramework(path, root_path):
|
||||
relPath = os.path.relpath(path, root_path)
|
||||
return os.path.join(root_path, relPath.split(os.sep)[0])
|
||||
path = Path(path)
|
||||
root_path = Path(root_path)
|
||||
relPath = path.relative_to(root_path)
|
||||
return str(root_path / relPath.parts[0])
|
||||
|
||||
def ResolveExecutablePath(path, executable_path):
|
||||
""" Transforms @executable_path into executable_path"""
|
||||
p = path.replace("@executable_path", "/%s/" % executable_path)
|
||||
executable_path = str(executable_path)
|
||||
p = Path(str(path).replace("@executable_path", "/%s/" % executable_path))
|
||||
return p
|
||||
|
||||
def DetectChanges(frameworkDependencyDict):
|
||||
|
|
@ -278,8 +289,11 @@ def PerformChanges(frameworkDependencyDict, replaceFromToPairs=None, executable_
|
|||
except StopIteration:
|
||||
dependencies = list()
|
||||
for replaceFrom, replaceTo, libdir in replaceFromToPairs:
|
||||
replaceFrom = str(Path(replaceFrom))
|
||||
replaceTo = str(Path(replaceTo))
|
||||
|
||||
fileName = ResolveExecutablePath(lib.replace(replaceFrom, replaceTo), executable_path)
|
||||
if fileName.startswith('/usr'):
|
||||
if str(fileName).startswith('/usr'):
|
||||
# print(f'skipping fileName: {fileName}')
|
||||
continue
|
||||
|
||||
|
|
@ -291,14 +305,14 @@ def PerformChanges(frameworkDependencyDict, replaceFromToPairs=None, executable_
|
|||
destFrameworkPath = frameworkPath.replace(replaceFrom, replaceTo)
|
||||
destFrameworkPath = ResolveExecutablePath(destFrameworkPath, executable_path)
|
||||
|
||||
if not os.path.exists(fileName):
|
||||
if not fileName.exists():
|
||||
print (lib.replace(replaceFrom, replaceTo), "DOES NOT EXIST")
|
||||
print ("COPY", frameworkPath, " -> ", destFrameworkPath)
|
||||
shutil.copytree(frameworkPath, destFrameworkPath)
|
||||
shutil.copytree(frameworkPath, str(destFrameworkPath))
|
||||
|
||||
nameId = lib.replace(replaceFrom, replaceTo)
|
||||
command = "%s %s %s" % ( cmdNameId, nameId, fileName )
|
||||
if not os.access(fileName, os.W_OK):
|
||||
if not os.access(str(fileName), os.W_OK):
|
||||
command = "chmod u+w %s; %s; chmod u-w %s" % (fileName, command, fileName)
|
||||
# print("\t%s" % command)
|
||||
if subprocess.call( command, shell=True ) != 0:
|
||||
|
|
|
|||
Loading…
Reference in New Issue