Repository navigation
Expand file tree
/
Copy pathrun_android.py
More file actions
71 lines (49 loc) · 1.82 KB
/
Copy pathrun_android.py
File metadata and controls
71 lines (49 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
"""Fetch facerecognitionsdk.aar if missing, then run the React Native Android example.
Mirrors the README manual steps: fetch missing native binaries, then the
standard yarn / React Native commands for this repo.
"""
from __future__ import annotations
import json
import os
import shutil
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
IS_WIN = os.name == "nt"
def die(msg: str) -> None:
print(f"ERROR: {msg}", file=sys.stderr)
raise SystemExit(1)
def which(name: str) -> str | None:
hits = [shutil.which(name)]
if IS_WIN:
hits.extend([shutil.which(name + ".cmd"), shutil.which(name + ".exe")])
return next((h for h in hits if h), None)
def need(name: str, hint: str) -> str:
path = which(name)
if not path:
die(f"{name} is not on PATH. {hint}")
return path
def run(args: list[str], cwd: Path | None = None) -> None:
print("+", " ".join(str(a) for a in args))
r = subprocess.run(args, cwd=str(cwd or ROOT))
if r.returncode:
raise SystemExit(r.returncode)
def yarn_cmd() -> list[str]:
yarn_js = ROOT / ".yarn" / "releases" / "yarn-3.6.1.cjs"
if yarn_js.is_file():
return [need("node", "Install Node.js from https://nodejs.org/"), str(yarn_js)]
return [need("yarn", "Enable Yarn (corepack enable) or install Yarn 3.")]
def yarn_install() -> None:
"""Yarn workspace install at the repo root (see package.json packageManager)."""
run([*yarn_cmd(), "install"])
AAR = ROOT / "example" / "android" / "libfacesdk" / "facerecognitionsdk.aar"
def main() -> None:
import fp_releases
print(f"{ROOT.name}: android (react-native)")
fp_releases.ensure_engine_aar(ROOT, AAR)
yarn_install()
run([*yarn_cmd(), "example", "android"])
if __name__ == "__main__":
main()