OXYGENHUB
# 2f0b4b0651ea 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
1
#!/usr/bin/env python3
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.
7
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
14
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
57
out = []
58
w = out.append
59
w(f'SUMMARY="{port["summary"]}"')
60
w('DESCRIPTION="' + " \\\n".join(port["description"]) + '"')
61
w(f'HOMEPAGE="https://oxygenhub.io/andymccall/{port["repo"]}"')
62
w('COPYRIGHT="2025-2026 Andy McCall"')
63
w('LICENSE="MIT\n\tApache v2"')
64
w('REVISION="1"')
65
w(f'SOURCE_URI="$HOMEPAGE/releases/download/v$portVersion/{name}-$portVersion-src.tar.gz"')
66
w(f'CHECKSUM_SHA256="{sha}"')
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"')
70
    w(f'CHECKSUM_SHA256_{i}="{ck}"')
71
    w(f'SOURCE_FILENAME_{i}="{crate}-{ver}.tar.gz"')
72
last = len(crates) + 1
73
w(f'''
74
ARCHITECTURES="!x86_gcc2 ?x86 x86_64"
75
SECONDARY_ARCHITECTURES="x86"
76
77
PROVIDES="
78
	{name}$secondaryArchSuffix = $portVersion
79
	cmd:{name}
80
	"
81
REQUIRES="
82
	haiku$secondaryArchSuffix
83
	lib:libzstd$secondaryArchSuffix
84
	"
85
86
BUILD_REQUIRES="
87
	haiku${{secondaryArchSuffix}}_devel
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()
97
{{
98
	export CARGO_HOME=$sourceDir/../cargo
99
	vendor=$CARGO_HOME/haiku
100
	mkdir -p "$vendor"
101
	for i in $(seq 2 {last}); do
102
		eval "srcDir=\\$sourceDir$i"
103
		eval "sha256sum=\\$CHECKSUM_SHA256_$i"
104
		set -- "$srcDir"/*
105
		ln -sf "$1" "$vendor"
106
		cat <<-EOF >"$vendor/${{1##*/}}/.cargo-checksum.json"
107
		{{
108
		  "package": "$sha256sum",
109
		  "files": {{}}
110
		}}
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
125
	cargo build --release --frozen -p {port["package"]}
126
}}
127
128
INSTALL()
129
{{
130
	install -v -m 755 -d "$prefix"/bin "$docDir"
131
	install -v -m 755 ./target/release/{name} "$prefix"/bin
132
	install -v -m 644 {port["docs"]} "$docDir"
133
}}
134
135
TEST()
136
{{
137
	export CARGO_HOME=$sourceDir/../cargo
138
	export ZSTD_SYS_USE_PKG_CONFIG=1
139
	cargo test --release --frozen -p {port["test"]}
140
}}''')
141
print("\n".join(out))