Makefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. .PHONY: build build-freebsd-amd64 build-freebsd-arm64 test test-v test-cover bench clean fmt lint version sqllogictest sqllogictest-basic sqllogictest-download build-sqllogictest install uninstall
  2. PREFIX ?= /usr/local
  3. GIT_VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
  4. GIT_COMMIT := $(shell git rev-parse --short=12 HEAD 2>/dev/null || echo unknown)
  5. GIT_DATE := $(shell git show -s --format=%cI HEAD 2>/dev/null || echo unknown)
  6. LDFLAGS := -X github.com/danfragoso/pizzasql-next/pkg/version.Version=$(GIT_VERSION) -X github.com/danfragoso/pizzasql-next/pkg/version.Commit=$(GIT_COMMIT) -X github.com/danfragoso/pizzasql-next/pkg/version.Date=$(GIT_DATE)
  7. # Build the project
  8. build:
  9. go build -ldflags "$(LDFLAGS)" -o ./bin/pizzasql ./main.go
  10. # Install pizzasql to PREFIX/bin (default: /usr/local/bin)
  11. install: build
  12. sudo install -d $(DESTDIR)$(PREFIX)/bin
  13. sudo install -m 755 ./bin/pizzasql $(DESTDIR)$(PREFIX)/bin/pizzasql
  14. @echo "Installed to $(DESTDIR)$(PREFIX)/bin/pizzasql"
  15. # Remove installed binary
  16. uninstall:
  17. sudo rm -f $(DESTDIR)$(PREFIX)/bin/pizzasql
  18. @echo "Removed $(DESTDIR)$(PREFIX)/bin/pizzasql"
  19. build-linux-amd64:
  20. GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./bin/pizzasql-linux-amd64 ./main.go
  21. build-freebsd-amd64:
  22. GOOS=freebsd GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./bin/pizzasql-freebsd-amd64 ./main.go
  23. build-freebsd-arm64:
  24. GOOS=freebsd GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o ./bin/pizzasql-freebsd-arm64 ./main.go
  25. # Print the version that a tag build would embed (git describe, commit-hash fallback).
  26. version:
  27. @echo "$(GIT_VERSION)"
  28. # Run all tests
  29. test:
  30. go test ./...
  31. # Run the pChat-style compatibility suite and write a JSON report. Strict mode
  32. # treats missing capabilities as failures and is intended for release gates.
  33. compat:
  34. PIZZASQL_COMPAT=1 \
  35. PIZZASQL_COMPAT_STRICT=$${PIZZASQL_COMPAT_STRICT:-0} \
  36. PIZZASQL_COMPAT_REPORT=$${PIZZASQL_COMPAT_REPORT:-$(CURDIR)/compat-report.json} \
  37. go test ./pkg/pgserver -run TestCompatibilitySuite -v
  38. # Run tests with verbose output
  39. test-v:
  40. go test -v ./...
  41. # Run tests with coverage
  42. test-cover:
  43. go test -coverprofile=coverage.out ./...
  44. go tool cover -html=coverage.out -o coverage.html
  45. @echo "Coverage report: coverage.html"
  46. # Run benchmarks
  47. bench:
  48. go test -bench=. -benchmem ./...
  49. # Run lexer tests only
  50. test-lexer:
  51. go test -v ./pkg/lexer/...
  52. # Run parser tests only
  53. test-parser:
  54. go test -v ./pkg/parser/...
  55. # Format code
  56. fmt:
  57. go fmt ./...
  58. # Run linter (requires golangci-lint)
  59. lint:
  60. golangci-lint run
  61. # Clean build artifacts
  62. clean:
  63. rm -f pizzasql coverage.out coverage.html
  64. # Run tests with race detection
  65. test-race:
  66. go test -race ./...
  67. # Quick test for development
  68. quick:
  69. go test -short ./...
  70. # ── sqllogictest ──────────────────────────────────────────────────────────────
  71. # Run the sqllogictest suite against a running PizzaSQL server (default: localhost:8080).
  72. # Set URL= to point at a different server, e.g. make sqllogictest URL=http://host:9090
  73. sqllogictest:
  74. go run ./cmd/sqllogictest -url $(or $(URL),http://localhost:8080) -dir testdata/sqllogictest -log sqllogictest-failures.log
  75. # Run only the built-in smoke test.
  76. sqllogictest-basic:
  77. go run ./cmd/sqllogictest -url $(or $(URL),http://localhost:8080) -file testdata/sqllogictest/basic.test
  78. # Download the official SQLite sqllogictest corpus into testdata/sqllogictest/.
  79. # Requires curl and tar. Files are not committed to the repo.
  80. sqllogictest-download:
  81. @echo "Downloading SQLite sqllogictest corpus..."
  82. mkdir -p testdata/sqllogictest
  83. mkdir -p /tmp/sqllogictest-dl
  84. curl -fsSL https://github.com/gregrahn/sqllogictest/archive/refs/heads/master.tar.gz \
  85. | tar xz -C /tmp/sqllogictest-dl
  86. find /tmp/sqllogictest-dl -name '*.test' | while read f; do \
  87. rel=$$(echo "$$f" | sed 's|.*/test/||'); \
  88. dir=testdata/sqllogictest/$$(dirname "$$rel"); \
  89. mkdir -p "$$dir"; \
  90. cp "$$f" "$$dir/"; \
  91. done
  92. rm -rf /tmp/sqllogictest-dl
  93. @echo "Done. $$(find testdata/sqllogictest -name '*.test' | wc -l | tr -d ' ') test files in testdata/sqllogictest/"
  94. # Build the sqllogictest runner binary.
  95. build-sqllogictest:
  96. go build -o ./bin/sqllogictest ./cmd/sqllogictest