-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
111 lines (81 loc) · 3.97 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
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
VERSION := $(shell echo $(shell git describe --always) | sed 's/^v//')
TENDERMINT_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
COMMIT := $(shell git log -1 --format='%H')
BUILDDIR ?= $(CURDIR)/build
DOCKER := $(shell which docker)
export GO111MODULE = on
all: lint test-unit install
###############################################################################
### Build flags ###
###############################################################################
# These lines here are essential to include the muslc library for static linking of libraries
# (which is needed for the wasmvm one) available during the build. Without them, the build will fail.
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
whitespace :=
whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
# Process linker flags
ldflags = -X 'github.com/forbole/juno/v5/cmd.Version=$(VERSION)' \
-X 'github.com/forbole/juno/v5/cmd.Commit=$(COMMIT)'
ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
###############################################################################
### Build ###
###############################################################################
BUILD_TARGETS := build install
build: BUILD_ARGS=-o $(BUILDDIR)
$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/
$(BUILD_TARGETS): go.sum $(BUILDDIR)/
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...
.PHONY: build install
###############################################################################
### Tools & Dependencies ###
###############################################################################
go-mod-cache: go.sum
@echo "--> Download go modules to local cache"
@go mod download
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
@go mod verify
@go mod tidy
clean:
rm -rf $(BUILDDIR)/
.PHONY: go-mod-cache go.sum clean
###############################################################################
### Tests & Simulation ###
###############################################################################
coverage:
@echo "Viewing test coverage..."
@go tool cover --html=coverage.out
stop-test-db:
@echo "Stopping test database..."
@docker stop athena-test-db || true && docker rm athena-test-db || true
start-test-db: stop-test-db
@echo "Starting test database..."
@docker run --name athena-test-db -e POSTGRES_USER=athena -e POSTGRES_PASSWORD=password -e POSTGRES_DB=athena -d -p 6432:5432 postgres
test-unit: start-test-db
@echo "Executing unit tests..."
@go test -mod=readonly -v -coverprofile coverage.txt ./...
.PHONY: coverage stop-docker-test start-docker-test test-unit
###############################################################################
### Linting ###
###############################################################################
golangci_lint_cmd=github.com/golangci/golangci-lint/cmd/golangci-lint
lint:
@echo "--> Running linter"
@go run $(golangci_lint_cmd) run --timeout=10m
lint-fix:
@echo "--> Running linter"
@go run $(golangci_lint_cmd) run --fix --out-format=tab --issues-exit-code=0
.PHONY: lint lint-fix
format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -path "./venv" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -path "./venv" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -path "./venv" | xargs goimports -w -local github.com/desmos-labs/athena
.PHONY: format
.PHONY: lint lint-fix format