joeylib2/installer/components/haikuTools.sh
2026-10-13 14:01:46 -05:00

87 lines
4.1 KiB
Bash

# Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
# See LICENSE.md for license information.
# SPDX-License-Identifier: MIT
#
# Haiku's own build-host tools, built from the R1/beta6 source: package
# (unpacks .hpkg packages: the Haiku sysroots are made from them) and
# bfs_shell (reads and writes Be File System volumes: the Haiku VM images
# get their job runner through it, and the gates hand programs to the VM
# and take results back on a BFS disk). jam, which builds them, comes from
# Haiku's buildtools at the same release. Installed into
# toolchains/opt/haikuTools; bin/ holds wrappers that find the tools'
# libraries.
compDescription="haiku: Haiku R1/beta6 host tools (package, bfs_shell; also read BeOS volumes)"
compGroups="toolchain:haiku toolchain:haiku32 toolchain:beos emulator:haiku emulator:haiku32 emulator:beos"
compRequires="host"
compHostDeps="build-tools git python3 zlib-dev zstd-dev bison flex"
compUrl="https://github.com/haiku/haiku.git"
compCommit="f6d86031a107e16f4fff6814e9aea20a39450842"
buildtoolsUrl="https://github.com/haiku/buildtools.git"
buildtoolsCommit="bfa561e3708c0e2d0155fb403b988ba515c9b16d"
compPin="$compCommit:$buildtoolsCommit"
hostTools="bfs_shell package"
compInstall() {
local src
local objects
local tool
src="$(freshBuildDir "$compId")"
gitFetchCommit "$compUrl" "$compCommit" "$src/haiku"
# Only jam is wanted from buildtools (the rest is the compilers'
# sources, gigabytes of them).
mkdir -p "$src/buildtools"
git -C "$src/buildtools" init -q
git -C "$src/buildtools" remote add origin "$buildtoolsUrl"
git -C "$src/buildtools" fetch -q --depth=1 --filter=blob:none origin "$buildtoolsCommit" || die "could not fetch $buildtoolsCommit from $buildtoolsUrl"
git -C "$src/buildtools" sparse-checkout set jam
git -C "$src/buildtools" checkout -q -f --detach FETCH_HEAD
make -C "$src/buildtools/jam" -j"$JOEY_JOBS"
mkdir -p "$src/haiku/generated"
(cd "$src/haiku/generated" && ../configure --host-only)
# The tools keep the attributes of the host's files (which have none
# here) in a folder named when they are built: theirs, not the build
# tree's, which goes.
(cd "$src/haiku/generated" && PATH="$src/buildtools/jam/bin.linuxx86:$PATH" jam -q -j"$JOEY_JOBS" -sHAIKU_BUILD_ATTRIBUTES_DIR="$compDir/attributes" '<build>bfs_shell' '<build>package')
objects="$src/haiku/generated/objects/linux"
rm -rf "$compDir"
mkdir -p "$compDir/bin" "$compDir/libexec" "$compDir/lib" "$compDir/attributes"
cp "$objects"/lib/*.so "$compDir/lib/"
for tool in $hostTools; do
cp "$(find "$objects" -type f -name "$tool" -perm -u+x -print -quit)" "$compDir/libexec/$tool"
printf '#!/bin/sh\n# Haiku build-host tool: its libraries are in ../lib.\ndir="$(cd "$(dirname "$0")/.." && pwd)"\nLD_LIBRARY_PATH="$dir/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" exec "$dir/libexec/%s" "$@"\n' "$tool" > "$compDir/bin/$tool"
chmod +x "$compDir/bin/$tool"
done
dropBuildDir "$compId"
}
compInstalled() {
[ -x "$compDir/bin/bfs_shell" ] && [ -x "$compDir/bin/package" ] && [ -x "$compDir/libexec/bfs_shell" ] && [ -x "$compDir/libexec/package" ] && [ -d "$compDir/attributes" ]
}
# Make a small BFS volume, write a file onto it and read it back; package
# starts. (Outputs are captured, not piped into grep: under pipefail a tool's
# own exit status, or SIGPIPE from an early grep, would fail the check.)
compVerify() {
local tmp
local readBack
local usage
tmp="$(mktemp -d)"
printf 'JoeyLib\n' > "$tmp/in.txt"
truncate -s 8M "$tmp/v.img"
"$compDir/bin/bfs_shell" --initialize "$tmp/v.img" Check > /dev/null 2>&1 || true
# After a copy, quit reports the volume busy; sync has written it.
printf 'cp :%s /myfs/in.txt\nsync\nquit\n' "$tmp/in.txt" | "$compDir/bin/bfs_shell" "$tmp/v.img" > /dev/null 2>&1 || true
readBack="$(printf 'cat /myfs/in.txt\nquit\n' | "$compDir/bin/bfs_shell" "$tmp/v.img" 2>&1 || true)"
usage="$("$compDir/bin/package" 2>&1 || true)"
rm -rf "$tmp"
[[ "$readBack" == *JoeyLib* && "$usage" == *"Usage: package"* ]]
}
compEnv() {
envVar HAIKU_TOOLS "$compDir/bin"
}