-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
367 lines (314 loc) · 13.3 KB
/
Makefile
File metadata and controls
367 lines (314 loc) · 13.3 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
.PHONY: all build build-release build-cli build-cli-release build-python build-python-release build-python-dev test test-rust test-python test-examples examples examples-verify coverage coverage-rust coverage-python fmt fmt-python lint lint-python check check-license clean dev-up dev-down bench bench-all fuzz fuzz-all fuzz-init fuzz-build help
# Default target
all: build
# ============================================================================
# Build targets
# ============================================================================
build: ## Build Rust library (debug)
@echo "Building robocodec (debug)..."
cargo build
@echo "✓ Build complete"
build-release: ## Build Rust library (release)
@echo "Building robocodec (release)..."
cargo build --release
@echo "✓ Build complete (release)"
build-cli: ## Build CLI tool (debug)
@echo "Building robocodec-cli (debug)..."
cargo build --package robocodec-cli
@echo "✓ CLI build complete"
build-cli-release: ## Build CLI tool (release)
@echo "Building robocodec-cli (release)..."
cargo build --release --package robocodec-cli
@echo "✓ CLI build complete (release)"
build-python: ## Build Python wheel (debug)
@echo "Building Python wheel..."
maturin build
@echo "✓ Python wheel built (see target/wheels/)"
build-python-release: ## Build Python wheel (release)
@echo "Building Python wheel (release)..."
maturin build --release --strip
@echo "✓ Python wheel built (release, see target/wheels/)"
build-python-dev: ## Install Python package in dev mode (requires virtualenv)
@echo "Installing Python package in dev mode..."
maturin develop --features python
@echo "✓ Python package installed"
# ============================================================================
# Testing
# ============================================================================
test: test-rust ## Run Rust tests
@echo "✓ All tests passed"
test-rust: ## Run Rust tests
@echo "Running Rust tests..."
cargo test
@echo "✓ Rust tests passed"
test-python: ## Run Python tests (builds extension first)
@echo "Building Python extension..."
maturin develop --features python
@echo "Running Python tests..."
pytest tests/python/ -v
@echo "✓ Python tests passed"
test-examples: ## Run Python examples to verify API compatibility (builds extension first)
@echo "Building Python extension..."
maturin develop --features python
@echo ""
@echo "Testing Python examples for API compatibility..."
@echo ""
@$(MAKE) -s test-examples-run
@echo ""
@echo "✓ All examples verified - API is compatible"
test-examples-run:
@# Test 1: Import verification (checks all required classes exist)
@echo "1. Verifying API imports..."
@.venv/bin/python3 -c "import robocodec; required=['RoboReader','RoboWriter','RoboRewriter','TransformBuilder','RobocodecError','ChannelInfo','RewriteStats']; missing=[n for n in required if not hasattr(robocodec, n)]; import sys; sys.exit(1) if missing else print(' ✓ All required classes available')" || { echo " ✗ Import verification failed"; exit 1; }
@# Test 2: Verify examples can be imported (syntax check)
@echo "2. Verifying example scripts syntax..."
@for script in examples/python/*.py; do \
if [ "$$(basename $$script)" != "_example_utils.py" ]; then \
printf " Checking $$(basename $$script)... "; \
if .venv/bin/python3 -m py_compile "$$script" 2>/dev/null; then \
echo "✓"; \
else \
echo "✗"; \
exit 1; \
fi; \
fi; \
done
@# Test 3: Run examples with test fixtures (actual execution)
@echo "3. Running examples with test data..."
@TEST_FILE=$$(ls tests/fixtures/*.mcap 2>/dev/null | head -1); \
if [ -z "$$TEST_FILE" ]; then \
echo " ⚠ No test fixtures found, skipping execution tests"; \
else \
echo " Using: $$TEST_FILE"; \
.venv/bin/python3 examples/python/inspect_mcap.py "$$TEST_FILE" > /dev/null && echo " ✓ inspect_mcap.py" || { echo " ✗ inspect_mcap.py failed"; exit 1; }; \
.venv/bin/python3 examples/python/mcap_stats.py "$$TEST_FILE" > /dev/null && echo " ✓ mcap_stats.py" || { echo " ✗ mcap_stats.py failed"; exit 1; }; \
.venv/bin/python3 examples/python/filter_topics.py "$$TEST_FILE" --list > /dev/null && echo " ✓ filter_topics.py" || { echo " ✗ filter_topics.py failed"; exit 1; }; \
fi
# ============================================================================
# Examples
# ============================================================================
examples: ## Run all Python examples (uses test fixtures)
@echo "Building Python extension..."
maturin develop --features python
@echo ""
@echo "Running Python examples..."
@echo ""
@$(MAKE) -s examples-run
@echo ""
@echo "✓ All examples executed successfully"
examples-run:
@# Find a test fixture to use
@FAILED=0; \
TEST_FILE=$$(ls tests/fixtures/*.mcap 2>/dev/null | head -1); \
if [ -z "$$TEST_FILE" ]; then \
echo "⚠ No test fixtures found. Skipping examples."; \
exit 0; \
fi; \
echo "Using test fixture: $$TEST_FILE"; \
echo ""; \
\
echo "1. inspect_mcap.py..."; \
.venv/bin/python3 examples/python/inspect_mcap.py "$$TEST_FILE" > /dev/null && echo " ✓ Passed" || { echo " ✗ Failed"; FAILED=1; }; \
\
echo ""; \
echo "2. mcap_stats.py..."; \
.venv/bin/python3 examples/python/mcap_stats.py "$$TEST_FILE" > /dev/null && echo " ✓ Passed" || { echo " ✗ Failed"; FAILED=1; }; \
\
echo ""; \
echo "3. filter_topics.py (list mode)..."; \
.venv/bin/python3 examples/python/filter_topics.py "$$TEST_FILE" --list > /dev/null && echo " ✓ Passed" || { echo " ✗ Failed"; FAILED=1; }; \
\
echo ""; \
if [ "$$FAILED" -eq 1 ]; then \
echo "✗ Some examples failed"; \
exit 1; \
else \
echo "✓ All examples verified"; \
fi
examples-verify: ## Verify Python example scripts have correct API imports
@echo "Verifying Python example API usage..."
@for script in examples/python/*.py; do \
if [ "$$(basename $$script)" != "_example_utils.py" ]; then \
echo " Checking $$(basename $$script)..."; \
if .venv/bin/python3 -c "import sys; sys.path.insert(0, 'examples/python'); exec(open('$$script').read().split('def main')[0])" 2>/dev/null; then \
echo " ✓ API imports OK"; \
else \
echo " ⚠ Import check skipped"; \
fi; \
fi; \
done; \
echo "✓ Example verification complete"
# ============================================================================
# Coverage
# ============================================================================
coverage: coverage-rust coverage-python ## Run all tests with coverage
@echo ""
@echo "✓ Coverage reports generated"
@echo " Rust: target/llvm-cov/html/index.html"
@echo " Python: tests/python/htmlcov/index.html"
coverage-rust: ## Run Rust tests with coverage (requires cargo-llvm-cov)
@echo "Running Rust tests with coverage..."
@echo "(Install: cargo install cargo-llvm-cov)"
cargo llvm-cov --workspace --html --output-dir target/llvm-cov/html
cargo llvm-cov --workspace --lcov --output-path lcov.info
@echo ""
@echo "✓ Rust coverage report: target/llvm-cov/html/index.html"
coverage-python: ## Run Python tests with coverage (requires pytest-cov)
@echo "Building Python extension..."
maturin develop --features python
@echo "Running Python tests with coverage..."
pytest tests/python/ --cov=robocodec --cov-report=html --cov-report=term-missing -v
@echo ""
@echo "✓ Python coverage report: tests/python/htmlcov/index.html"
# ============================================================================
# Code quality
# ============================================================================
fmt: fmt-python ## Format all code (Rust + Python)
@echo "Formatting Rust code..."
cargo fmt
@echo "✓ Code formatted"
fmt-python: ## Format Python code (requires black)
@echo "Formatting Python code..."
@if command -v black >/dev/null 2>&1; then \
black python/ tests/python/; \
else \
echo "⚠ black not found. Install with: pip install black"; \
exit 1; \
fi
@echo "✓ Python code formatted"
lint: lint-python ## Lint all code (Rust + Python)
@echo "Linting Rust code with all features..."
cargo clippy --all-targets --all-features -- -D warnings
@echo "✓ Linting passed"
lint-python: ## Lint Python code (requires ruff)
@echo "Linting Python code..."
@if command -v ruff >/dev/null 2>&1; then \
ruff check python/ tests/python/; \
else \
echo "⚠ ruff not found. Install with: pip install ruff"; \
exit 1; \
fi
@echo "✓ Python linting passed"
check: fmt lint ## Run format check and lint
# ============================================================================
# Benchmarks
# ============================================================================
bench: ## Run performance benchmarks ( Criterion)
@echo "Running performance benchmarks..."
cargo bench
@echo ""
@echo "✓ Benchmarks complete"
@echo " View results: open target/criterion/report/index.html"
bench-all: ## Run all benchmarks with verbose output
@echo "Running all benchmarks (verbose)..."
cargo bench -- --verbose
@echo ""
@echo "✓ Benchmarks complete"
bench-save: ## Run benchmarks and save baseline
@echo "Running benchmarks and saving baseline..."
cargo bench -- --save-baseline main
@echo ""
@echo "✓ Baseline saved as 'main'"
bench-compare: ## Compare current performance against saved baseline
@echo "Comparing against baseline..."
cargo bench -- --baseline main
@echo ""
@echo "✓ Comparison complete"
check-license: ## Check REUSE license compliance
@echo "Checking REUSE license compliance..."
@if command -v reuse >/dev/null 2>&1; then \
reuse lint; \
else \
echo "⚠ reuse tool not found. Install with: pip install reuse"; \
exit 1; \
fi
# ============================================================================
# Development
# ============================================================================
dev-up: ## Start MinIO S3 server for local development (ports 9000, 9001)
@echo "Starting MinIO S3 server..."
@docker compose -f docker-compose.dev.yml up -d
@echo ""
@echo "✓ MinIO is running:"
@echo " S3 API: http://localhost:9000"
@echo " Web UI: http://localhost:9001 (minioadmin/minioadmin)"
@echo ""
@echo "Stop with: make dev-down"
dev-down: ## Stop MinIO S3 server
@echo "Stopping MinIO S3 server..."
@docker compose -f docker-compose.dev.yml down
@echo "✓ MinIO stopped"
dev-logs: ## Show MinIO logs
@docker compose -f docker-compose.dev.yml logs -f
dev-status: ## Show MinIO container status
@docker compose -f docker-compose.dev.yml ps
# ============================================================================
# Fuzzing
# ============================================================================
fuzz-init: ## Initialize cargo-fuzz configuration (one-time setup)
@echo "Initializing cargo-fuzz..."
@if ! command -v cargo-fuzz >/dev/null 2>&1; then \
echo "Installing cargo-fuzz..."; \
cargo install cargo-fuzz --locked; \
fi
@rustup install nightly 2>/dev/null || echo "Nightly toolchain already installed"
@echo "✓ Fuzzing infrastructure initialized"
fuzz-build: ## Build all fuzz targets
@echo "Building fuzz targets..."
cargo +nightly fuzz build
@echo "✓ Fuzz targets built"
fuzz: ## Run fuzzers for a short duration (quick check)
@echo "Running fuzzers (quick check)..."
@echo "Fuzzing MCAP parser..."
cargo +nightly fuzz run mcap_parser -- -timeout=10 -max_total_time=30 || true
@echo "Fuzzing ROS1 bag parser..."
cargo +nightly fuzz run bag_parser -- -timeout=10 -max_total_time=30 || true
@echo "Fuzzing CDR decoder..."
cargo +nightly fuzz run cdr_decoder -- -timeout=10 -max_total_time=30 || true
@echo "✓ Quick fuzzing complete (no crashes found)"
fuzz-all: ## Run all fuzz targets for a longer duration
@echo "Running all fuzz targets..."
@for target in mcap_parser bag_parser rrd_parser cdr_decoder schema_parser; do \
echo ""; \
echo "Fuzzing $$target..."; \
cargo +nightly fuzz run "$$target" -- -timeout=10 -max_total_time=60 || true; \
done
@echo ""
@echo "✓ Fuzzing complete"
fuzz-mcap: ## Run MCAP parser fuzzer
@echo "Fuzzing MCAP parser..."
cargo +nightly fuzz run mcap_parser -- -timeout=10 -dict=fuzz/dictionaries/mcap.dict
fuzz-bag: ## Run ROS1 bag parser fuzzer
@echo "Fuzzing ROS1 bag parser..."
cargo +nightly fuzz run bag_parser -- -timeout=10 -dict=fuzz/dictionaries/bag.dict
fuzz-cdr: ## Run CDR decoder fuzzer
@echo "Fuzzing CDR decoder..."
cargo +nightly fuzz run cdr_decoder -- -timeout=10
fuzz-schema: ## Run schema parser fuzzer
@echo "Fuzzing schema parser..."
cargo +nightly fuzz run schema_parser -- -timeout=10 -dict=fuzz/dictionaries/schema.dict
fuzz-cmin-%: ## Minimize corpus for a specific fuzzer
@echo "Minimizing corpus for $*..."
cargo +nightly fuzz cmin $* -- -timeout=30
# ============================================================================
# Utilities
# ============================================================================
clean: ## Clean build artifacts
@echo "Cleaning..."
cargo clean
rm -rf target/
rm -rf **/__pycache__/
rm -rf **/.pytest_cache/
rm -rf tests/python/htmlcov/
rm -rf tests/python/.coverage*
rm -rf *.egg-info/
rm -rf .pytest_cache/
rm -rf coverage-html/
rm -f coverage.xml lcov.info
@echo "✓ Cleaned"
help: ## Show this help message
@echo "Robocodec - Robotics Message Codec"
@echo ""
@echo "Usage: make [target]"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'