fixed ls links, modules writeable

This commit is contained in:
2026-03-02 21:23:35 -05:00
parent 413afd96de
commit 16c900de84
15 changed files with 1198 additions and 230 deletions

158
build.py
View File

@@ -6,8 +6,10 @@ Usage:
Targets:
build
build-mini
build-micro
build-test
build-mini-test
build-micro-test
clean
Arch flags:
@@ -23,11 +25,9 @@ import sys
import shutil
import argparse
import subprocess
import hashlib
import random
import string
from pathlib import Path
from typing import Union
import lz4.frame
PROJECT_ROOT = Path(__file__).resolve().parent
SRC_ROOT = PROJECT_ROOT / "Src"
@@ -48,7 +48,34 @@ def clean():
print("Nothing to clean.")
def process_root(src_root: Path, out_root: Path, minify: bool):
def has_minify_header(path: Path) -> bool:
try:
with path.open("r", encoding="utf-8", errors="ignore") as f:
for _ in range(3):
if "--:Minify:--" in f.readline():
return True
except OSError:
pass
return False
def minify_file(src: Path) -> str:
result = subprocess.run(
["luamin.cmd", "-f", str(src)],
capture_output=True,
text=True
)
if result.returncode != 0:
print(f" ! luamin failed: {result.stderr.strip()}", file=sys.stderr)
sys.exit(1)
return result.stdout
def compress_lz4(data: bytes) -> bytes:
return lz4.frame.compress(data)
def process_root(src_root: Path, out_root: Path, minify: bool, micro: bool):
print(f"Building from {src_root}")
print(f"Output to {out_root}")
print()
@@ -69,16 +96,20 @@ def process_root(src_root: Path, out_root: Path, minify: bool):
print(f" Processing: {src.relative_to(src_root)}")
if minify and has_minify_header(src):
if has_minify_header(src):
print(" > Minifying")
result = subprocess.run(
["luamin.cmd", "-f", str(src)],
capture_output=True, text=True
)
if result.returncode != 0:
print(f" ! luamin failed: {result.stderr.strip()}", file=sys.stderr)
sys.exit(1)
dst.write_text(result.stdout, encoding="utf-8")
content = minify_file(src)
if micro:
print(" > LZ4 compressing")
compressed = compress_lz4(content.encode("utf-8"))
# wrap in kernel.unpack if in hyperion-kernel
if pkg_dir.name == "hyperion-kernel" and dst.suffix == ".lua":
content_str = f"kernel.unpack([=[{compressed.hex()}]=])"
dst.write_text(content_str, encoding="utf-8")
else:
dst.write_bytes(compressed)
else:
dst.write_text(content, encoding="utf-8")
else:
print(" > Copying")
shutil.copy2(src, dst)
@@ -95,26 +126,15 @@ def install_bootloader(arch: str, release: bool):
shutil.copy2(eeprom, BUILD_ROOT / eeprom_dst_name)
def has_minify_header(path: Path) -> bool:
try:
with path.open("r", encoding="utf-8", errors="ignore") as f:
for _ in range(3):
if "--:Minify:--" in f.readline():
return True
except OSError:
pass
return False
def run_build(minify: bool, include_test: bool, arch: Union[str, None], release: bool):
def run_build(minify: bool, micro: bool, include_test: bool, arch: Union[str, None], release: bool):
clean()
BUILD_ROOT.mkdir()
out_root = BUILD_ROOT / "$" if arch else BUILD_ROOT
process_root(SRC_ROOT, out_root, minify)
process_root(SRC_ROOT, out_root, minify, micro)
if include_test:
process_root(TEST_ROOT, out_root, minify)
process_root(TEST_ROOT, out_root, minify, micro)
if arch:
print("Installing bootloader files ...")
@@ -122,46 +142,6 @@ def run_build(minify: bool, include_test: bool, arch: Union[str, None], release:
print()
def main():
parser = argparse.ArgumentParser(description="HyperionOS build script")
parser.add_argument("target", choices=["build", "build-mini", "build-test", "build-mini-test", "clean"])
parser.add_argument("--arch", choices=["cct", "oc"], default=None,
help="Target architecture (cct or oc)")
parser.add_argument("--release", dest="release", action="store_true", default=True,
help="Release build: eeprom placed as startup.lua (default)")
parser.add_argument("--dev", dest="release", action="store_false",
help="Dev build: boot.lua and eeprom copied unchanged")
parser.add_argument(
"--makeuser", metavar=("USERNAME", "PASSWORD"), nargs=2, action="append",
default=[],
help=(
"Pre-create a user on first boot (dev builds only). "
"May be specified multiple times. "
"Example: --makeuser root secretpass --makeuser alice alicepass"
),
)
args = parser.parse_args()
if args.makeuser and args.release:
parser.error("--makeuser is only allowed with --dev builds")
if args.target == "clean":
clean()
return
minify = "mini" in args.target
include_test = "test" in args.target
run_build(minify=minify, include_test=include_test, arch=args.arch, release=args.release)
if args.makeuser:
print("Injecting first-boot user setup ...")
inject_makeusers(args.makeuser, args.arch)
print()
print("Build complete.")
def _make_firstboot_kmod(users):
lines = []
lines.append("local kernel = ...")
@@ -212,5 +192,47 @@ def inject_makeusers(users, arch):
print(" Wrote first-boot user setup -> " + str(kmod_path.relative_to(BUILD_ROOT)))
def main():
parser = argparse.ArgumentParser(description="HyperionOS build script")
parser.add_argument("target", choices=["build", "build-mini", "build-micro", "build-test", "build-mini-test", "build-micro-test", "clean"])
parser.add_argument("--arch", choices=["cct", "oc"], default=None,
help="Target architecture (cct or oc)")
parser.add_argument("--release", dest="release", action="store_true", default=True,
help="Release build: eeprom placed as startup.lua (default)")
parser.add_argument("--dev", dest="release", action="store_false",
help="Dev build: boot.lua and eeprom copied unchanged")
parser.add_argument(
"--makeuser", metavar=("USERNAME", "PASSWORD"), nargs=2, action="append",
default=[],
help=(
"Pre-create a user on first boot (dev builds only). "
"May be specified multiple times. "
"Example: --makeuser root secretpass --makeuser alice alicepass"
),
)
args = parser.parse_args()
if args.makeuser and args.release:
parser.error("--makeuser is only allowed with --dev builds")
if args.target == "clean":
clean()
return
minify = "mini" in args.target or "micro" in args.target
micro = "micro" in args.target
include_test = "test" in args.target
run_build(minify=minify, micro=micro, include_test=include_test, arch=args.arch, release=args.release)
if args.makeuser:
print("Injecting first-boot user setup ...")
inject_makeusers(args.makeuser, args.arch)
print()
print("Build complete.")
if __name__ == "__main__":
main()
main()