.PHONY: install-server build check test fmt clippy changelog run ts install deps-check

# Spectra's own packages. `--workspace` and `--all` also reach the pinned
# Oxygen in deps/ (a path dependency), whose tests and lints are its own.
PKGS = -p spectra -p spectra-core -p spectra-mcp -p spectra-api -p radar

build:
	cargo build --release

check: changelog deps-check fmt clippy test

# A code change needs a CHANGELOG.md line (scripts/changelog-check.sh).
changelog:
	scripts/changelog-check.sh

fmt:
	cargo fmt $(PKGS) -- --check

clippy:
	cargo clippy $(PKGS) --all-targets -- -D warnings

test:
	cargo test $(PKGS)

run:
	cargo run -- --data data serve

# TypeScript declarations of the API types, for the VS Code extensions.
ts:
	cargo run -q -p spectra-api --bin spectra-api-typescript > crates/spectra-api/ts/index.d.ts

# Build and install spectra with its build identity (oxy describe) in --version.
install:
	SPECTRA_BUILD="$$(oxy --plain describe 2>/dev/null)" CARGO_INCREMENTAL=0 cargo build --release
	install -D -m 755 $${CARGO_TARGET_DIR:-$(CURDIR)/target}/release/spectra $(HOME)/.local/bin/spectra
	$(HOME)/.local/bin/spectra --version

# The daemon on another machine over SSH (spec §8.6): make install-server HOST=user@host
install-server:
	@test -n "$(HOST)" || { echo "make install-server HOST=[USER@]HOST" >&2; exit 2; }
	scripts/install-server.sh $(HOST)

# Every crate in Cargo.lock must be one the OxygenFlow build image vendors
# (oxygenflow images/rust: the crates of oxygen, oxygenhub and oxygenflow), or
# CI cannot build offline (spectra#2).
deps-check:
	scripts/deps-check.sh
