79 lines
3.2 KiB
Python
79 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Prepare FFprobe payload files for rust_realease bundle protocol 1."""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
from fetch_ffprobe import fetch, sha256
|
|
from build_macos_ffprobe import build as build_macos
|
|
|
|
|
|
def prepare(context, manifest):
|
|
if context["schema_version"] != 1:
|
|
raise ValueError("Unsupported bundle context schema")
|
|
if Path(manifest).resolve() != Path(context["manifest_path"]).resolve():
|
|
raise ValueError("Manifest path differs from the bundle context")
|
|
pins = json.loads((Path(context["package_root"]) / "ffprobe-pins.json").read_text())
|
|
pin = pins[context["target"]]
|
|
if pin["release"] == "latest" or not re.fullmatch(r"[0-9a-f]{64}", pin["sha256"]):
|
|
raise ValueError("FFprobe requires a dated release and SHA-256 pin")
|
|
if context["target"].endswith("-apple-darwin"):
|
|
binary, notices = build_macos(context["target"], Path(context["cache_directory"]), pin)
|
|
else:
|
|
binary, notices = fetch(
|
|
context["target"], Path(context["cache_directory"]),
|
|
pin["release"], pin["sha256"], asset_name=pin["asset"],
|
|
)
|
|
out = Path(context["output_directory"])
|
|
files = []
|
|
|
|
def include(source, relative, destination, kind="file"):
|
|
if source.is_symlink() or not source.is_file():
|
|
raise ValueError(f"Not a regular prepared input: {source}")
|
|
copied = out / relative
|
|
copied.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(source, copied)
|
|
files.append({
|
|
"source": relative, "destination": destination, "kind": kind,
|
|
"sha256": sha256(copied),
|
|
})
|
|
|
|
name = "ffprobe" + context["binary_ext"]
|
|
include(binary, name, name, "executable")
|
|
if notices.is_symlink() or not notices.is_dir():
|
|
raise ValueError("Missing or symlinked FFprobe notices")
|
|
licenses = []
|
|
for path in sorted(notices.rglob("*")):
|
|
if path.is_symlink() or not (path.is_file() or path.is_dir()):
|
|
raise ValueError(f"Unsafe notice: {path}")
|
|
if path.is_file():
|
|
relative = path.relative_to(notices).as_posix()
|
|
include(path, "notices/" + relative, "LICENSES/ffmpeg/" + relative)
|
|
if path.name.lower().startswith(("license", "copying")):
|
|
licenses.append(path)
|
|
if not licenses:
|
|
raise ValueError("Missing upstream license")
|
|
if not any(f["destination"] == "LICENSES/ffmpeg/LICENSE.txt" for f in files):
|
|
include(licenses[0], "canonical-LICENSE.txt", "LICENSES/ffmpeg/LICENSE.txt")
|
|
if not any(f["destination"] == "LICENSES/ffmpeg/provenance.json" for f in files):
|
|
raise ValueError("Missing FFprobe provenance")
|
|
Path(manifest).write_text(json.dumps({
|
|
"schema_version": 1, "target": context["target"], "files": files,
|
|
}, indent=2) + "\n")
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--context", type=Path, required=True)
|
|
parser.add_argument("--manifest", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
prepare(json.loads(args.context.read_text()), args.manifest)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|