-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathMakefile
More file actions
169 lines (143 loc) · 7.17 KB
/
Copy pathMakefile
File metadata and controls
169 lines (143 loc) · 7.17 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
SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -c
GO ?= go
DIST ?= dist
BINARIES := $(notdir $(patsubst %/,%,$(dir $(wildcard cmd/*/main.go))))
GEN_KINDS := proto ssz mocks logs
TEST_KINDS := mainnet mainnet-spectest minimal minimal-spectest
E2E_SCENARIOS := minimal builder web3signer slasher slashing scenario scenario-multiclient postmerge statediff mainnet multiclient
E2E_SUITES := presubmit postsubmit scenario_tests
E2E_KINDS := $(E2E_SCENARIOS) $(E2E_SUITES)
# Suite -> scenario(s) mapping (keep in sync with the `suites` map in build/e2e/main.go).
E2E_SUITE_presubmit := minimal statediff slashing slasher
E2E_SUITE_postsubmit := builder postmerge mainnet multiclient
E2E_SUITE_scenario_tests := scenario scenario-multiclient
POSITIONAL := $(sort $(GEN_KINDS) $(TEST_KINDS) $(E2E_KINDS) $(BINARIES))
COMMANDS := run build gen clean help test testdata e2e
TAGS ?=
TAGFLAG := $(if $(TAGS),-tags=$(TAGS),)
flags ?=
ALLOWED_VARS := GO DIST TAGS flags mode
BAD_VARS := $(strip $(foreach v,$(.VARIABLES),$(if $(filter command line,$(origin $(v))),$(filter-out $(ALLOWED_VARS),$(v)))))
ifneq ($(BAD_VARS),)
$(error unknown variable(s): $(BAD_VARS) (allowed: $(ALLOWED_VARS)))
endif
GEN_MODE := $(or $(mode),no-force)
GEN_MODE_BAD := $(filter-out force no-force,$(GEN_MODE))
TEST_MODE := $(or $(mode),no-race)
TEST_MODE_BAD := $(filter-out no-race race,$(TEST_MODE))
TEST_ARGS := $(filter-out $(COMMANDS),$(MAKECMDGOALS))
TEST_BAD := $(filter-out $(TEST_KINDS),$(TEST_ARGS))
E2E_ARGS := $(filter-out $(COMMANDS),$(MAKECMDGOALS))
E2E_BAD := $(filter-out $(E2E_KINDS),$(E2E_ARGS))
# Goals left over after `run` and the binary name are the program's arguments.
# A leading `--` ends make's option parsing so `--flag value` reaches us as goals
# (caught as no-ops by the catch-all) rather than being treated as make options.
RUN_BIN := $(filter $(BINARIES),$(MAKECMDGOALS))
RUN_ARGS := $(filter-out run $(COMMANDS) $(RUN_BIN),$(MAKECMDGOALS))
# ---------------------------------------------------------------------------
# Code generation
# ---------------------------------------------------------------------------
GEN_GOALS := $(filter-out gen,$(MAKECMDGOALS))
GEN_BAD := $(filter-out $(GEN_KINDS),$(GEN_GOALS))
.PHONY: gen
gen:
@$(if $(GEN_MODE_BAD),echo "❌ gen: invalid mode '$(GEN_MODE)' (one of: force no-force)" >&2; exit 1;) \
$(if $(GEN_BAD),echo "❌ gen: unknown kind(s): $(GEN_BAD) (one of: $(GEN_KINDS))" >&2; exit 1;) \
$(GO) run ./build/gen --mode=$(GEN_MODE) $(filter $(GEN_KINDS),$(MAKECMDGOALS))
.PHONY: clean
clean:
rm -f .gen-cache.json
rm -rf third_party/testdata
$(GO) clean -cache -testcache -modcache -fuzzcache
# ---------------------------------------------------------------------------
# Run
# ---------------------------------------------------------------------------
.PHONY: run
run:
@$(MAKE) --no-print-directory gen
@bin="$(strip $(RUN_BIN))"; \
case "$$bin" in \
"") echo "❌ run: specify a binary (one of: $(BINARIES))" >&2; exit 1;; \
*" "*) echo "❌ run: only one binary at a time (got: $$bin)" >&2; exit 1;; \
esac; \
cmd="$(strip $(GO) run $(TAGFLAG) $(flags) ./cmd/$$bin $(RUN_ARGS))"; \
echo "→ $$cmd"; \
eval "$$cmd"
# ---------------------------------------------------------------------------
# Build
# ---------------------------------------------------------------------------
.PHONY: build
build:
@$(MAKE) --no-print-directory gen
@bins="$(or $(strip $(filter $(BINARIES),$(MAKECMDGOALS))),$(BINARIES))"; \
bad="$(strip $(filter-out $(COMMANDS) $(BINARIES),$(MAKECMDGOALS)))"; \
[ -z "$$bad" ] || { echo "❌ build: not a binary: $$bad (available: $(BINARIES))" >&2; exit 1; }; \
mkdir -p $(DIST); \
for b in $$bins; do \
cmd="$(strip $(GO) build $(TAGFLAG) $(flags) -o \"$(DIST)/$$b\" ./cmd/$$b)"; \
echo "→ $$cmd"; \
eval "$$cmd" || exit 1; \
done; \
echo "✅ build ==> $(DIST)/"
# ---------------------------------------------------------------------------
# Test
# ---------------------------------------------------------------------------
.PHONY: test
test:
@$(if $(TEST_MODE_BAD),echo "❌ test: invalid mode '$(TEST_MODE)' (one of: no-race race)" >&2; exit 1;) \
$(if $(TEST_BAD),echo "❌ test: unknown kind(s): $(TEST_BAD) (one of: $(TEST_KINDS))" >&2; exit 1;) :
@$(MAKE) --no-print-directory gen
@GO="$(GO)" $(GO) run ./build/test $(if $(filter race,$(TEST_MODE)),-race,) $(TEST_ARGS)
.PHONY: testdata
testdata:
$(GO) run ./tools/cmd/fetch-testdata
# ---------------------------------------------------------------------------
# End-to-end tests
# ---------------------------------------------------------------------------
.PHONY: e2e
e2e:
@$(if $(E2E_BAD),echo "❌ e2e: unknown target(s): $(E2E_BAD) (scenarios: $(E2E_SCENARIOS) - suites: $(E2E_SUITES))" >&2; exit 1;) \
GO="$(GO)" DIST="$(DIST)" $(GO) run ./build/e2e $(filter $(E2E_KINDS),$(MAKECMDGOALS))
# ---------------------------------------------------------------------------
# Help (default target)
# ---------------------------------------------------------------------------
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help
@echo ""
@printf '\033[1;38;5;214m'
@echo "Prysm - Ethereum consensus client"
@printf '\033[0m'
@echo ""
@printf '\033[1mCommands:\033[0m\n'
@printf " \033[36m%-44s\033[0m %s\n" "make run <bin> [flags=...] [-- <args>]" "Run a binary"
@printf " \033[36m%-44s\033[0m %s\n" "make build [<bin>...] [flags=...]" "Build a binary (default: all)"
@printf " \033[36m%-44s\033[0m %s\n" "make gen [<kind>...] [mode=force|no-force]" "Create generated code (default: all,no-force)"
@printf " \033[36m%-44s\033[0m %s\n" "make test [<kind>...] [mode=no-race|race]" "Run unit tests (default: all,no-race)"
@printf " \033[36m%-44s\033[0m %s\n" "make e2e [<scenario>|<suite>...]" "Run end-to-end tests (default: presubmit)"
@printf " \033[36m%-44s\033[0m %s\n" "make testdata" "Pre-fetch external spec-test data"
@printf " \033[36m%-44s\033[0m %s\n" "make clean" "Clean everything"
@printf " \033[36m%-44s\033[0m %s\n" "make help" "Show this help"
@echo ""
@printf '\033[1mOptions:\033[0m\n'
@printf " \033[36m%-16s\033[0m %s\n" "<bin>:" "$(BINARIES)"
@printf " \033[36m%-16s\033[0m %s\n" "gen <kind>:" "$(GEN_KINDS)"
@printf " \033[36m%-16s\033[0m %s\n" "test <kind>:" "$(TEST_KINDS)"
@printf " \033[36m%-16s\033[0m %s\n" "e2e <scenario>:" "$(E2E_SCENARIOS)"
@printf " \033[36m%-16s\033[0m\n" "e2e <suite>:"
@printf " \033[36m%-16s\033[0m %s\n" "presubmit:" "$(E2E_SUITE_presubmit)"
@printf " \033[36m%-16s\033[0m %s\n" "postsubmit:" "$(E2E_SUITE_postsubmit)"
@printf " \033[36m%-16s\033[0m %s\n" "scenario_tests:" "$(E2E_SUITE_scenario_tests)"
@echo ""
@printf '\033[1mNotes:\033[0m\n'
@echo " After '--', pass '--flag value' (not '--flag=value')"
@echo ""
# ---------------------------------------------------------------------------
# Positional-argument catch-all (lets `make gen proto` / `make build beacon-chain`
# name kinds and binaries as goals)
# ---------------------------------------------------------------------------
.PHONY: $(POSITIONAL)
$(POSITIONAL): ; @:
%:
@: