Makefile 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. .PHONY: lint test install clean
  2. # Lua 5.1 lint + runtime test pipeline
  3. # Run: make lint test
  4. LUA_FILES := $(shell find src tests -name '*.lua' 2>/dev/null)
  5. LUA51 := lua5.1
  6. LINT_SCRIPT := $(shell find /root/.openclaw/workspace/skills/lua51-openwrt-lint/scripts -name 'lint.py' 2>/dev/null | head -1)
  7. TESTBED_SCRIPTS := $(shell find /root/.openclaw/workspace/skills/openwrt-testbed/scripts -name '*.sh' 2>/dev/null)
  8. TESTBED := $(shell echo "$$(dirname $$(dirname $(TESTBED_SCRIPTS)))" 2>/dev/null)
  9. # ------------------------------------------------------------------
  10. # Lint — parse check + feature scan (fast, no Docker)
  11. # ------------------------------------------------------------------
  12. lint:
  13. @echo "=== Lua 5.1 / OpenWrt Lint ==="
  14. @for f in $(LUA_FILES); do \
  15. echo "checking $$f"; \
  16. $(LUA51) -p "$$f" 2>&1 | grep -v "^$" && echo " PARSE FAIL $$f" && exit 1 || true; \
  17. done
  18. @echo " parse: all OK"
  19. @echo ""
  20. @if [ -x "$(LINT_SCRIPT)" ]; then \
  21. python3 $(LINT_SCRIPT) . 2>&1 | head -60; \
  22. else \
  23. echo "lint.py not found — skipping feature scan (install lua51-openwrt-lint skill)"; \
  24. fi
  25. @echo ""
  26. @echo "lint: OK"
  27. # ------------------------------------------------------------------
  28. # Test on OpenWrt 19.07.7 testbed (Docker, ~2-5s overhead)
  29. # ------------------------------------------------------------------
  30. TEST_FILE ?= tests/smoke.lua
  31. test:
  32. @echo "=== OpenWrt Testbed runtime check ==="
  33. @if [ ! -x "$(TESTBED_SCRIPTS)/test.sh" ]; then \
  34. echo "testbed not found — skipping runtime tests"; \
  35. echo "(install openwrt-testbed skill first)"; \
  36. exit 0; \
  37. fi
  38. @echo "using testbed: $(TESTBED)"
  39. $(TESTBED_SCRIPTS)/test.sh $(TEST_FILE) --assert "OK" 2>&1 | tail -20
  40. @echo "=== done ==="
  41. # ------------------------------------------------------------------
  42. # Test a specific file
  43. # ------------------------------------------------------------------
  44. test-file:
  45. @$(TESTBED_SCRIPTS)/test.sh $(TEST_FILE) --assert "OK" 2>&1 | tail -20
  46. # ------------------------------------------------------------------
  47. # Run unit tests (plain Lua, no Docker needed for logic-only tests)
  48. # ------------------------------------------------------------------
  49. unit:
  50. @echo "=== Unit tests (plain Lua) ==="
  51. @for t in tests/test_*.lua; do \
  52. echo "running $$t"; \
  53. $(LUA51) $$t 2>&1 | grep -E '(PASS|FAIL|ERROR|OK)' | head -5; \
  54. done
  55. # ------------------------------------------------------------------
  56. # Install to local staging dir (for SDK packaging)
  57. # ------------------------------------------------------------------
  58. DESTDIR ?= /tmp/balancerlite-staging
  59. PREFIX ?= /usr
  60. install:
  61. install -d $(DESTDIR)$(PREFIX)/lib/lua/5.1/balancerlite/
  62. install -d $(DESTDIR)$(PREFIX)/bin/
  63. install -d $(DESTDIR)/etc/config/
  64. install -d $(DESTDIR)/etc/init.d/
  65. install -m 0644 src/balancerlite/*.lua $(DESTDIR)$(PREFIX)/lib/lua/5.1/balancerlite/
  66. install -m 0755 src/balancerlite/main.lua $(DESTDIR)$(PREFIX)/bin/balancerlite
  67. install -m 0644 etc/config/balancerlite $(DESTDIR)/etc/config/
  68. install -m 0755 etc/init.d/balancerlite $(DESTDIR)/etc/init.d/
  69. @echo "installed to $(DESTDIR)"
  70. clean:
  71. @echo "nothing to clean (no build artifacts)"
  72. .PHONY: lint test unit install clean test-file