-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
85 lines (65 loc) · 1.85 KB
/
Makefile
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
include common.mk
# Each Oasis CLI example's input .in must have a corresponding output .out.
EXAMPLES := $(patsubst %.in,%.out,$(wildcard examples/*/*.in))
# Check if Go's linkers flags are set in common.mk and add them as extra flags.
ifneq ($(GOLDFLAGS),)
GO_EXTRA_FLAGS += -ldflags $(GOLDFLAGS)
endif
# Set all target as the default target.
all: build
# Build.
build: oasis
oasis: $(shell find . -name "*.go" -type f) go.sum go.mod
@$(PRINT) "$(MAGENTA)*** Building Go code...$(OFF)\n"
@$(GO) build -v -o oasis $(GOFLAGS) $(GO_EXTRA_FLAGS)
examples: $(EXAMPLES)
examples/%.out: examples/%.in oasis scripts/gen_example.sh
@rm -f $@
@scripts/gen_example.sh $< $@
clean-examples:
@rm -f examples/*/*.out
# Format code.
fmt:
@$(PRINT) "$(CYAN)*** Running Go formatters...$(OFF)\n"
@gofumpt -w .
@goimports -w -local github.com/oasisprotocol/cli .
# Lint code, commits and documentation.
lint-targets := lint-go lint-docs lint-git lint-go-mod-tidy
lint-go:
@$(PRINT) "$(CYAN)*** Running Go linters...$(OFF)\n"
@env -u GOPATH golangci-lint run --verbose
lint-git:
@$(PRINT) "$(CYAN)*** Running gitlint...$(OFF)\n"
@$(CHECK_GITLINT)
lint-docs:
@$(PRINT) "$(CYAN)*** Running markdownlint-cli...$(OFF)\n"
@npx --yes markdownlint-cli '**/*.md'
lint-go-mod-tidy:
@$(PRINT) "$(CYAN)*** Checking go mod tidy...$(OFF)\n"
@$(ENSURE_GIT_CLEAN)
@$(CHECK_GO_MOD_TIDY)
lint: $(lint-targets)
# Release.
release-build:
@goreleaser release --clean
# Test.
test-targets := test-unit
test-unit:
@$(PRINT) "$(CYAN)*** Running unit tests...$(OFF)\n"
@$(GO) test -v -race ./...
test: $(test-targets)
# Clean.
clean:
@$(PRINT) "$(CYAN)*** Cleaning up ...$(OFF)\n"
@$(GO) clean -x
rm -f oasis
$(GO) clean -testcache
# List of targets that are not actual files.
.PHONY: \
all build \
examples \
clean-examples \
fmt \
$(lint-targets) lint \
$(test-targets) test \
clean