Files
breeze/scripts/generate-android-sources.py
T
waozi f25b4dfd5e Build Apps and Crypto as locked packages and take the node-app ABI from Apps
Apps and Crypto are now ordinary Ziran dependencies, pinned in ziran.lock
and linked by scripts/packages.sh, instead of local checkouts handed to the
build. Every dependency and the toolchain are on their latest revisions.

scripts/package-paths.sh is the one list of NAME=DIR package paths; the
native, web, Windows and Android builds, the source check, the bundle
scripts and the tests all use it, so they resolve packages the same way.
The shared Apps controller bundle is built from the locked Apps package,
and its reviewed digest matches that build.

Node apps, the feature cells and the host import the module ABI and the
node-app types and codec from the Apps package. Inner Breeze no longer
keeps its own copies, its codec generator, or the unused protocol module.

Test hosts include zir_string.h for the string helpers they call.
2026-10-18 23:20:13 -03:00

61 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""Generate the complete checked Zi graph and its CMake source manifest."""
import argparse
from pathlib import Path
import shutil
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument("--compiler", type=Path, required=True)
parser.add_argument("--root", type=Path, required=True)
parser.add_argument("--kryon", type=Path, required=True)
parser.add_argument("--output", type=Path, required=True)
parser.add_argument("--manifest", type=Path, required=True)
parser.add_argument("--define", action="append", default=[])
args = parser.parse_args()
root = args.root.resolve()
kryon = args.kryon.resolve()
sources = sorted((root / "src").rglob("*.zi"))
sources.append(root / "apps/practice/downloads_view.zi")
if list((root / "src").rglob("*.c")) or list((root / "src").rglob("*.kry")):
raise SystemExit("Android application implementation must be current Zi")
if args.output.exists():
shutil.rmtree(args.output)
args.output.mkdir(parents=True)
command = ["sh", str(root / "scripts/run-ziran.sh"), str(args.compiler),
"--no-main", "--root", str(root)]
for name in args.define:
command.extend(["--define", name])
for directory in (
root / "src", kryon / "src/ui", kryon / "src/backend", root / "build/packages/kss/src",
root / "build/packages/game2d/src", root / "build/packages/ziran/std", root / "build/packages/daochi-client",
):
command.extend(["--module-path", str(directory)])
# Dependencies are imported as PACKAGE/Module through their linked packages.
command.extend(subprocess.check_output(
["sh", str(root / "scripts/package-paths.sh"), str(root / "build/packages")], text=True).split())
command.extend(["-o", str(args.output)])
command.extend(str(path.relative_to(root)) for path in sources)
completed = subprocess.run(command, cwd=root)
if completed.returncode != 0:
# The compiler already printed precise diagnostics; avoid repeating the
# entire application source list inside a Python exception traceback.
raise SystemExit(completed.returncode)
outputs = sorted(args.output.rglob("*.c"))
if not outputs:
raise SystemExit("Zi compiler emitted no Android native sources")
headers = sorted(args.output.rglob("*.h"))
include_dirs = sorted({args.output, args.output / "src", *(p.parent for p in headers)})
lines = ["# Generated from the complete Zi import graph.", "set(APP_ZIRAN_GENERATED_SOURCES"]
lines.extend(f' "{path}"' for path in outputs)
lines.extend([")", "set(APP_ZIRAN_GENERATED_HEADERS"])
lines.extend(f' "{path}"' for path in headers)
lines.extend([")", "set(APP_ZIRAN_INCLUDE_DIRS"])
lines.extend(f' "{path}"' for path in include_dirs)
lines.append(")\n")
content = "\n".join(lines)
args.manifest.parent.mkdir(parents=True, exist_ok=True)
if not args.manifest.exists() or args.manifest.read_text() != content:
args.manifest.write_text(content)
print(f"Generated {len(outputs)} Android C outputs from maintained Zi sources")