73 lines
3.5 KiB
Python
73 lines
3.5 KiB
Python
"""Stage the ARM DSView runtime and the canonical templates decoder package."""
|
|
import argparse
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
|
|
|
|
def copy(source, target):
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copy2(source, target)
|
|
|
|
|
|
def stage(source, binary, protocol, sysroot, objdump, templates, output):
|
|
target_lib = output / "lib"
|
|
target_share = output / "share/DSView"
|
|
machine = "arm-linux-gnueabihf"
|
|
lib_dirs = (sysroot / "usr/lib" / machine, sysroot / "lib" / machine)
|
|
copy(binary, output / "bin/DSView")
|
|
copy(protocol, target_lib / "libsetprotocol.so")
|
|
shutil.copytree(sysroot / "usr/lib/python3.11", target_lib / "python3.11", dirs_exist_ok=True,
|
|
ignore=shutil.ignore_patterns("__pycache__", "test", "tests", "tkinter", "idlelib", "ensurepip"))
|
|
plugins = lib_dirs[0] / "qt5/plugins"
|
|
for plugin in ("platforms/libqlinuxfb.so", "imageformats/libqjpeg.so", "imageformats/libqsvg.so",
|
|
"iconengines/libqsvgicon.so"):
|
|
copy(plugins / plugin, output / "plugins" / plugin)
|
|
for name in ("res", "demo"):
|
|
shutil.copytree(source / "DSView" / name, target_share / name, dirs_exist_ok=True)
|
|
shutil.copytree(source / "lang", target_share / "lang", dirs_exist_ok=True)
|
|
shutil.copytree(source / "libsigrokdecode4DSL/decoders", target_share / "decoders", dirs_exist_ok=True,
|
|
ignore=shutil.ignore_patterns("__pycache__"))
|
|
recipe = templates / "tools/dsview/build.py"
|
|
spec = importlib.util.spec_from_file_location("dsview_recipe", recipe)
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
module.package_decoders(target_share)
|
|
shutil.copytree(sysroot / "usr/share/fonts/truetype/dejavu", output / "fonts", dirs_exist_ok=True)
|
|
(output / "fonts.conf").write_text(
|
|
'<fontconfig><dir prefix="relative">fonts</dir>'
|
|
'<cachedir>/run/scope-logic/fonts</cachedir></fontconfig>\n', encoding="ascii")
|
|
copy(source / "COPYING", output / "COPYING-DSView")
|
|
|
|
# Use an isolated glibc loader because the factory Linux has its own libc.
|
|
copy(lib_dirs[1] / "ld-linux-armhf.so.3", target_lib / "ld-linux-armhf.so.3")
|
|
candidates = [output / "bin/DSView", target_lib / "ld-linux-armhf.so.3"]
|
|
candidates.extend(output.rglob("*.so"))
|
|
known = set()
|
|
while candidates:
|
|
candidate = candidates.pop()
|
|
if candidate in known:
|
|
continue
|
|
known.add(candidate)
|
|
header = subprocess.check_output([objdump, "-p", candidate], text=True)
|
|
for name in re.findall(r"^\s*NEEDED\s+(\S+)", header, re.MULTILINE):
|
|
destination = target_lib / name
|
|
if destination.is_file():
|
|
continue
|
|
dependency = next((path / name for path in lib_dirs if (path / name).is_file()), None)
|
|
if dependency is None:
|
|
raise FileNotFoundError(f"{candidate.name} requires {name}")
|
|
copy(dependency, destination)
|
|
candidates.append(destination)
|
|
print(f"ARM runtime: {len(known)} ELF files, "
|
|
f"{sum(1 for _ in (target_share / 'decoders').glob('*/pd.py'))} protocol decoders")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
for option in ("source", "binary", "protocol", "sysroot", "objdump", "templates", "output"):
|
|
parser.add_argument("--" + option, type=Path, required=True)
|
|
stage(**{name: path.resolve() for name, path in vars(parser.parse_args()).items()})
|