|
| 1 | +# Lint, format, build and test every example. `make check` is what CI runs. |
| 2 | +# Each per-language target needs only that language's toolchain. |
| 3 | + |
| 4 | +PYTHON_DIRS := weather-server-python mcp-client-python |
| 5 | +TS_DIRS := weather-server-typescript mcp-client-typescript tests/helpers |
| 6 | +GO_DIRS := weather-server-go mcp-client-go |
| 7 | +RUST_DIRS := weather-server-rust mcp-client-rust |
| 8 | +RUBY_FILES := weather-server-ruby/weather.rb mcp-client-ruby/client.rb |
| 9 | + |
| 10 | +.PHONY: help check lint fmt build test \ |
| 11 | + lint-python lint-typescript lint-go lint-rust lint-ruby \ |
| 12 | + fmt-python fmt-go fmt-rust \ |
| 13 | + build-typescript build-go build-rust |
| 14 | + |
| 15 | +help: |
| 16 | + @echo "make check lint, then build and run the smoke tests" |
| 17 | + @echo "make lint check formatting and lint every example" |
| 18 | + @echo "make fmt format Python, Go and Rust in place" |
| 19 | + @echo "make build rebuild the TypeScript, Go and Rust examples" |
| 20 | + @echo "make test rebuild, then run tests/smoke-test.sh" |
| 21 | + @echo "Per language: lint-{python,typescript,go,rust,ruby}," |
| 22 | + @echo " fmt-{python,go,rust}, build-{typescript,go,rust}" |
| 23 | + |
| 24 | +# Lint first, then test, even under `make -j`: both install npm packages. |
| 25 | +check: lint |
| 26 | + $(MAKE) test |
| 27 | + |
| 28 | +lint: lint-python lint-typescript lint-go lint-rust lint-ruby |
| 29 | + |
| 30 | +fmt: fmt-python fmt-go fmt-rust |
| 31 | + |
| 32 | +build: build-typescript build-go build-rust |
| 33 | + |
| 34 | +# smoke-test.sh builds only what is missing, so rebuild first to avoid |
| 35 | +# testing stale binaries. |
| 36 | +test: build |
| 37 | + ./tests/smoke-test.sh |
| 38 | + |
| 39 | +lint-python: |
| 40 | + @set -e; for d in $(PYTHON_DIRS); do \ |
| 41 | + echo "== ruff $$d"; \ |
| 42 | + uv --directory $$d run --quiet ruff check .; \ |
| 43 | + uv --directory $$d run --quiet ruff format --check .; \ |
| 44 | + done |
| 45 | + |
| 46 | +fmt-python: |
| 47 | + @set -e; for d in $(PYTHON_DIRS); do \ |
| 48 | + uv --directory $$d run --quiet ruff check --fix .; \ |
| 49 | + uv --directory $$d run --quiet ruff format .; \ |
| 50 | + done |
| 51 | + |
| 52 | +lint-typescript: |
| 53 | + @set -e; for d in $(TS_DIRS); do \ |
| 54 | + echo "== tsc $$d"; \ |
| 55 | + [ -d $$d/node_modules ] || npm --prefix $$d ci --silent; \ |
| 56 | + (cd $$d && npx tsc --noEmit); \ |
| 57 | + done |
| 58 | + |
| 59 | +build-typescript: |
| 60 | + @set -e; for d in $(TS_DIRS); do \ |
| 61 | + [ -d $$d/node_modules ] || npm --prefix $$d ci --silent; \ |
| 62 | + npm --prefix $$d run --silent build; \ |
| 63 | + done |
| 64 | + |
| 65 | +lint-go: |
| 66 | + @set -e; for d in $(GO_DIRS); do \ |
| 67 | + echo "== gofmt, go vet $$d"; \ |
| 68 | + unformatted=$$(cd $$d && gofmt -l .); \ |
| 69 | + if [ -n "$$unformatted" ]; then echo "needs gofmt: $$unformatted"; exit 1; fi; \ |
| 70 | + (cd $$d && go vet ./...); \ |
| 71 | + done |
| 72 | + |
| 73 | +fmt-go: |
| 74 | + @set -e; for d in $(GO_DIRS); do (cd $$d && gofmt -w .); done |
| 75 | + |
| 76 | +# The binary names are the ones smoke-test.sh runs. `go build -o` adds no |
| 77 | +# `.exe` on Windows, so add it to replace the binary the smoke tests pick. |
| 78 | +build-go: |
| 79 | + cd weather-server-go && go build -o server$$(go env GOEXE) . |
| 80 | + cd mcp-client-go && go build -o mcp-client-go$$(go env GOEXE) . |
| 81 | + |
| 82 | +lint-rust: |
| 83 | + @set -e; for d in $(RUST_DIRS); do \ |
| 84 | + echo "== rustfmt, clippy $$d"; \ |
| 85 | + (cd $$d && cargo fmt --check && cargo clippy --quiet --all-targets -- -D warnings); \ |
| 86 | + done |
| 87 | + |
| 88 | +fmt-rust: |
| 89 | + @set -e; for d in $(RUST_DIRS); do (cd $$d && cargo fmt); done |
| 90 | + |
| 91 | +build-rust: |
| 92 | + @set -e; for d in $(RUST_DIRS); do (cd $$d && cargo build --quiet --release); done |
| 93 | + |
| 94 | +# `ruby -wc` exits 0 even when it prints warnings, so fail on the output. |
| 95 | +lint-ruby: |
| 96 | + @set -e; for f in $(RUBY_FILES); do \ |
| 97 | + echo "== ruby -wc $$f"; \ |
| 98 | + out=$$(ruby -wc $$f 2>&1) || { echo "$$out"; exit 1; }; \ |
| 99 | + echo "$$out"; \ |
| 100 | + if echo "$$out" | grep -q 'warning:'; then exit 1; fi; \ |
| 101 | + done |
0 commit comments