OXYGENHUB
◆ main 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) 6 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"]}"')
cea2e2f8 Andy McCall ↶ 62
w('COPYRIGHT="2026 Andy McCall"')
a42f9fb4 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'''
34c777f8 Andy McCall ↶ 74
ARCHITECTURES="!all x86_64"
a42f9fb4 Andy McCall ↶ 75
76
PROVIDES="
04534029 Andy McCall ↶ 77
	{name}$secondaryArchSuffix = $portVersion
78
	cmd:{name}
a42f9fb4 Andy McCall ↶ 79
	"
80
REQUIRES="
81
	haiku$secondaryArchSuffix
82
	lib:libzstd$secondaryArchSuffix
83
	"
84
85
BUILD_REQUIRES="
04534029 Andy McCall ↶ 86
	haiku${{secondaryArchSuffix}}_devel
a42f9fb4 Andy McCall ↶ 87
	devel:libzstd$secondaryArchSuffix
88
	"
89
BUILD_PREREQUIRES="
90
	cmd:gcc$secondaryArchSuffix
91
	cmd:pkg_config$secondaryArchSuffix
34c777f8 Andy McCall ↶ 92
	cmd:rustc$secondaryArchSuffix
a42f9fb4 Andy McCall ↶ 93
	"
94
95
BUILD()
04534029 Andy McCall ↶ 96
{{
a42f9fb4 Andy McCall ↶ 97
	export CARGO_HOME=$sourceDir/../cargo
98
	vendor=$CARGO_HOME/haiku
99
	mkdir -p "$vendor"
04534029 Andy McCall ↶ 100
	for i in $(seq 2 {last}); do
a42f9fb4 Andy McCall ↶ 101
		eval "srcDir=\\$sourceDir$i"
102
		eval "sha256sum=\\$CHECKSUM_SHA256_$i"
103
		set -- "$srcDir"/*
104
		ln -sf "$1" "$vendor"
04534029 Andy McCall ↶ 105
		cat <<-EOF >"$vendor/${{1##*/}}/.cargo-checksum.json"
106
		{{
a42f9fb4 Andy McCall ↶ 107
		  "package": "$sha256sum",
04534029 Andy McCall ↶ 108
		  "files": {{}}
109
		}}
a42f9fb4 Andy McCall ↶ 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
04534029 Andy McCall ↶ 124
	cargo build --release --frozen -p {port["package"]}
125
}}
a42f9fb4 Andy McCall ↶ 126
127
INSTALL()
04534029 Andy McCall ↶ 128
{{
a42f9fb4 Andy McCall ↶ 129
	install -v -m 755 -d "$prefix"/bin "$docDir"
04534029 Andy McCall ↶ 130
	install -v -m 755 ./target/release/{name} "$prefix"/bin
131
	install -v -m 644 {port["docs"]} "$docDir"
132
}}
a42f9fb4 Andy McCall ↶ 133
134
TEST()
04534029 Andy McCall ↶ 135
{{
a42f9fb4 Andy McCall ↶ 136
	export CARGO_HOME=$sourceDir/../cargo
137
	export ZSTD_SYS_USE_PKG_CONFIG=1
04534029 Andy McCall ↶ 138
	cargo test --release --frozen -p {port["test"]}
139
}}''')
a42f9fb4 Andy McCall ↶ 140
print("\n".join(out))