LIEF/tests/utils.py.in
2021-01-03 17:52:44 +01:00

45 lines
1.1 KiB
Python

#!/usr/bin/env python
import os
import sys
import platform
import re
import subprocess
def get_sample(filename):
fullpath = os.path.join("@LIEF_SAMPLES_DIRECTORY@", filename)
assert os.path.exists(fullpath)
assert os.path.isfile(fullpath)
return fullpath
def get_compiler():
compiler = os.getenv("CC", "/usr/bin/cc")
if not os.path.exists(compiler):
raise RuntimeError("Unable to find a compiler")
return compiler
def is_linux():
return sys.platform.startswith("linux")
def is_x86_64():
machine = platform.machine().lower()
return machine in ("x86_64", "amd64")
def is_aarch64():
return platform.machine() == "aarch64"
def has_recent_glibc():
"""Check if we have at least GLIBC 2.17 (2012)"""
try:
out = subprocess.check_output(["ldd", "--version"]).decode("ascii")
version_str = re.search(" (\d\.\d+)\n", out).group(1)
major, minor = version_str.split(".")
except (OSError, AttributeError):
pass
else:
if int(major) == 2 and int(minor) >= 17:
return True
return False