Skip to content

Commit 896f734

Browse files
committed
full python embed with dependencies. includes ssl
1 parent 73772cc commit 896f734

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

Diff for: macbuild/build4mac.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -797,23 +797,41 @@ def DeployBinariesForBundle():
797797
os.chmod( targetDirM + "/klayout_console", 0o0755 )
798798

799799
print(" [2] Relinking dylib dependencies inside Python.framework")
800+
print(" [2.1] Patching Python Framework")
800801
depdict = WalkFrameworkPaths(pythonFrameworkPath)
801802
appPythonFrameworkPath = '@executable_path/../Frameworks/Python.framework/'
802-
PerformChanges(depdict, [(pythonOriginalFrameworkPath, appPythonFrameworkPath)], bundleExecPathAbs)
803+
PerformChanges(depdict, [(pythonOriginalFrameworkPath, appPythonFrameworkPath, False)], bundleExecPathAbs)
803804

805+
print(" [2.2] Patching /usr/local/opt/ libs")
804806
usrLocalPath = '/usr/local/opt/'
805807
appUsrLocalPath = '@executable_path/../Frameworks/'
806-
depdict = WalkFrameworkPaths(pythonFrameworkPath)
807-
PerformChanges(depdict, [(usrLocalPath, appUsrLocalPath)], bundleExecPathAbs, libdir=True)
808+
replacePairs = [(usrLocalPath, appUsrLocalPath, True)]
809+
depdict = WalkFrameworkPaths(pythonFrameworkPath, search_path_filter=r'\t+/usr/local/(opt|Cellar)')
810+
PerformChanges(depdict, replacePairs, bundleExecPathAbs)
811+
812+
print(" [2.3] Patching openssl, gdbm, readline, sqlite, tcl-tk, xz")
813+
usrLocalPath = '/usr/local/opt'
814+
appUsrLocalPath = '@executable_path/../Frameworks/'
815+
replacePairs = [(usrLocalPath, appUsrLocalPath, True)]
816+
replacePairs.extend([(openssl_version, '@executable_path/../Frameworks/openssl', True)
817+
for openssl_version in list(Path('/usr/local/Cellar/openssl').glob('*'))])
818+
depdict = WalkFrameworkPaths([pythonFrameworkPath + '/../openssl',
819+
pythonFrameworkPath + '/../gdbm',
820+
pythonFrameworkPath + '/../readline',
821+
pythonFrameworkPath + '/../sqlite',
822+
pythonFrameworkPath + '/../tcl-tk',
823+
pythonFrameworkPath + '/../xz'], search_path_filter=r'\t+/usr/local/(opt|Cellar)')
824+
825+
PerformChanges(depdict, replacePairs, bundleExecPathAbs)
808826

809827
print(" [3] Relinking dylib dependencies for klayout")
810828
klayoutPath = bundleExecPathAbs
811829
depdict = WalkFrameworkPaths(klayoutPath, filter_regex=r'klayout$')
812-
PerformChanges(depdict, [(pythonOriginalFrameworkPath, appPythonFrameworkPath)], bundleExecPathAbs)
830+
PerformChanges(depdict, [(pythonOriginalFrameworkPath, appPythonFrameworkPath, False)], bundleExecPathAbs)
813831

814832
libKlayoutPath = bundleExecPathAbs + '../Frameworks'
815833
depdict = WalkFrameworkPaths(libKlayoutPath, filter_regex=r'libklayout')
816-
PerformChanges(depdict, [(pythonOriginalFrameworkPath, appPythonFrameworkPath)], bundleExecPathAbs)
834+
PerformChanges(depdict, [(pythonOriginalFrameworkPath, appPythonFrameworkPath, False)], bundleExecPathAbs)
817835

818836
print(" [4] Patching site.py, pip/, and distutils/")
819837
site_module = f"{pythonFrameworkPath}/Versions/3.6/lib/python3.6/site.py"

Diff for: macbuild/build4mac_util.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,12 @@ def WalkLibDependencyTree( dylibPath, depth=0, filter_regex=r'\t+/usr/local/opt'
206206
else:
207207
raise RuntimeError("Exceeded maximum recursion depth.")
208208

209-
def WalkFrameworkPaths(frameworkPaths, filter_regex=r'\.(so|dylib)$'):
209+
def WalkFrameworkPaths(frameworkPaths, filter_regex=r'\.(so|dylib)$', search_path_filter=r'\t+/usr/local/opt'):
210210

211211
if isinstance(frameworkPaths, str):
212212
frameworkPathsIter = [frameworkPaths]
213+
else:
214+
frameworkPathsIter = frameworkPaths
213215

214216
dependency_dict = dict()
215217

@@ -223,7 +225,7 @@ def WalkFrameworkPaths(frameworkPaths, filter_regex=r'\.(so|dylib)$'):
223225

224226
dependency_dict[frameworkPath] = list()
225227
for idx, file in enumerate(framework_files):
226-
dict_file = {file: WalkLibDependencyTree(file)}
228+
dict_file = {file: WalkLibDependencyTree(file, filter_regex=search_path_filter)}
227229
dependency_dict[frameworkPath].append(dict_file)
228230
return dependency_dict
229231

@@ -277,7 +279,7 @@ def DetectChanges(frameworkDependencyDict):
277279

278280
return libNameChanges
279281

280-
def PerformChanges(frameworkDependencyDict, replaceFromToPairs=None, executable_path="/tmp/klayout", libdir=False):
282+
def PerformChanges(frameworkDependencyDict, replaceFromToPairs=None, executable_path="/tmp/klayout"):
281283
libNameChanges = DetectChanges(frameworkDependencyDict)
282284
cmdNameId = XcodeToolChain['nameID']
283285
cmdNameChg = XcodeToolChain['nameCH']
@@ -290,11 +292,15 @@ def PerformChanges(frameworkDependencyDict, replaceFromToPairs=None, executable_
290292
dependencies = next(libNameChangeIterator)
291293
except StopIteration:
292294
dependencies = list()
293-
for replaceFrom, replaceTo in replaceFromToPairs:
295+
for replaceFrom, replaceTo, libdir in replaceFromToPairs:
294296
replaceFrom = str(Path(replaceFrom))
295297
replaceTo = str(Path(replaceTo))
296298

297299
fileName = ResolveExecutablePath(lib.replace(replaceFrom, replaceTo), executable_path)
300+
if str(fileName).startswith('/usr'):
301+
# print(f'skipping fileName: {fileName}')
302+
continue
303+
298304
if lib.find(replaceFrom) >= 0:
299305
if libdir:
300306
frameworkPath = FindFramework(lib, replaceFrom)
@@ -320,7 +326,7 @@ def PerformChanges(frameworkDependencyDict, replaceFromToPairs=None, executable_
320326

321327
for dependency in dependencies:
322328
if dependency.find(replaceFrom) >= 0:
323-
print("In:", fileName)
329+
print("\tIn:", fileName)
324330
print("\tRENAME", dependency, " -> ", dependency.replace(replaceFrom, replaceTo))
325331

326332
# Try changing id first

0 commit comments

Comments
 (0)