TauriTavern/scripts/ohos/validate-hap.py
LeenHawk 0077e15241
feat: add experimental OpenHarmony HAP support (#300)
* feat: add experimental OpenHarmony application build

* build(ohos): isolate experimental NAPI dependencies

* ci(ohos): build in this repository with public toolchain image

* ci: run existing checks for OHOS adaptation

* fix(ohos): generate QuickJS bindings for the OHOS target

* fix(ohos): use private caches and exclude desktop migration logs

* feat(ohos): restore native plugins and trusted endpoint confirmation

* ci(ohos): verify native plugin integration with existing checks

* chore(ohos): remove completed one-off validation workflow

* fix(ohos): clean dependency warnings and enable HAP LTO

* fix(ohos): retain shared plugin callbacks for the native bridge

* refactor(ohos): keep the native project and align the framework baseline

* fix(ohos): pin frame authorization and name the launcher entry

* fix(ohos): bind native builds and HAP packaging to the selected ABI

* fix(ohos): pin ordered Tauri bridge initialization

* fix(ohos): compress native libraries in HAP packages

* refactor(ohos): simplify HAP builds and Canary publishing

Build Rust once through the OHOS CLI and derive HAP versions from its merged
configuration. Replace the demo with the application page and remove generated
configuration writes, CMake scaffolding, and redundant preparation steps.

Keep ARM64 HAPs optional for Canary, report unsupported dev-log exports clearly,
and document the current build and host contracts.

Validated with pnpm run check, a local x86_64 HAP build and simulator smoke checks,
and Windows notification smoke checks.

---------

Co-authored-by: Darkatse <39111369+Darkatse@users.noreply.github.com>
2026-10-04 14:09:37 +08:00

46 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Reject missing or wrong-architecture native libraries before publishing a HAP."""
import argparse
import hashlib
from pathlib import Path
import struct
import zipfile
def validate_hap(path, target):
abi, machine = {
"aarch64-unknown-linux-ohos": ("arm64-v8a", 183),
"x86_64-unknown-linux-ohos": ("x86_64", 62),
}[target]
with zipfile.ZipFile(path) as archive:
names = archive.namelist()
library = f"libs/{abi}/libtauritavern_lib.so"
if library not in names:
raise ValueError(f"Missing application library: {library}")
for name in names:
if not name.startswith("libs/") or not name.endswith(".so"):
continue
if name.split("/")[1] != abi:
raise ValueError(f"Unexpected ABI in HAP: {name}; expected {abi}")
with archive.open(name) as stream:
header = stream.read(20)
if (len(header) != 20 or header[:6] != b"\x7fELF\x02\x01"
or struct.unpack_from("<H", header, 18)[0] != machine):
raise ValueError(f"Wrong ELF architecture: {name}; expected {target}")
if "ets/modules.abc" not in names or "module.json" not in names:
raise ValueError("HAP is missing its ArkTS bytecode or module manifest")
bad = archive.testzip()
if bad:
raise ValueError(f"Corrupt HAP entry: {bad}")
with Path(path).open("rb") as stream:
digest = hashlib.file_digest(stream, "sha256").hexdigest()
return digest
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--target", required=True)
parser.add_argument("hap", type=Path)
args = parser.parse_args()
digest = validate_hap(args.hap, args.target)
print(f"Verified {args.target}: {args.hap}\nSHA256 {digest}")