File: cairo-lookup-macos.py

package info (click to toggle)
mkdocs-material 9.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 76,636 kB
  • sloc: javascript: 3,965; python: 3,622; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,303 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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)