import os import stat import subprocess from lib import common strip = os.environ.get("STRIP", "strip") def _is_elf(filepath): with open(filepath, "rb") as f: return f.read(4) == b"\x7fELF" def autostrip(composer): for ent in common.treedir(composer.workdir): if not ent.is_file(follow_symlinks=False): continue if not (os.access(ent.path, os.X_OK) or ".so" in ent.name): continue if not _is_elf(ent.path): continue oldperm = stat.S_IMODE(os.stat(ent.path).st_mode) os.chmod(ent.path, 0o777) subprocess.run([strip, ent.path], check=True) os.chmod(ent.path, oldperm)