Debian Codegraph @

GNUmakefile

raw symbols SCIP
1 # Copyright 2025 The go-yaml Project Contributors
2 # SPDX-License-Identifier: Apache-2.0
3
4 # Auto-install https://github.com/makeplus/makes at specific commit:
5 MAKES := .cache/makes
6 MAKES-LOCAL := .cache/local
7 MAKES-COMMIT ?= 4e48a743c3652b88adc4a257398d895a801e6d11
8 $(shell [ -d $(MAKES) ] || ( \
9 git clone -q https://github.com/makeplus/makes $(MAKES) && \
10 git -C $(MAKES) reset -q --hard $(MAKES-COMMIT)))
11 ifneq ($(shell git -C $(MAKES) rev-parse HEAD), \
12 $(shell git -C $(MAKES) rev-parse $(MAKES-COMMIT)))
13 $(error $(MAKES) is not at the correct commit: $(MAKES-COMMIT). \
14 Remove $(MAKES) and try again.)
15 endif
16
17 include $(MAKES)/init.mk
18 include $(MAKES)/shellcheck.mk
19
20 # Auto-install go unless GO_YAML_PATH is set:
21 ifdef GO_YAML_PATH
22 override export PATH := $(GO_YAML_PATH):$(PATH)
23 else
24 GO-VERSION ?= 1.25.5
25 endif
26 GO-VERSION-NEEDED := $(GO-VERSION)
27
28 # yaml-test-suite info:
29 YTS-URL ?= https://github.com/yaml/yaml-test-suite
30 YTS-TAG ?= data-2022-01-17
31 YTS-DIR := yts/testdata/$(YTS-TAG)
32
33 CLI-BINARY := go-yaml
34
35 # Pager for viewing documentation:
36 PAGER ?= less -FRX
37
38 # Setup and include go.mk and shell.mk:
39
40 # We need to limit `find` to avoid dirs like `.cache/` and any git worktrees,
41 # as this makes `make` operations very slow:
42 REPO-DIRS := $(shell find * -maxdepth 0 -type d \
43 ! -exec test -f {}/.git \; -print)
44 GO-FILES := $(shell find $(REPO-DIRS) -name '*.go')
45
46 ifndef GO-VERSION-NEEDED
47 GO-NO-DEP-GO := true
48 endif
49
50 include $(MAKES)/go.mk
51
52 # Set this from the `make` command to override:
53 GOLANGCI-LINT-VERSION ?= v2.8.0
54 GOLANGCI-LINT-INSTALLER := \
55 https://github.com/golangci/golangci-lint/raw/main/install.sh
56 GOLANGCI-LINT := $(LOCAL-BIN)/golangci-lint
57 GOLANGCI-LINT-VERSIONED := $(GOLANGCI-LINT)-$(GOLANGCI-LINT-VERSION)
58
59 SHELL-DEPS += $(GOLANGCI-LINT-VERSIONED)
60
61 ifdef GO-VERSION-NEEDED
62 GO-DEPS += $(GO)
63 else
64 SHELL-DEPS := $(filter-out $(GO),$(SHELL-DEPS))
65 endif
66
67 SHELL-NAME := makes go-yaml
68 include $(MAKES)/clean.mk
69 include $(MAKES)/shell.mk
70
71 MAKES-CLEAN := $(CLI-BINARY) $(GOLANGCI-LINT)
72 MAKES-REALCLEAN := $(dir $(YTS-DIR))
73
74 SHELL-SCRIPTS = \
75 util/common.bash \
76 $(shell grep -rl '^.!/usr/bin/env bash' util | \
77 grep -v '\.sw')
78
79 COVER-TESTS := \
80 . \
81 ./cmd/... \
82 ./internal/... \
83
84 # v=1 for verbose
85 MAKE := $(MAKE) --no-print-directory
86
87 v ?=
88 cover ?=
89 fuzz ?=
90 time ?= 60s
91 opts ?=
92
93 TEST-OPTS := \
94 $(if $v, -v)\
95 $(if $(cover), --cover)\
96 $(if $(fuzz), --fuzz=FuzzEncodeFromJSON --fuzztime=$(time))\
97 $(if $(opts), $(opts))\
98
99 # Test rules:
100 test: test-main test-internal test-cmd test-yts-all test-shell
101 @echo 'ALL TESTS PASS'
102
103 check:
104 $(MAKE) fmt
105 $(MAKE) tidy
106 $(MAKE) lint
107 $(MAKE) test
108
109 test-main: $(GO-DEPS)
110 go test .$(TEST-OPTS)
111 @echo 'ALL MAIN FILES PASS'
112
113 test-cmd: $(GO-DEPS)
114 go test ./cmd/...$(TEST-OPTS)
115 @echo 'ALL CMD FILES PASS'
116
117 test-internal: $(GO-DEPS)
118 go test ./internal/...$(TEST-OPTS)
119 @echo 'ALL INTERNAL FILES PASS'
120
121 test-cover: $(GO-DEPS)
122 go test . $(COVER-TESTS) -vet=off --cover$(TEST-OPTS)
123
124 test-yts: $(GO-DEPS) $(YTS-DIR)
125 go test ./yts$(TEST-OPTS)
126
127 test-yts-all: $(GO-DEPS) $(YTS-DIR)
128 @echo 'Testing yaml-test-suite'
129 util/yaml-test-suite all
130
131 test-yts-fail: $(GO-DEPS) $(YTS-DIR)
132 @echo 'Testing yaml-test-suite failures'
133 util/yaml-test-suite fail
134
135 test-shell: $(SHELLCHECK)
136 shellcheck $(SHELL-SCRIPTS)
137 @echo 'ALL SHELL FILES PASS'
138
139 test-count: $(GO-DEPS)
140 util/test-count
141
142 yts-dir: $(YTS-DIR)
143
144 get-test-data: $(YTS-DIR)
145
146 # Install golangci-lint for GitHub Actions:
147 golangci-lint-install: $(GOLANGCI-LINT)
148
149 fmt: $(GOLANGCI-LINT-VERSIONED)
150 $< fmt ./...
151
152 lint: $(GOLANGCI-LINT-VERSIONED)
153 $< run ./...
154
155 tidy: $(GO-DEPS)
156 go mod tidy
157
158 cli: $(CLI-BINARY)
159
160 $(CLI-BINARY): $(GO)
161 go build -o $@ ./cmd/$@
162
163 run-examples: $(GO)
164 @for dir in example/*/; do \
165 (set -x; go run "$${dir}main.go") || \
166 { echo "$$dir failed"; break; }; \
167 done
168
169 # CLI documentation (go doc) - view in terminal:
170 doc: $(GO-DEPS)
171 @go doc -all . | $(PAGER)
172
173 # HTTP documentation server - opens browser:
174 doc-http: $(GO-DEPS)
175 go doc -http -all
176
177 # Setup rules:
178 $(YTS-DIR):
179 git clone -q $(YTS-URL) $@
180 git -C $@ checkout -q $(YTS-TAG)
181
182 # Downloads golangci-lint binary and moves to versioned path
183 # (.cache/local/bin/golangci-lint-<version>).
184 $(GOLANGCI-LINT-VERSIONED): $(GO-DEPS)
185 curl -sSfL $(GOLANGCI-LINT-INSTALLER) | \
186 bash -s -- -b $(LOCAL-BIN) $(GOLANGCI-LINT-VERSION)
187 mv $(GOLANGCI-LINT) $@
188
189 # Moves golangci-lint-<version> to golangci-lint for CI requirement
190 $(GOLANGCI-LINT): $(GOLANGCI-LINT-VERSIONED)
191 cp $< $@