Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
152 lines (128 loc) · 4.98 KB
/
Copy pathMakefile
File metadata and controls
152 lines (128 loc) · 4.98 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
# Generated by promptkit -- do not edit. Regenerate with: promptkit update
GOBIN ?= build/bin
GO111MODULE=on
ifneq ($(OS),Windows_NT)
EXE =
else
EXE = .exe
endif
PKG = $(shell go env GOOS)_$(shell go env GOARCH)
TAGS ?=
VERSION_PKG = github.com/dmytrogajewski/spin/pkg/version
GIT_COMMIT = $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
GIT_VERSION = $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_DATE = $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS = -X $(VERSION_PKG).Version=$(GIT_VERSION) -X $(VERSION_PKG).Commit=$(GIT_COMMIT) -X $(VERSION_PKG).Date=$(BUILD_DATE)
CGO_ENABLED=0
all: ${GOBIN}/spin${EXE}
# Build all binaries (alias for all)
.PHONY: build
build: all
# Show help
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Build all binaries"
@echo " build - Build all binaries (alias for all)"
@echo " install - Install binaries to system PATH"
@echo " test - Run all tests"
@echo " testv - Run all tests (verbose)"
@echo " lint - Run linters and deadcode analysis"
@echo " fmt - Format code"
@echo " deadcode - Run deadcode analysis with detailed output"
@echo " deadcode-prod - Run deadcode analysis excluding tests"
@echo " deadcode-why - Show why a function is not dead (FUNC=name)"
@echo " clean - Clean build artifacts"
@echo " bench - Run benchmarks"
# Install binaries to user's local bin directory
install: all
@echo "Installing binaries..."
@mkdir -p ~/.local/bin
@cp ${GOBIN}/spin${EXE} ~/.local/bin/
@echo "Installed to ~/.local/bin"
@if ! echo $$PATH | grep -q "$$HOME/.local/bin"; then \
echo ""; \
echo "Note: ~/.local/bin is not in your PATH"; \
echo "Add it by running: export PATH=\"\$$HOME/.local/bin:\$$PATH\""; \
echo "Or add the above line to your ~/.bashrc or ~/.zshrc"; \
fi
# Run all tests
test: all
CGO_ENABLED=0 go test ./...
# Run all tests with verbose output
testv: all
CGO_ENABLED=0 go test ./... -v
# Run benchmarks
bench: all
CGO_ENABLED=0 go test -run="^$$" -bench=. -benchmem ./...
# Run benchmarks with CPU profiling
benchcpu: all
CGO_ENABLED=0 go test -run="^$$" -bench=. -benchmem -cpuprofile=cpu.prof ./...
# Run benchmarks with memory profiling
benchmem: all
CGO_ENABLED=0 go test -run="^$$" -bench=. -benchmem -memprofile=mem.prof ./...
# Linting tools (resolve from GOPATH/bin if not on PATH)
GOPATH_BIN=$(shell go env GOPATH)/bin
GOLINT=$(or $(shell command -v golangci-lint 2>/dev/null),$(GOPATH_BIN)/golangci-lint)
DEADCODE=$(or $(shell command -v deadcode 2>/dev/null),$(GOPATH_BIN)/deadcode)
# Package paths for linting
INTERNAL_PKGS=./...
DEADCODE_PKGS=./...
LINT_GOCACHE?=/tmp/spin-go-cache
LINT_GOLANGCI_CACHE?=/tmp/spin-golangci-lint-cache
## lint: Run linters and deadcode analysis
.PHONY: lint
lint:
@echo "Running linters..."
@mkdir -p $(LINT_GOCACHE) $(LINT_GOLANGCI_CACHE)
@GOCACHE=$(LINT_GOCACHE) \
GOLANGCI_LINT_CACHE=$(LINT_GOLANGCI_CACHE) \
CGO_ENABLED=0 $(GOLINT) run $(INTERNAL_PKGS)
@echo "Running deadcode analysis..."
@GOCACHE=$(LINT_GOCACHE) ./scripts/deadcode-filter.sh -test $(DEADCODE_PKGS)
@echo "Linting complete"
## deadcode: Run deadcode analysis with whitelist filter (fails if dead code found)
.PHONY: deadcode
deadcode:
@echo "Running deadcode analysis with whitelist..."
@GOCACHE=$(LINT_GOCACHE) ./scripts/deadcode-filter.sh -test $(DEADCODE_PKGS)
## deadcode-prod: Run deadcode analysis excluding tests (production-only dead code)
.PHONY: deadcode-prod
deadcode-prod:
@echo "Running deadcode analysis (production only)..."
@echo "================================================================"
@GOCACHE=$(LINT_GOCACHE) ./scripts/deadcode-filter.sh $(DEADCODE_PKGS)
## deadcode-json: Run deadcode analysis with JSON output
.PHONY: deadcode-json
deadcode-json:
@echo "Running deadcode analysis (JSON output)..."
@GOCACHE=$(LINT_GOCACHE) $(DEADCODE) -json $(DEADCODE_PKGS)
## deadcode-why: Show why a function is not dead (usage: make deadcode-why FUNC=functionName)
.PHONY: deadcode-why
deadcode-why:
@if [ -z "$(FUNC)" ]; then \
echo "Usage: make deadcode-why FUNC=functionName"; \
echo "Example: make deadcode-why FUNC=bytes.Buffer.String"; \
exit 1; \
fi
@echo "Analyzing why $(FUNC) is considered live..."
@GOCACHE=$(LINT_GOCACHE) $(DEADCODE) -whylive="$(FUNC)" $(DEADCODE_PKGS)
## fmt: Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
@go fmt $(INTERNAL_PKGS)
@echo "Formatting complete"
clean:
rm -rf ${GOBIN}/
rm -f *.prof
rm -rf profiles/
# =============================================================================
# Binary build targets
# =============================================================================
# FORCE prerequisite: always re-run go build (its cache makes this cheap);
# a file target with no deps would silently ship stale binaries on install.
${GOBIN}/spin${EXE}: FORCE
CGO_ENABLED=0 go build -tags "$(TAGS)" -ldflags "$(LDFLAGS)" -o ${GOBIN}/spin${EXE} ./cmd/spin
.PHONY: FORCE
FORCE: