Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 tests with verbose output
  32. test-v:
  33. go test -v ./...
  34. # Run tests with coverage
  35. test-cover:
  36. go test -coverprofile=coverage.out ./...
  37. go tool cover -html=coverage.out -o coverage.html
  38. @echo "Coverage report: coverage.html"
  39. # Run benchmarks
  40. bench:
  41. go test -bench=. -benchmem ./...
  42. # Run lexer tests only
  43. test-lexer:
  44. go test -v ./pkg/lexer/...
  45. # Run parser tests only
  46. test-parser:
  47. go test -v ./pkg/parser/...
  48. # Format code
  49. fmt:
  50. go fmt ./...
  51. # Run linter (requires golangci-lint)
  52. lint:
  53. golangci-lint run
  54. # Clean build artifacts
  55. clean:
  56. rm -f pizzasql coverage.out coverage.html
  57. # Run tests with race detection
  58. test-race:
  59. go test -race ./...
  60. # Quick test for development
  61. quick:
  62. go test -short ./...
  63. # ── sqllogictest ──────────────────────────────────────────────────────────────
  64. # Run the sqllogictest suite against a running PizzaSQL server (default: localhost:8080).
  65. # Set URL= to point at a different server, e.g. make sqllogictest URL=http://host:9090
  66. sqllogictest:
  67. go run ./cmd/sqllogictest -url $(or $(URL),http://localhost:8080) -dir testdata/sqllogictest -log sqllogictest-failures.log
  68. # Run only the built-in smoke test.
  69. sqllogictest-basic:
  70. go run ./cmd/sqllogictest -url $(or $(URL),http://localhost:8080) -file testdata/sqllogictest/basic.test
  71. # Download the official SQLite sqllogictest corpus into testdata/sqllogictest/.
  72. # Requires curl and tar. Files are not committed to the repo.
  73. sqllogictest-download:
  74. @echo "Downloading SQLite sqllogictest corpus..."
  75. mkdir -p testdata/sqllogictest
  76. mkdir -p /tmp/sqllogictest-dl
  77. curl -fsSL https://github.com/gregrahn/sqllogictest/archive/refs/heads/master.tar.gz \
  78. | tar xz -C /tmp/sqllogictest-dl
  79. find /tmp/sqllogictest-dl -name '*.test' | while read f; do \
  80. rel=$$(echo "$$f" | sed 's|.*/test/||'); \
  81. dir=testdata/sqllogictest/$$(dirname "$$rel"); \
  82. mkdir -p "$$dir"; \
  83. cp "$$f" "$$dir/"; \
  84. done
  85. rm -rf /tmp/sqllogictest-dl
  86. @echo "Done. $$(find testdata/sqllogictest -name '*.test' | wc -l | tr -d ' ') test files in testdata/sqllogictest/"
  87. # Build the sqllogictest runner binary.
  88. build-sqllogictest:
  89. go build -o ./bin/sqllogictest ./cmd/sqllogictest