#!/usr/bin/env python3 """Write a haikuports recipe for oxy from a release's Cargo.lock: the source archive from OxygenHub, and every crates.io crate as its own source with its checksum, vendored offline in BUILD() as haikuports' Rust recipes do.""" import hashlib, sys, tomllib lock_path, version, archive = sys.argv[1], sys.argv[2], sys.argv[3] lock = tomllib.load(open(lock_path, "rb")) crates = sorted((p["name"], p["version"], p["checksum"]) for p in lock["package"] if p.get("source", "").startswith("registry+")) sha = hashlib.sha256(open(archive, "rb").read()).hexdigest() out = [] w = out.append w('SUMMARY="A version control system of signed, commuting changes, with Git interop"') w('DESCRIPTION="oxy is the command line of Oxygen, a version control system built on \\') w('patch theory: changes commute, conflicts are recorded rather than blocking, \\') w('every change can be signed, and a trust policy says who may move what. It \\') w('imports and exports Git history, clones from OxygenHub and other Oxygen \\') w('hosts, and keeps repositories on disk or in S3, GCS or Azure buckets."') w('HOMEPAGE="https://oxygenhub.io/andymccall/oxygen"') w('COPYRIGHT="2025-2026 Andy McCall"') w('LICENSE="MIT\n\tApache v2"') w('REVISION="1"') w(f'SOURCE_URI="$HOMEPAGE/archive?ref=v$portVersion&format=tar.zst"') w(f'SOURCE_FILENAME="oxygen-v$portVersion.tar.zst"') w(f'CHECKSUM_SHA256="{sha}"') w('SOURCE_DIR="oxygen-v$portVersion"') for i, (name, ver, ck) in enumerate(crates, start=2): w(f'SOURCE_URI_{i}="https://static.crates.io/crates/{name}/{name}-{ver}.crate"') w(f'CHECKSUM_SHA256_{i}="{ck}"') w(f'SOURCE_FILENAME_{i}="{name}-{ver}.tar.gz"') last = len(crates) + 1 w(''' ARCHITECTURES="!x86_gcc2 ?x86 x86_64" SECONDARY_ARCHITECTURES="x86" PROVIDES=" oxy$secondaryArchSuffix = $portVersion cmd:oxy " REQUIRES=" haiku$secondaryArchSuffix lib:libzstd$secondaryArchSuffix " BUILD_REQUIRES=" haiku${secondaryArchSuffix}_devel devel:libzstd$secondaryArchSuffix " BUILD_PREREQUIRES=" cmd:gcc$secondaryArchSuffix cmd:pkg_config$secondaryArchSuffix cmd:rustc$secondaryArchSuffix >= 1.88 " BUILD() { export CARGO_HOME=$sourceDir/../cargo vendor=$CARGO_HOME/haiku mkdir -p "$vendor" for i in $(seq 2 ''' + str(last) + '''); do eval "srcDir=\\$sourceDir$i" eval "sha256sum=\\$CHECKSUM_SHA256_$i" set -- "$srcDir"/* ln -sf "$1" "$vendor" cat <<-EOF >"$vendor/${1##*/}/.cargo-checksum.json" { "package": "$sha256sum", "files": {} } EOF done cat <<-EOF >"$CARGO_HOME"/config.toml [source.haiku] directory = "$vendor" [source.crates-io] replace-with = "haiku" EOF # The bundled zstd's hidden symbols break the link on Haiku: use the system's. export ZSTD_SYS_USE_PKG_CONFIG=1 export OXY_BUILD=v$portVersion cargo build --release --frozen -p oxy } INSTALL() { install -v -m 755 -d "$prefix"/bin "$docDir" install -v -m 755 ./target/release/oxy "$prefix"/bin install -v -m 644 README.md LICENSE* "$docDir" } TEST() { export CARGO_HOME=$sourceDir/../cargo export ZSTD_SYS_USE_PKG_CONFIG=1 cargo test --release --frozen -p oxy-core }''') print("\n".join(out))