OXYGENHUB
◆ v0.10.0 oxygen / packaging / haikuports / make-recipe.py
4.2 KiB · Python · last changed HaikuPorts recipes: no x86 secondary architecture; the 32-bit build runs out of memory compiling oxy-core (refs #157) 5 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="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="!all x86_64"
75
76
PROVIDES="
77
	{name}$secondaryArchSuffix = $portVersion
78
	cmd:{name}
79
	"
80
REQUIRES="
81
	haiku$secondaryArchSuffix
82
	lib:libzstd$secondaryArchSuffix
83
	"
84
85
BUILD_REQUIRES="
86
	haiku${{secondaryArchSuffix}}_devel
87
	devel:libzstd$secondaryArchSuffix
88
	"
89
BUILD_PREREQUIRES="
90
	cmd:gcc$secondaryArchSuffix
91
	cmd:pkg_config$secondaryArchSuffix
92
	cmd:rustc$secondaryArchSuffix
93
	"
94
95
BUILD()
96
{{
97
	export CARGO_HOME=$sourceDir/../cargo
98
	vendor=$CARGO_HOME/haiku
99
	mkdir -p "$vendor"
100
	for i in $(seq 2 {last}); do
101
		eval "srcDir=\\$sourceDir$i"
102
		eval "sha256sum=\\$CHECKSUM_SHA256_$i"
103
		set -- "$srcDir"/*
104
		ln -sf "$1" "$vendor"
105
		cat <<-EOF >"$vendor/${{1##*/}}/.cargo-checksum.json"
106
		{{
107
		  "package": "$sha256sum",
108
		  "files": {{}}
109
		}}
110
		EOF
111
	done
112
113
	cat <<-EOF >"$CARGO_HOME"/config.toml
114
	[source.haiku]
115
	directory = "$vendor"
116
117
	[source.crates-io]
118
	replace-with = "haiku"
119
	EOF
120
121
	# The bundled zstd's hidden symbols break the link on Haiku: use the system's.
122
	export ZSTD_SYS_USE_PKG_CONFIG=1
123
	export OXY_BUILD=v$portVersion
124
	cargo build --release --frozen -p {port["package"]}
125
}}
126
127
INSTALL()
128
{{
129
	install -v -m 755 -d "$prefix"/bin "$docDir"
130
	install -v -m 755 ./target/release/{name} "$prefix"/bin
131
	install -v -m 644 {port["docs"]} "$docDir"
132
}}
133
134
TEST()
135
{{
136
	export CARGO_HOME=$sourceDir/../cargo
137
	export ZSTD_SYS_USE_PKG_CONFIG=1
138
	cargo test --release --frozen -p {port["test"]}
139
}}''')
140
print("\n".join(out))