Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
136 lines (104 loc) · 5.69 KB
/
Copy pathMakefile
File metadata and controls
136 lines (104 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# pybmap monorepo — build, test, and publish for Python, Rust, and C++
.PHONY: help all test lint clean \
python-setup python-test python-lint python-build python-publish \
rust-test rust-build rust-publish rust-secret \
cpp-test cpp-build \
integration \
artifacts release
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
all: python-test rust-test cpp-test ## Run all tests
# ── Python ───────────────────────────────────────────────────────────────────
PYTHON_DIR = python
VENV = $(PYTHON_DIR)/.venv
PIP = $(VENV)/bin/pip
PYTEST = $(VENV)/bin/pytest
PYTHON = $(VENV)/bin/python
$(VENV)/bin/activate:
python3 -m venv $(VENV)
$(PIP) install -q --upgrade pip
$(PIP) install -q pytest
@if [ "$$(uname -s)" = "Darwin" ]; then \
echo "Installing macOS Bluetooth dependencies (PyObjC) in virtualenv..."; \
$(PIP) install -q pyobjc-core pyobjc-framework-Cocoa pyobjc-framework-IOBluetooth; \
fi
python-setup: $(VENV)/bin/activate ## Set up Python virtualenv
$(PIP) install -q -e $(PYTHON_DIR)
python-test: python-setup ## Run Python unit tests
$(PYTEST) $(PYTHON_DIR)/tests/ -v --tb=short
python-lint: python-setup ## Lint Python code
$(PYTHON) -m py_compile $(PYTHON_DIR)/pybmap/__init__.py
$(PYTHON) -m py_compile $(PYTHON_DIR)/pybmap/protocol.py
$(PYTHON) -m py_compile $(PYTHON_DIR)/pybmap/connection.py
$(PYTHON) -m py_compile $(PYTHON_DIR)/pybmap/cli.py
@echo "All Python files compile OK"
python-build: python-setup ## Build Python sdist and wheel
cd $(PYTHON_DIR) && $(PYTHON) -m build
python-publish: python-build ## Publish to PyPI (requires TWINE_PASSWORD)
cd $(PYTHON_DIR) && $(PYTHON) -m twine upload dist/*
# ── Rust ─────────────────────────────────────────────────────────────────────
RUST_DIR = rust
rust-test: ## Run Rust tests
cd $(RUST_DIR) && cargo test
rust-build: ## Build Rust library
cd $(RUST_DIR) && cargo build --release
rust-publish: rust-test ## Publish to crates.io
cd $(RUST_DIR) && cargo publish
# ENV_CRATES holds one line, CARGO_REGISTRY_TOKEN=...; .env* is gitignored.
ENV_CRATES ?= .env.crates
rust-secret: ## Push CARGO_REGISTRY_TOKEN from .env.crates (or ENV_CRATES=path) to GitHub Actions secrets
@test -f "$(ENV_CRATES)" || { echo "$(ENV_CRATES) not found"; exit 1; }
@. "$(abspath $(ENV_CRATES))" && \
{ test -n "$$CARGO_REGISTRY_TOKEN" || { echo "CARGO_REGISTRY_TOKEN empty in $(ENV_CRATES)" >&2; exit 1; }; } && \
printf '%s' "$$CARGO_REGISTRY_TOKEN" | gh secret set CARGO_REGISTRY_TOKEN
# ── C++ ──────────────────────────────────────────────────────────────────────
CPP_DIR = cpp
CPP_BUILD = $(CPP_DIR)/build
cpp-test: cpp-build ## Run C++ tests
cd $(CPP_BUILD) && ctest --output-on-failure
$(CPP_BUILD)/bmap_tests
cpp-build: ## Build C++ library
cmake -S $(CPP_DIR) -B $(CPP_BUILD)
cmake --build $(CPP_BUILD)
# ── Integration Tests ────────────────────────────────────────────────────────
integration: python-setup ## Run integration tests (requires paired BT device)
BMAP_INTEGRATION=1 $(PYTEST) $(PYTHON_DIR)/tests/ -v --tb=short --integration
# ── Cross-Language ───────────────────────────────────────────────────────────
test: python-test rust-test cpp-test ## Run all tests across all languages
lint: python-lint ## Lint all languages
# ── Release Artifacts ────────────────────────────────────────────────────────
ARCH := $(shell uname -m)
DIST = dist
artifacts: rust-build cpp-build ## Build release binaries with checksums
@mkdir -p $(DIST)
cp $(RUST_DIR)/target/release/bmapctl $(DIST)/bmapctl-rust-linux-$(ARCH)
strip $(DIST)/bmapctl-rust-linux-$(ARCH)
cmake -S $(CPP_DIR) -B $(CPP_BUILD) -DCMAKE_BUILD_TYPE=Release
cmake --build $(CPP_BUILD) --config Release
cp $(CPP_BUILD)/bmapctl $(DIST)/bmapctl-cpp-linux-$(ARCH)
strip $(DIST)/bmapctl-cpp-linux-$(ARCH)
cd $(DIST) && sha256sum bmapctl-* > SHA256SUMS
@echo ""
@echo "Artifacts in $(DIST)/:"
@ls -lh $(DIST)/
@echo ""
@cat $(DIST)/SHA256SUMS
release: test artifacts ## Run tests, build artifacts, create GitHub release
@if [ -z "$(VERSION)" ]; then echo "Usage: make release VERSION=v0.2.0"; exit 1; fi
gh release create $(VERSION) \
$(DIST)/bmapctl-rust-linux-$(ARCH) \
$(DIST)/bmapctl-cpp-linux-$(ARCH) \
$(DIST)/SHA256SUMS \
--title "$(VERSION)" \
--generate-notes
@echo ""
@echo "Released $(VERSION):"
@echo " https://github.com/$$(gh repo view --json nameWithOwner -q .nameWithOwner)/releases/tag/$(VERSION)"
# ── Cleanup ─────────────────────────────────────────────────────────────────
clean: ## Remove build artifacts
rm -rf $(VENV) $(PYTHON_DIR)/dist $(PYTHON_DIR)/build $(PYTHON_DIR)/*.egg-info
rm -rf $(PYTHON_DIR)/.pytest_cache $(PYTHON_DIR)/__pycache__
cd $(RUST_DIR) && cargo clean 2>/dev/null || true
rm -rf $(CPP_BUILD)
rm -rf $(DIST)