| 1 |
|
| 2 |
> |
| 3 |
|
| 4 |
|
| 5 |
import logging as log |
| 6 |
import subprocess as sp |
| 7 |
import re |
| 8 |
import os |
| 9 |
import sys |
| 10 |
from pathlib import Path |
| 11 |
|
| 12 |
if len(sys.argv) != 2: |
| 13 |
print(f"{sys.argv[0]} <wheel_dir>") |
| 14 |
exit(-1) |
| 15 |
|
| 16 |
log.basicConfig( |
| 17 |
level=log.INFO, |
| 18 |
stream=sys.stdout, |
| 19 |
format="%(levelname)-5s - %(message)s", |
| 20 |
force=True, |
| 21 |
) |
| 22 |
|
| 23 |
archs = { |
| 24 |
"universal2": ["x86_64", "arm64"], |
| 25 |
"x86_64": [r"x86[_-]64"], |
| 26 |
"arm64": ["arm64"], |
| 27 |
"aarch64": ["ARM aarch64"], |
| 28 |
"i686": ["Intel 80386"], |
| 29 |
"win32": [r"INVALID"], |
| 30 |
"amd64": [r"x86[_-]64"], |
| 31 |
} |
| 32 |
|
| 33 |
filename = { |
| 34 |
"macosx": "libcapstone.dylib", |
| 35 |
"manylinux": "libcapstone.so", |
| 36 |
"musllinux": "libcapstone.so", |
| 37 |
"win": "capstone.dll", |
| 38 |
} |
| 39 |
|
| 40 |
success = True |
| 41 |
wheel_seen = False |
| 42 |
for root, dir, files in os.walk(sys.argv[1]): |
| 43 |
for file in files: |
| 44 |
f = Path(root).joinpath(file) |
| 45 |
if f.suffix != ".whl": |
| 46 |
continue |
| 47 |
wheel_seen = True |
| 48 |
target = re.search(r"py3-none-(.+).whl", f"{f}").group(1) |
| 49 |
platform = re.search("^(win|manylinux|musllinux|macosx)", target).group(1) |
| 50 |
|
| 51 |
arch = re.search( |
| 52 |
"(universal2|x86_64|arm64|aarch64|i686|win32|amd64)$", target |
| 53 |
).group(1) |
| 54 |
log.info(f"Target: {target} - Platform: {platform} - Arch: {archs[arch]}") |
| 55 |
|
| 56 |
out_dir = f"{platform}__{arch}" |
| 57 |
sp.run(["unzip", "-q", f"{f}", "-d", out_dir], check=True) |
| 58 |
lib_path = Path(out_dir).joinpath(f"capstone/lib/{filename[platform]}") |
| 59 |
result = sp.run(["file", "-b", f"{lib_path}"], capture_output=True, check=True) |
| 60 |
stdout = result.stdout.decode("utf8").strip() |
| 61 |
if any([not re.search(a, stdout) for a in archs[arch]]): |
| 62 |
success = False |
| 63 |
log.error(f"The wheel '{file}' is not compiled for '{archs[arch]}'.") |
| 64 |
log.error(f"Binary is: {stdout}") |
| 65 |
print() |
| 66 |
else: |
| 67 |
log.info(f"OK: Arch: {arch} - {lib_path}") |
| 68 |
log.info(f"Binary is: {stdout}") |
| 69 |
log.info(f"Delete {out_dir}") |
| 70 |
print() |
| 71 |
os.system(f"rm -r {out_dir}") |
| 72 |
break |
| 73 |
|
| 74 |
if not wheel_seen: |
| 75 |
log.error("No wheel was checked.") |
| 76 |
exit(-1) |
| 77 |
|
| 78 |
if not success: |
| 79 |
log.error("Binary files are compiled for the wrong architecture.") |
| 80 |
exit(-1) |