1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-28 01:10:58 +01:00
mkdocs-material/includes/debug/cairo-lookup-macos.py
Julien a2cb35d4c5
Improved error handling on social plugin (#6818)
* fix(social): CairoSVG OSError handling in social plugin

Related issue: #6817

Co-authored-by: Guts <1596222+Guts@users.noreply.github.com>

* feat(docs): Add troubleshooting guide for CairoSVG crash

---------

Co-authored-by: Kamil Krzyśków <kamilzary@gmail.com>
Co-authored-by: Guts <1596222+Guts@users.noreply.github.com>
Co-authored-by: Martin Donath <martin.donath@squidfunk.com>
2024-03-31 17:00:27 +08:00

50 lines
1.3 KiB
Python

import os
from ctypes.macholib import dyld
from itertools import chain
library_names = ("cairo-2", "cairo", "libcairo-2")
filenames = ("libcairo.so.2", "libcairo.2.dylib", "libcairo-2.dll")
first_found = ""
names = []
for name in library_names:
names += [
"lib%s.dylib" % name,
"%s.dylib" % name,
"%s.framework/%s" % (name, name),
]
for name in names:
for path in dyld.dyld_image_suffix_search(
chain(
dyld.dyld_override_search(name),
dyld.dyld_executable_path_search(name),
dyld.dyld_default_search(name),
)
):
if os.path.isfile(path):
print(f"Found: {path}")
if not first_found:
first_found = path
continue
try:
if dyld._dyld_shared_cache_contains_path(path):
print(f"Found: {path}")
if not first_found:
first_found = path
continue
except NotImplementedError:
pass
print(f"Doesn't exist: {path}")
print("---")
if first_found:
filenames = (first_found,) + filenames
print(f"The path is {first_found or 'not found'}")
print("List of files that FFI will try to load:")
for filename in filenames:
print("-", filename)