joeylib2/installer/components/host.sh

67 lines
2.4 KiB
Bash

# Host tools every JoeyLib setup needs: a native compiler for the in-repo
# tools, GNU make, git with LFS (the sample assets live in LFS), the
# archive tools the other components unpack with, and Python 3 with
# Pillow for the asset converters.
compDescription="host tools: make, host compiler, git-lfs, python3 + Pillow, archivers"
# Not in any port group: every other component requires it.
compGroups="host"
compRequires=""
compHostDeps="build-tools make git git-lfs curl tar xz bzip2 unzip lhasa python3 python3-pil procps diffutils"
compPin="1"
# Print the LFS-tracked files that are still pointer stubs.
lfsPointerFiles() {
local file
local names
local start
names="$(git -C "$JOEY_REPO" lfs ls-files --name-only 2>/dev/null || true)"
while IFS= read -r file; do
[ -n "$file" ] || continue
# A pointer stub starts with this 23-byte line; read just that much
# (binary assets hold NUL bytes a command substitution would warn about).
start=""
IFS= read -r -N 23 start < "$JOEY_REPO/$file" 2>/dev/null || true
if [[ "$start" == "version https://git-lfs"* ]]; then
printf '%s\n' "$file"
fi
done <<< "$names"
}
compInstall() {
mkdir -p "$compDir"
# A clone made without git-lfs holds pointer stubs instead of the
# sample assets; fetch the real files only in that case.
if [ -d "$JOEY_REPO/.git" ] && [ -n "$(lfsPointerFiles)" ]; then
info "fetching Git LFS assets"
git -C "$JOEY_REPO" lfs install --local
git -C "$JOEY_REPO" lfs pull
fi
}
compInstalled() {
command -v make >/dev/null && command -v cc >/dev/null && command -v python3 >/dev/null && command -v git-lfs >/dev/null
}
compVerify() {
local makeVersion
local stubs
# No pipes into head here: under pipefail an early-exiting reader makes
# the writer die of SIGPIPE, and the check fails at random.
makeVersion="$(make --version 2>/dev/null || true)"
[[ "$makeVersion" =~ ([0-9]+\.[0-9]+) ]] && makeVersion="${BASH_REMATCH[1]}"
# Grouped targets (&:) in the port makefiles need GNU make 4.3.
printf '%s\n4.3\n' "$makeVersion" | sort -V -C -r || { warn "GNU make $makeVersion is older than 4.3"; return 1; }
python3 -c 'import PIL' || { warn "python3 cannot import PIL (Pillow)"; return 1; }
stubs="$(lfsPointerFiles | wc -l)"
[ "$stubs" = "0" ] || { warn "$stubs Git LFS files are still pointer stubs"; return 1; }
}
compEnv() {
:
}