-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (96 loc) · 3.65 KB
/
Copy pathMakefile
File metadata and controls
110 lines (96 loc) · 3.65 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
.PHONY: help build install test test-race lint fmt fmt-check commitmsg-lint commitlint commitmsg-fmt
GOCC ?= go
TOOLS_DIR := tools
COMMITMSG_DIR := $(TOOLS_DIR)/commitmsg
LLFORMAT_DIR := $(TOOLS_DIR)/llformat
LLFORMAT_PKG := github.com/bhandras/llformat/cmd/llformat
LLFORMAT_BIN := $(CURDIR)/$(LLFORMAT_DIR)/bin/llformat
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2
EXAMPLE_PLUGIN_DIR := plugins/example
GO_INTEL_PLUGIN_DIR := plugins/go-intel
BINDIR ?= bin
ETCH_BIN ?= $(BINDIR)/etch
PLUGIN_BINDIR ?= $(HOME)/.etch/bin
GO_INTEL_BIN ?= $(PLUGIN_BINDIR)/go-intel
help:
@printf '%s\n' \
'Targets:' \
' build Build the etch binary into bin/etch.' \
' install Install etch and bundled plugin binaries.' \
' test Run the Go test suite.' \
' test-race Run race-enabled tests for the main module.' \
' lint Run golangci-lint for all Go modules.' \
' fmt Format handwritten Go source with llformat.' \
' fmt-check Run fmt and fail if git sees formatting changes.' \
' commitmsg-lint Lint commit messages. Use range=, commit=, or file=.' \
' commitlint Alias for commitmsg-lint.' \
' commitmsg-fmt Format a commit message. Use file= [inplace=1] or commit=.'
build:
@mkdir -p $(BINDIR)
$(GOCC) build -trimpath -o $(ETCH_BIN) ./cmd/etch
install:
$(GOCC) install -trimpath ./cmd/etch
@mkdir -p $(PLUGIN_BINDIR)
cd $(GO_INTEL_PLUGIN_DIR); $(GOCC) build -trimpath -o $(GO_INTEL_BIN) .
test:
$(GOCC) test ./...
cd $(EXAMPLE_PLUGIN_DIR); $(GOCC) test ./...
cd $(GO_INTEL_PLUGIN_DIR); $(GOCC) test ./...
test-race:
$(GOCC) test -race ./...
lint:
$(GOCC) run $(GOLANGCI_LINT_PKG) run ./...
cd $(EXAMPLE_PLUGIN_DIR); $(GOCC) run $(GOLANGCI_LINT_PKG) run ./...
cd $(GO_INTEL_PLUGIN_DIR); $(GOCC) run $(GOLANGCI_LINT_PKG) run ./...
$(LLFORMAT_BIN): $(LLFORMAT_DIR)/go.mod $(LLFORMAT_DIR)/tools.go
@mkdir -p $(LLFORMAT_DIR)/bin
cd $(LLFORMAT_DIR); GOBIN="$(CURDIR)/$(LLFORMAT_DIR)/bin" \
$(GOCC) install -trimpath $(LLFORMAT_PKG)
fmt: $(LLFORMAT_BIN)
@find . -type f -name '*.go' \
-not -path './.git/*' \
-not -path './tools/llformat/bin/*' \
-not -path './vendor/*' \
-not -path './third_party/*' \
-print0 | xargs -0 $(LLFORMAT_BIN) -w
fmt-check: fmt
@if [ -d .git ]; then \
if test -n "$$(git status --porcelain)"; then \
echo 'code not formatted correctly, please run make fmt'; \
git status --short; \
git diff; \
exit 1; \
fi; \
else \
echo 'fmt-check: no .git directory; skipped dirty-worktree check'; \
fi
commitmsg-lint:
@if [ -n "$(range)" ]; then \
cd $(COMMITMSG_DIR); $(GOCC) run . lint --range "$(range)"; \
elif [ -n "$(commit)" ]; then \
cd $(COMMITMSG_DIR); $(GOCC) run . lint --commit "$(commit)"; \
elif [ -n "$(file)" ]; then \
cd $(COMMITMSG_DIR); $(GOCC) run . lint --file "$(abspath $(file))"; \
elif [ -d .git ]; then \
cd $(COMMITMSG_DIR); $(GOCC) run . lint --commit HEAD; \
else \
echo "Error: provide range=<rev-range>, commit=<rev>, or file=<path>."; \
exit 1; \
fi
commitlint: commitmsg-lint
commitmsg-fmt:
@if [ -n "$(file)" ]; then \
if [ "$(inplace)" = "1" ]; then \
cd $(COMMITMSG_DIR); $(GOCC) run . fmt --file "$(abspath $(file))" --in-place \
$(if $(filter 1,$(decode)),--decode-escaped-newlines,); \
else \
cd $(COMMITMSG_DIR); $(GOCC) run . fmt --file "$(abspath $(file))" \
$(if $(filter 1,$(decode)),--decode-escaped-newlines,); \
fi; \
elif [ -n "$(commit)" ]; then \
cd $(COMMITMSG_DIR); $(GOCC) run . fmt --commit "$(commit)" \
$(if $(filter 1,$(decode)),--decode-escaped-newlines,); \
else \
echo "Error: provide file=<path> or commit=<rev>."; \
exit 1; \
fi