80 lines
2.7 KiB
Makefile
80 lines
2.7 KiB
Makefile
# Justfile for cc-libs
|
|
# Run `just ci` to verify local tooling and lint Lua code.
|
|
|
|
# List available recipes.
|
|
default:
|
|
@just --list
|
|
|
|
# Install local development tooling.
|
|
install: install-git-hooks check-craftos
|
|
|
|
# Install Git hooks for this repository.
|
|
install-git-hooks:
|
|
@mkdir -p .git/hooks
|
|
@printf '%s\n' '#!/bin/sh' '' 'just ci' > .git/hooks/pre-commit
|
|
@chmod +x .git/hooks/pre-commit
|
|
@printf '%s\n' 'Installed .git/hooks/pre-commit'
|
|
|
|
# Verify the CraftOS-PC harness is installed and recent enough.
|
|
check-craftos:
|
|
@command -v craftos >/dev/null 2>&1 || { \
|
|
printf '%s\n' 'craftos not found on $PATH. See docs/install-craftos-pc.md.' >&2; \
|
|
exit 1; \
|
|
}
|
|
@version="$(craftos --version)"; \
|
|
number="${version##* v}"; \
|
|
case "$number" in \
|
|
*.*.*) \
|
|
;; \
|
|
*) \
|
|
printf '%s\n' "$version"; \
|
|
printf '%s\n' 'Could not parse CraftOS-PC version. See docs/install-craftos-pc.md.' >&2; \
|
|
exit 1; \
|
|
;; \
|
|
esac; \
|
|
major="${number%%.*}"; \
|
|
rest="${number#*.}"; \
|
|
minor="${rest%%.*}"; \
|
|
patch="${rest#*.}"; \
|
|
patch="${patch%%[^0-9]*}"; \
|
|
printf '%s\n' "$version"; \
|
|
case "$major.$minor.$patch" in \
|
|
*[!0-9.]*|.*|*..*|*.) \
|
|
printf '%s\n' 'Could not parse CraftOS-PC version. See docs/install-craftos-pc.md.' >&2; \
|
|
exit 1; \
|
|
;; \
|
|
esac; \
|
|
if ! { [ "${major:-0}" -gt 2 ] || \
|
|
{ [ "${major:-0}" -eq 2 ] && [ "${minor:-0}" -gt 8 ]; } || \
|
|
{ [ "${major:-0}" -eq 2 ] && [ "${minor:-0}" -eq 8 ] && [ "${patch:-0}" -ge 3 ]; }; }; then \
|
|
printf '%s\n' 'CraftOS-PC v2.8.3 or newer is required. See docs/install-craftos-pc.md.' >&2; \
|
|
exit 1; \
|
|
fi
|
|
|
|
# Local CI entry point used by Git hooks. Pass args through to `test`.
|
|
ci *args: check-craftos check
|
|
@just test {{args}}
|
|
|
|
# Run CraftOS-PC headless smoke tests. Pass `--verbose` to list each test.
|
|
test *args:
|
|
@verbose=0; \
|
|
for a in {{args}}; do [ "$a" = "--verbose" ] && verbose=1; done; \
|
|
rom_arg=""; \
|
|
if [ "$(uname -s)" = "Darwin" ]; then \
|
|
rom_arg="--rom /Applications/CraftOS-PC.app/Contents/Resources"; \
|
|
fi; \
|
|
green=$(printf '\033[32m'); reset=$(printf '\033[0m'); red=$(printf '\033[31m'); \
|
|
for script in tests/boot.lua tests/ready.lua; do \
|
|
if craftos --headless $rom_arg --script "$script" | grep -q __READY__; then \
|
|
[ "$verbose" -eq 1 ] && printf '%s\n' "${green}PASS${reset} $script"; \
|
|
else \
|
|
printf '%s\n' "${red}FAIL${reset} $script did not print __READY__" >&2; \
|
|
exit 1; \
|
|
fi; \
|
|
done; \
|
|
printf '%s\n' 'OK: smoke tests passed'
|
|
|
|
# Lint all Lua source with luacheck.
|
|
check:
|
|
luacheck .
|