@@ -0,0 +1,95 @@ |
| 1 | +# Makefile for sultree |
| 2 | +# A SELinux-aware tree command |
| 3 | + |
| 4 | +PYTHON = python3 |
| 5 | +PACKAGE = sultree |
| 6 | +VERSION = 0.1.0 |
| 7 | + |
| 8 | +.PHONY: help build install test clean dist rpm dev-install check format |
| 9 | + |
| 10 | +help: |
| 11 | + @echo "Available targets:" |
| 12 | + @echo " build - Build the package" |
| 13 | + @echo " install - Install the package" |
| 14 | + @echo " dev-install - Install in development mode" |
| 15 | + @echo " test - Run tests" |
| 16 | + @echo " check - Run code quality checks" |
| 17 | + @echo " format - Format code" |
| 18 | + @echo " clean - Clean build artifacts" |
| 19 | + @echo " dist - Create distribution package" |
| 20 | + @echo " rpm - Build RPM package" |
| 21 | + |
| 22 | +build: |
| 23 | + $(PYTHON) -m build |
| 24 | + |
| 25 | +install: |
| 26 | + $(PYTHON) -m pip install . |
| 27 | + |
| 28 | +dev-install: |
| 29 | + $(PYTHON) -m pip install -e .[dev] |
| 30 | + |
| 31 | +test: |
| 32 | + PYTHONPATH=src $(PYTHON) -m unittest discover tests -v |
| 33 | + |
| 34 | +check: |
| 35 | + @echo "Running security checks..." |
| 36 | + @command -v bandit >/dev/null 2>&1 && bandit -r src/ || echo "bandit not available - install with: pip install bandit" |
| 37 | + @echo "Running type checking..." |
| 38 | + @command -v mypy >/dev/null 2>&1 && mypy src/ || echo "mypy not available - install with: pip install mypy" |
| 39 | + @echo "Running lint checks..." |
| 40 | + @command -v flake8 >/dev/null 2>&1 && flake8 src/ || echo "flake8 not available - install with: pip install flake8" |
| 41 | + |
| 42 | +format: |
| 43 | + @command -v black >/dev/null 2>&1 && black src/ tests/ || echo "black not available - install with: pip install black" |
| 44 | + |
| 45 | +clean: |
| 46 | + rm -rf build/ |
| 47 | + rm -rf dist/ |
| 48 | + rm -rf src/$(PACKAGE).egg-info/ |
| 49 | + find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true |
| 50 | + find . -type f -name "*.pyc" -delete |
| 51 | + find . -type f -name "*.pyo" -delete |
| 52 | + rm -f $(PACKAGE)-$(VERSION).tar.gz |
| 53 | + |
| 54 | +dist: clean |
| 55 | + $(PYTHON) -m build |
| 56 | + tar czf $(PACKAGE)-$(VERSION).tar.gz \ |
| 57 | + --exclude='.git*' \ |
| 58 | + --exclude='*.pyc' \ |
| 59 | + --exclude='__pycache__' \ |
| 60 | + --exclude='build' \ |
| 61 | + --exclude='dist' \ |
| 62 | + --transform 's,^,$(PACKAGE)-$(VERSION)/,' \ |
| 63 | + src/ tests/ *.py *.toml *.md *.spec Makefile sultree |
| 64 | + |
| 65 | +rpm: dist |
| 66 | + @echo "Building RPM package..." |
| 67 | + @command -v rpmbuild >/dev/null 2>&1 || (echo "rpmbuild not available - install rpm-build package" && exit 1) |
| 68 | + mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} |
| 69 | + cp $(PACKAGE)-$(VERSION).tar.gz ~/rpmbuild/SOURCES/ |
| 70 | + cp $(PACKAGE).spec ~/rpmbuild/SPECS/ |
| 71 | + rpmbuild -ba ~/rpmbuild/SPECS/$(PACKAGE).spec |
| 72 | + @echo "RPM packages created in ~/rpmbuild/RPMS/" |
| 73 | + |
| 74 | +# Performance testing |
| 75 | +perf-test: |
| 76 | + @echo "Running performance tests..." |
| 77 | + @time ./sultree -L 2 /usr >/dev/null |
| 78 | + @echo "Testing with SELinux filtering..." |
| 79 | + @time ./sultree -S "*_t" -L 2 /etc >/dev/null |
| 80 | + |
| 81 | +# Cache performance info |
| 82 | +cache-info: |
| 83 | + @$(PYTHON) -c "import sys; sys.path.insert(0, 'src'); from sultree.selinux import get_cache_info; info = get_cache_info(); print('SELinux Context Cache Performance:'); print(f' Hits: {info[\"context_cache\"][\"hits\"]}'); print(f' Misses: {info[\"context_cache\"][\"misses\"]}'); print(f' Hit Rate: {info[\"context_cache\"][\"hit_rate\"]:.2%}'); print(f' Current Size: {info[\"context_cache\"][\"currsize\"]}/{info[\"context_cache\"][\"maxsize\"]}')" |
| 84 | + |
| 85 | +# Smoke test - basic functionality verification |
| 86 | +smoke-test: |
| 87 | + @echo "Running smoke tests..." |
| 88 | + @./sultree --version |
| 89 | + @./sultree --help >/dev/null |
| 90 | + @./sultree -L 1 . >/dev/null && echo "✓ Basic tree functionality works" |
| 91 | + @./sultree -d -L 1 /etc >/dev/null && echo "✓ Directory-only mode works" |
| 92 | + @./sultree -S "*_t" -L 1 /etc >/dev/null && echo "✓ SELinux filtering works" || echo "⚠ SELinux filtering may not be available" |
| 93 | + @echo "All smoke tests passed!" |
| 94 | + |
| 95 | +all: clean build test check |