osi-tools/Makefile

69 lines
2.7 KiB
Makefile

# Copyright (C) 2018, 2024 Luke Shumaker
# Copyright (C) 2023-2024 Umorpha Systems
# SPDX-License-Identifier: AGPL-3.0-or-later
shell_programs += bin/osi-mk
shell_programs += bin/osi-shell
shell_programs += bin/osi-mount
shell_programs += bin/osi-extract
python_programs += lib/pacman-choices
perl_programs += lib/indent
MAKEFLAGS += --no-builtin-rules
# Lint #########################################################################
lint: $(addsuffix .bash,$(wildcard test/*.bats)) bin/osi-mk.bash
@PS4=; r=0; set -x; { \
shellcheck -- lib/*.sh lib/mk/*.sh $(patsubst bin/osi-mk,bin/osi-mk.bash,$(shell_programs)) || r=$$?; \
shellcheck -x -- test/*.bats.bash || r=$$?; \
MYPYPATH=$$PWD/mypy-stubs mypy --strict $(python_programs) || r=$$?; \
black --check $(python_programs) mypy-stubs || r=$$?; \
isort --check $(python_programs) mypy-stubs || r=$$?; \
diff -u /dev/null <(git grep -L SPDX-License-Identifier: -- $(addprefix :!,$(generate/files))) || r=$$?; \
}; exit $$r
.PHONY: lint
# The `end_indent` alias is osi-mk confuses ShellCheck. The alias
# makes programming nicer-enough that I want to keep it. So,
# preprocess osi-mk to expand the alias before feeding it to
# ShellCheck.
bin/osi-mk.bash: bin/osi-mk
end_indent=$$(sed -En "s/^alias end_indent='(.*)'/\1/p" <$<) && sed -e '/^alias /d' -e "s,end_indent,$${end_indent}," <$< >$@
# Modern versions of ShellCheck now natively support BATS syntax, so
# running the preprocessor ourselves to feed to ShellCheck "should" no
# longer be necessary. However, as of ShellCheck 0.10.0, it doesn't
# know about --separate-stderr and so emits spurious SC2154
# ("referenced but not assigned") warnings about ${stderr} and
# ${stderr_lines[@]}. ShellCheck has already fixed this in 796c6bd
# (Add new bats variables stderr and stderr_lines, 2024-04-24), so we
# only need to keep this around until the next ShellCheck release.
%.bats.bash: %.bats
{ \
echo 'source /usr/lib/bats-core/test_functions.bash'; \
echo 'run() { lines=("bogus"); stderr_lines=("bogus"); }'; \
export BATS_LIBDIR=usr/lib; /$${BATS_LIBDIR}/bats-core/bats-preprocess $<; \
} >$@
# Check ########################################################################
bats_parallel = $(patsubst -j%,-j %,$(patsubst -j,-j$$(nproc),$(filter-out -j1,$(filter -j%,$(MAKEFLAGS)))))
check:
PATH=$(CURDIR)/bin:$$PATH && cd test && sudo true && bats $(bats_parallel) .
.PHONY: check
.NOTPARALLEL: check
# Generate #####################################################################
generate/files = COPYING.txt
COPYING.txt:
curl https://www.gnu.org/licenses/agpl-3.0.txt >$@
generate: $(generate/files)
generate-clean:
rm -f -- $(generate/files)
.PHONY: generate generate-clean