# The "install_test" target installs the subplot binary so that
# $(SUBPLOT) refers to it. This lets us run Subplot without invoking
# "cargo run" every time. This means we invoke in a way that's more
# natural and have to jump through fewer hoops. Also the binary can be
# run from Python tests directly.

SUBPLOT_DIR = $(abspath inst)

# Individual tests run by `test` or `fast-test` targets.
TESTS =

# Set this to "--offline --locked" to build offline.
OFFLINE = 

# Cargo target architecture.
TARGET =

ifdef TARGET
TARGET_ARG = --target $(TARGET)
else
TARGET_ARG =
endif

all: check build test doc shear

check:
	cargo clippy --workspace --all-targets -- -Dwarnings
	RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace
	cargo deny check -Dwarnings

build:
	cargo build --all-targets --workspace
	subplot docgen ci-broker.subplot -o ci-broker.html

install_test_binary:
	rm -rf "$(SUBPLOT_DIR)"
	cargo install $(TARGET_ARG) --locked $(OFFLINE) --path=. --root="$(SUBPLOT_DIR)" --debug
	mv "$(SUBPLOT_DIR)"/bin/* "$(SUBPLOT_DIR)"
	rm -rf "$(SUBPLOT_DIR)"/.crate*  "$(SUBPLOT_DIR)"/bin

fast-test: install_test_binary build
	env SUBPLOT_DIR="$(SUBPLOT_DIR)" timeout 60 cargo test --workspace -- --skip upgrades $(TESTS)

test: fast-test
	env SUBPLOT_DIR="$(SUBPLOT_DIR)" timeout 300 cargo test --workspace -- $(TESTS)

.PHONY: doc
doc:
	make -C doc

semver:
	cargo semver-checks

shear:
	cargo shear
