forked from gastownhall/beads
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
207 lines (184 loc) · 7.7 KB
/
Makefile
File metadata and controls
207 lines (184 loc) · 7.7 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
# Makefile for beads project
# On Windows, GNU Make defaults to cmd.exe which doesn't support POSIX
# shell syntax used throughout this Makefile. Use Git for Windows' bash.
ifeq ($(OS),Windows_NT)
GIT_BASH := $(shell where git 2>nul)
ifneq ($(GIT_BASH),)
SHELL := $(subst cmd,bin,$(subst git.exe,bash.exe,$(GIT_BASH)))
endif
endif
.PHONY: all build test test-full-cgo test-regression test-upgrade test-cross-version bench bench-quick clean install install-force help check-up-to-date fmt fmt-check
# Default target
all: build
BUILD_DIR := .
GIT_BUILD := $(shell git rev-parse --short HEAD)
ifeq ($(OS),Windows_NT)
INSTALL_DIR := $(USERPROFILE)/.local/bin
else
INSTALL_DIR := $(HOME)/.local/bin
endif
# Dolt backend requires CGO for embedded database support.
# Without CGO, builds will fail with "dolt backend requires CGO".
#
# Windows notes:
# - ICU is NOT required. go-icu-regex has a pure-Go fallback (regex_windows.go)
# and gms_pure_go tag tells go-mysql-server to use pure-Go regex too.
# - CGO_ENABLED=1 needs a C compiler (MinGW/MSYS2) but does NOT need ICU.
export CGO_ENABLED := 1
# When go.mod requires a newer Go version than the locally installed one,
# GOTOOLCHAIN=auto downloads the right compiler but coverage instrumentation
# may still use the local toolchain's compile tool, causing version mismatch.
# Force the go.mod version to ensure all tools match.
GO_VERSION := $(shell sed -n 's/^go //p' go.mod)
ifneq ($(GO_VERSION),)
export GOTOOLCHAIN := go$(GO_VERSION)
endif
# ICU4C is keg-only in Homebrew (not symlinked into the prefix).
# Dolt's go-icu-regex dependency needs these paths to compile and link.
# This handles both macOS (brew --prefix icu4c) and Linux/Linuxbrew.
# On Windows, ICU is not needed (pure-Go regex via gms_pure_go + regex_windows.go).
ifneq ($(OS),Windows_NT)
ICU_PREFIX := $(shell brew --prefix icu4c 2>/dev/null)
ifneq ($(ICU_PREFIX),)
export CGO_CFLAGS += -I$(ICU_PREFIX)/include
export CGO_CPPFLAGS += -I$(ICU_PREFIX)/include
export CGO_LDFLAGS += -L$(ICU_PREFIX)/lib
# Linuxbrew gcc doesn't install a 'c++' symlink; point CGO at g++
ifeq ($(shell uname),Linux)
export CXX ?= g++
endif
endif
endif
# Build the bd binary
build:
@echo "Building bd..."
ifeq ($(OS),Windows_NT)
go build -tags gms_pure_go -ldflags="-X main.Build=$(GIT_BUILD)" -o $(BUILD_DIR)/bd.exe ./cmd/bd
else
go build -ldflags="-X main.Build=$(GIT_BUILD)" -o $(BUILD_DIR)/bd ./cmd/bd
ifeq ($(shell uname),Darwin)
@codesign -s - -f $(BUILD_DIR)/bd 2>/dev/null || true
@echo "Signed bd for macOS"
endif
endif
# Run all tests (skips known broken tests listed in .test-skip)
test:
@echo "Running tests..."
@TEST_COVER=1 ./scripts/test.sh
# Run full CGO-enabled test suite (no skip list).
# On macOS, auto-configures ICU include/link flags.
test-full-cgo:
@echo "Running full CGO-enabled tests..."
@./scripts/test-cgo.sh ./...
# Run differential regression tests (baseline v0.49.6 vs current worktree).
# Downloads baseline binary on first run; cached in ~/Library/Caches/beads-regression/.
# Override baseline: BD_REGRESSION_BASELINE_BIN=/path/to/bd make test-regression
test-regression:
@echo "Running regression tests (baseline vs candidate)..."
go test -tags=regression -timeout=10m -v ./tests/regression/...
# Run upgrade smoke tests (release stability gate).
# Tests that upgrading from previous release preserves data, role, and mode.
# Override version: ./scripts/upgrade-smoke-test.sh v0.62.0
test-upgrade: build
@echo "Running upgrade smoke tests..."
@CANDIDATE_BIN=./bd ./scripts/upgrade-smoke-test.sh
# Run cross-version smoke tests (last 30 tags → candidate).
# Creates epic, issues, and dependencies with old versions, upgrades, verifies.
# Specific versions: ./scripts/cross-version-smoke-test.sh v0.55.0 v0.56.1
# All from v0.30.0: ./scripts/cross-version-smoke-test.sh --from v0.30.0
test-cross-version: build
@echo "Running cross-version smoke tests..."
@CANDIDATE_BIN=./bd ./scripts/cross-version-smoke-test.sh
# Run performance benchmarks against Dolt storage backend
# Requires CGO and Dolt; generates CPU profile files
# View flamegraph: go tool pprof -http=:8080 <profile-file>
bench:
@echo "Running performance benchmarks (Dolt backend)..."
@echo ""
go test -bench=. -benchtime=1s -benchmem -run=^$$ ./internal/storage/dolt/ -timeout=30m
@echo ""
@echo "Benchmark complete."
# Run quick benchmarks (shorter benchtime for faster feedback)
bench-quick:
@echo "Running quick performance benchmarks..."
go test -bench=. -benchtime=100ms -benchmem -run=^$$ ./internal/storage/dolt/ -timeout=15m
# Check that local branch is up to date with origin/main
check-up-to-date:
ifndef SKIP_UPDATE_CHECK
@# Skip check on detached HEAD (tag checkouts, CI builds)
@if ! git symbolic-ref HEAD >/dev/null 2>&1; then exit 0; fi
@git fetch origin main --quiet 2>/dev/null || true
@LOCAL=$$(git rev-parse HEAD 2>/dev/null); \
REMOTE=$$(git rev-parse origin/main 2>/dev/null); \
if [ -n "$$REMOTE" ] && [ "$$LOCAL" != "$$REMOTE" ]; then \
echo "ERROR: Local branch is not up to date with origin/main"; \
echo " Local: $$(git rev-parse --short HEAD)"; \
echo " Remote: $$(git rev-parse --short origin/main)"; \
echo "Run 'git pull' first, or use 'make install-force' to override"; \
exit 1; \
fi
endif
# Install bd to ~/.local/bin (builds, signs on macOS, and copies)
# Also creates 'beads' symlink as an alias for bd
# Use install-force to skip the origin/main update check
install install-force: build
@mkdir -p $(INSTALL_DIR)
ifeq ($(OS),Windows_NT)
@rm -f $(INSTALL_DIR)/bd.exe
@cp $(BUILD_DIR)/bd.exe $(INSTALL_DIR)/bd.exe
@echo "Installed bd.exe to $(INSTALL_DIR)/bd.exe"
else
@rm -f $(INSTALL_DIR)/bd
@cp $(BUILD_DIR)/bd $(INSTALL_DIR)/bd
@echo "Installed bd to $(INSTALL_DIR)/bd"
@rm -f $(INSTALL_DIR)/beads
@ln -s bd $(INSTALL_DIR)/beads
@echo "Created 'beads' alias -> bd"
endif
@git config core.hooksPath .githooks 2>/dev/null && echo "Configured git hooks (.githooks/)" || true
install: check-up-to-date
# Format all Go files
fmt:
@echo "Formatting Go files..."
@gofmt -w .
@echo "Done"
# Check that all Go files are properly formatted (for CI)
fmt-check:
@echo "Checking Go formatting..."
@UNFORMATTED=$$(gofmt -l .); \
if [ -n "$$UNFORMATTED" ]; then \
echo "The following files are not properly formatted:"; \
echo "$$UNFORMATTED"; \
echo ""; \
echo "Run 'make fmt' to fix formatting"; \
exit 1; \
fi
@echo "All Go files are properly formatted"
# Validate documentation references against actual CLI flags
check-docs: build
@./scripts/check-doc-flags.sh ./bd
# Clean build artifacts and benchmark profiles
clean:
@echo "Cleaning..."
rm -f bd
rm -f bd.exe
rm -f internal/storage/dolt/bench-cpu-*.prof
rm -f beads-perf-*.prof
# Show help
help:
@echo "Beads Makefile targets:"
@echo " make build - Build the bd binary"
@echo " make test - Run all tests"
@echo " make test-full-cgo - Run full CGO-enabled test suite"
@echo " make test-regression - Run differential regression tests (baseline vs candidate)"
@echo " make test-upgrade - Run upgrade smoke tests (release stability gate)"
@echo " make test-cross-version - Run cross-version smoke tests (last 30 tags)"
@echo " make bench - Run performance benchmarks (generates CPU profiles)"
@echo " make bench-quick - Run quick benchmarks (shorter benchtime)"
@echo " make install - Install bd to ~/.local/bin (with codesign on macOS, includes 'beads' alias)"
@echo " make install-force - Install bd, skipping the origin/main update check"
@echo " make fmt - Format all Go files with gofmt"
@echo " make fmt-check - Check Go formatting (for CI)"
@echo " make check-docs - Validate docs against CLI flags"
@echo " make clean - Remove build artifacts and profile files"
@echo " make help - Show this help message"