Debian Codegraph @

Makefile

raw
1 # vim: ts=4 sw=4 ft=make
2
3 # Packages to run exhaustive tests against
4 EXHAUSTIVE_PKGS = github.com/charlievieth/strcase \
5 github.com/charlievieth/strcase/bytcase
6
7 # Run tests and linters. If this passes then CI tests
8 # should also pass.
9 .PHONY: all
10 all: install test testbenchmarks testgenerate testgenpkg vet golangci-lint
11
12 include common.mk
13
14 # Install pre-commit hooks and download modules
15 .PHONY: install
16 install: pre-commit
17 @$(GO) mod download
18 @$(GO) install
19
20 # Run verbose tests
21 testverbose: override GO_TEST_FLAGS += -v
22
23 # Run short tests
24 testshort: override GO_TEST_FLAGS += -short
25 testshort: override GO_COVER_FLAGS = ''
26
27 # TODO: add back "testinvalid" once we find an easy way
28 # to construct fuzz tests with invalid UTF-8 sequences.
29
30 .PHONY: test testshort testverbose
31 test testshort testverbose:
32 @GOGC=$(GO_GOGC) $(GO_TEST) ./...
33
34 # Run exhaustive fuzz tests
35 .PHONY: exhaustive
36 exhaustive:
37 @GOGC=$(GO_GOGC) $(GO_TEST) $(EXHAUSTIVE_PKGS) -exhaustive
38
39 # Generate code coverage report for strcase/bytecase
40 .PHONY: codecov
41 codecov: override GO_COVER_FLAGS = -covermode=count
42 codecov: override GO_COVER_FLAGS += -coverprofile=coverage.txt
43 codecov: exhaustive
44
45 # Assert that there are no skipped tests
46 .PHONY: testskipped
47 testskipped:
48 @if $(MAKE) testverbose | $(xgrep) --fixed-strings -- '--- SKIP:'; then \
49 echo ''; \
50 echo '$(red)FAIL: $(cyan)^^^ skipped tests ^^^$(term-reset)'; \
51 echo ''; \
52 exit 1; \
53 fi
54
55 # The gen package is separate from the strcase package (so we don't pollute
56 # our go.mod with its dependencies) so we need to cd into its directory to
57 # run the tests.
58 .PHONY: testgenpkg
59 testgenpkg:
60 @$(MAKE) -C $(MAKEFILE_DIR)/internal/gen --quiet test
61
62 # Test that `go generate` does not change tables.go
63 .PHONY: testgenerate
64 testgenerate: bin/gen
65 @if ! $(GEN_TARGET) -dry-run -skip-tests >/dev/null; then \
66 $(GEN_TARGET) -dry-run -skip-tests; \
67 fi;
68
69 # Make sure the benchmarks pass (we run them with a short benchtime)
70 .PHONY: testbenchmarks
71 testbenchmarks:
72 @cd $(MAKEFILE_DIR) && ./scripts/test-benchmarks.bash
73
74 # Run all tests (slow)
75 .PHONY: testall
76 testall: exhaustive testskipped testgenerate testgenpkg
77
78 # CI tests
79 .PHONY: ci
80 ci: test
81 ci: testbenchmarks
82 ci: vet
83
84 # Calibrate brute-force cutover
85 .PHONY: calibrate
86 calibrate: GO_COVER_FLAGS =
87 calibrate: GO_TEST_FLAGS += -v
88 calibrate:
89 @$(GO_TEST) -run 'Test.*Calibrate' -calibrate
90
91 .PHONY: vet-strcase
92 vet-strcase:
93 @$(GO) vet ./...
94
95 .PHONY: vet-gen
96 vet-gen:
97 @$(GO) vet -tags gen gen.go
98
99 .PHONY: vet-genpkg
100 vet-genpkg:
101 @cd $(MAKEFILE_DIR)/internal/gen && $(MAKE) --quiet vet
102
103 # NOTE: we don't run vet-genpkg here since it requires Go version 1.20
104 # and we run this against Go 1.19 in CI.
105 .PHONY: vet
106 vet: vet-strcase vet-gen
107
108 golangci-lint-gen: override GOLANGCI_EXTRA_FLAGS += --build-tags=gen gen.go
109 golangci-lint-gen: override GOLANGCI_SKIP =
110
111 # Run golangci-lint
112 .PHONY: golangci-lint-strcase golangci-lint-gen
113 golangci-lint-strcase golangci-lint-gen: bin/golangci-lint
114 @$(GOLANGCI_TARGET) run $(GOLANGCI_FLAGS)
115
116 .PHONY: golangci-lint
117 golangci-lint: golangci-lint-strcase golangci-lint-gen
118
119 .PHONY: lint
120 lint: vet golangci-lint golangci-lint-gen
121
122 # Make sure there aren't any comments that need addressing (TODO or WARN)
123 #
124 # NOTE: not currently part of the "lint" target.
125 .PHONY: lint-comments
126 lint-comments:
127 @if $(xgrep) $(GREP_COMMENTS) $(COMMENTS); then \
128 echo ''; \
129 echo '$(red)FAIL: $(cyan)address comments!$(term-reset)'; \
130 exit 1; \
131 fi
132
133 # Generate tables.go file
134 .PHONY: generate
135 generate:
136 @$(GO) generate
137
138 # Install pre-commit hook
139 # TODO: omit on Windows ???
140 .git/hooks/pre-commit: scripts/pre-commit
141 @mkdir -p $(MAKEFILE_DIR)/.git/hooks
142 ln -s $(MAKEFILE_DIR)/scripts/pre-commit $(MAKEFILE_DIR)/.git/hooks/pre-commit
143
144 # Install pre-commit hooks
145 # TODO: omit on Windows ???
146 pre-commit: .git/hooks/pre-commit
147
148 # Run pre-release tests (excluding: golangci-lint)
149 .PHONY: release
150 release: exhaustive testgenpkg testgenerate testbenchmarks calibrate vet
151
152 # Print information about the version of go being used
153 .PHONY: env
154 env:
155 @$(GO) env
156
157 .PHONY: clean
158 clean:
159 @rm -f cpu*.out mem*.out
160 @rm -rf DATA bin
161 @$(GO) clean -i ./...
162 @cd $(MAKEFILE_DIR)/internal/gen && $(MAKE) --quiet clean