OXYGENHUB
◆ v0.9.0 oxygen / packaging / haikuports / make-recipe.py
4.3 KiB · Python · last changed Releases carry their source: oxy-VERSION-src.tar.gz, reproducible; haikuports recipes for oxy and oh written from release source tarballs (refs #157) 7 days ago source blame history raw
a42f9fb4 Andy McCall ↶ 1
#!/usr/bin/env python3
04534029 Andy McCall ↶ 2
"""Write a haikuports recipe for oxy or oh (oxygen#156, #157) from a release's
3
source tarball, NAME-VERSION-src.tar.gz, as the release job attaches it: the
4
tarball itself from the release's stable download address, and every
5
crates.io crate in its Cargo.lock as a source of its own with its checksum,
6
vendored offline in BUILD() as haikuports' Rust recipes (ripgrep) do.
a42f9fb4 Andy McCall ↶ 7
04534029 Andy McCall ↶ 8
    make-recipe.py oxy|oh SRC_TARBALL VERSION > NAME-VERSION.recipe
9
"""
10
import hashlib
11
import sys
12
import tarfile
13
import tomllib
a42f9fb4 Andy McCall ↶ 14
04534029 Andy McCall ↶ 15
PORTS = {
16
    "oxy": {
17
        "repo": "oxygen",
18
        "package": "oxy",
19
        "summary": "A version control system of signed, commuting changes, with Git interop",
20
        "description": [
21
            "oxy is the command line of Oxygen, a version control system built on",
22
            "patch theory: changes commute, conflicts are recorded rather than blocking,",
23
            "every change can be signed, and a trust policy says who may move what. It",
24
            "imports and exports Git history, clones from OxygenHub and other Oxygen",
25
            "hosts, and keeps repositories on disk or in S3, GCS or Azure buckets.",
26
        ],
27
        "docs": "README.md LICENSE*",
28
        "test": "oxy-core",
29
    },
30
    "oh": {
31
        "repo": "oxygenhub",
32
        "package": "oh",
33
        "summary": "The command line of OxygenHub, the forge for Oxygen repositories",
34
        "description": [
35
            "oh talks to an OxygenHub (such as https://oxygenhub.io): issues, proposals",
36
            "and their reviews, releases, Flow runs, their logs and reports, and checks,",
37
            "from the terminal. It works alongside oxy, the Oxygen version control",
38
            "client.",
39
        ],
40
        "docs": "README.md LICENSE docs/oh.md",
41
        "test": "hub-api",
42
    },
43
}
44
45
name, tarball, version = sys.argv[1], sys.argv[2], sys.argv[3]
46
port = PORTS[name]
47
prefix = f"{port['repo']}-{version}"
48
with tarfile.open(tarball) as t:
49
    lock = tomllib.load(t.extractfile(f"{prefix}/Cargo.lock"))
50
crates = sorted(
51
    (p["name"], p["version"], p["checksum"])
52
    for p in lock["package"]
53
    if p.get("source", "").startswith("registry+")
54
)
55
sha = hashlib.sha256(open(tarball, "rb").read()).hexdigest()
56
a42f9fb4 Andy McCall ↶ 57
out = []
58
w = out.append
04534029 Andy McCall ↶ 59
w(f'SUMMARY="{port["summary"]}"')
60
w('DESCRIPTION="' + " \\\n".join(port["description"]) + '"')
61
w(f'HOMEPAGE="https://oxygenhub.io/andymccall/{port["repo"]}"')
a42f9fb4 Andy McCall ↶ 62
w('COPYRIGHT="2025-2026 Andy McCall"')
63
w('LICENSE="MIT\n\tApache v2"')
64
w('REVISION="1"')
04534029 Andy McCall ↶ 65
w(f'SOURCE_URI="$HOMEPAGE/releases/download/v$portVersion/{name}-$portVersion-src.tar.gz"')
a42f9fb4 Andy McCall ↶ 66
w(f'CHECKSUM_SHA256="{sha}"')
04534029 Andy McCall ↶ 67
w(f'SOURCE_DIR="{port["repo"]}-$portVersion"')
68
for i, (crate, ver, ck) in enumerate(crates, start=2):
69
    w(f'SOURCE_URI_{i}="https://static.crates.io/crates/{crate}/{crate}-{ver}.crate"')
a42f9fb4 Andy McCall ↶ 70
    w(f'CHECKSUM_SHA256_{i}="{ck}"')
04534029 Andy McCall ↶ 71
    w(f'SOURCE_FILENAME_{i}="{crate}-{ver}.tar.gz"')
a42f9fb4 Andy McCall ↶ 72
last = len(crates) + 1
04534029 Andy McCall ↶ 73
w(f'''
a42f9fb4 Andy McCall ↶ 74
ARCHITECTURES="!x86_gcc2 ?x86 x86_64"
75
SECONDARY_ARCHITECTURES="x86"
76
77
PROVIDES="
04534029 Andy McCall ↶ 78
	{name}$secondaryArchSuffix = $portVersion
79
	cmd:{name}
a42f9fb4 Andy McCall ↶ 80
	"
81
REQUIRES="
82
	haiku$secondaryArchSuffix
83
	lib:libzstd$secondaryArchSuffix
84
	"
85
86
BUILD_REQUIRES="
04534029 Andy McCall ↶ 87
	haiku${{secondaryArchSuffix}}_devel
a42f9fb4 Andy McCall ↶ 88
	devel:libzstd$secondaryArchSuffix
89
	"
90
BUILD_PREREQUIRES="
91
	cmd:gcc$secondaryArchSuffix
92
	cmd:pkg_config$secondaryArchSuffix
93
	cmd:rustc$secondaryArchSuffix >= 1.88
94
	"
95
96
BUILD()
04534029 Andy McCall ↶ 97
{{
a42f9fb4 Andy McCall ↶ 98
	export CARGO_HOME=$sourceDir/../cargo
99
	vendor=$CARGO_HOME/haiku
100
	mkdir -p "$vendor"
04534029 Andy McCall ↶ 101
	for i in $(seq 2 {last}); do
a42f9fb4 Andy McCall ↶ 102
		eval "srcDir=\\$sourceDir$i"
103
		eval "sha256sum=\\$CHECKSUM_SHA256_$i"
104
		set -- "$srcDir"/*
105
		ln -sf "$1" "$vendor"
04534029 Andy McCall ↶ 106
		cat <<-EOF >"$vendor/${{1##*/}}/.cargo-checksum.json"
107
		{{
a42f9fb4 Andy McCall ↶ 108
		  "package": "$sha256sum",
04534029 Andy McCall ↶ 109
		  "files": {{}}
110
		}}
a42f9fb4 Andy McCall ↶ 111
		EOF
112
	done
113
114
	cat <<-EOF >"$CARGO_HOME"/config.toml
115
	[source.haiku]
116
	directory = "$vendor"
117
118
	[source.crates-io]
119
	replace-with = "haiku"
120
	EOF
121
122
	# The bundled zstd's hidden symbols break the link on Haiku: use the system's.
123
	export ZSTD_SYS_USE_PKG_CONFIG=1
124
	export OXY_BUILD=v$portVersion
04534029 Andy McCall ↶ 125
	cargo build --release --frozen -p {port["package"]}
126
}}
a42f9fb4 Andy McCall ↶ 127
128
INSTALL()
04534029 Andy McCall ↶ 129
{{
a42f9fb4 Andy McCall ↶ 130
	install -v -m 755 -d "$prefix"/bin "$docDir"
04534029 Andy McCall ↶ 131
	install -v -m 755 ./target/release/{name} "$prefix"/bin
132
	install -v -m 644 {port["docs"]} "$docDir"
133
}}
a42f9fb4 Andy McCall ↶ 134
135
TEST()
04534029 Andy McCall ↶ 136
{{
a42f9fb4 Andy McCall ↶ 137
	export CARGO_HOME=$sourceDir/../cargo
138
	export ZSTD_SYS_USE_PKG_CONFIG=1
04534029 Andy McCall ↶ 139
	cargo test --release --frozen -p {port["test"]}
140
}}''')
a42f9fb4 Andy McCall ↶ 141
print("\n".join(out))