-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
116 lines (96 loc) · 4.67 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
112
113
114
115
116
include Makefile.ledger
git_tag=$(shell git describe --tags --abbrev=0)
git_commit=$(shell git rev-list -1 HEAD)
tags = -X github.com/cosmos/cosmos-sdk/version.Name=dfinance \
-X github.com/cosmos/cosmos-sdk/version.ServerName=dnode \
-X github.com/cosmos/cosmos-sdk/version.ClientName=dncli \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(git_commit) \
-X github.com/cosmos/cosmos-sdk/version.Version=${git_tag} \
build_dir=./.build
swagger_dir=$(build_dir)/swagger
cosmos_dir=$(swagger_dir)/cosmos-sdk
dnode = ./cmd/dnode
dncli =./cmd/dncli
cosmos_version = $(shell awk '/replace github.com\/cosmos\/cosmos-sdk => github.com\/dfinance\/cosmos-sdk/ {print $$NF}' < go.mod)
all: install
install: go.sum install-dnode install-dncli
swagger-ui: swagger-ui-deps swagger-ui-build
tests: | test-unit test-cli test-rest test-integ
install-dnode:
GO111MODULE=on go install -ldflags "$(tags)" -tags "$(build_tags)" $(dnode)
install-dncli:
GO111MODULE=on go install -ldflags "$(tags)" -tags "$(build_tags)" $(dncli)
lint:
@echo "--> Running Golang linter (unused variable / function warning are skipped)"
golangci-lint run --exclude 'unused'
test-unit:
@echo "--> Testing: UNIT tests"
go test ./... -tags=unit -count=1
test-cli: install
@echo "--> Testing: dncli CLI tests"
go test ./... -tags=cli -count=1
test-rest: install
@echo "--> Testing: dncli REST endpoints tests"
go test ./... -tags=rest -count=1
test-integ: install
@echo "--> Testing: dnode <-> dvm integration tests (using Binary)"
DN_DVM_INTEG_TESTS_USE=binary go test ./... -v -tags=integ -count=1
simulate:
#go test ./helpers/tests/simulator -run TestSimInflation -tags=simulator -v -timeout=24h -memprofile memprofile.out
go test ./helpers/tests/simulator -run TestSimInflation -tags=simulator -v -timeout=24h
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
swagger-ui-deps:
@echo "--> Preparing deps for building Swagger API specificaion"
@echo "-> Make tmp build folder"
rm -rf $(swagger_dir)
mkdir -p $(cosmos_dir)
@echo "-> Cosmos-SDK $(cosmos_version) checkout"
git -C $(swagger_dir) clone --depth 1 --branch $(cosmos_version) https://github.com/dfinance/cosmos-sdk.git
@echo "-> Fetching Golang libraries: swag, statik"
go get -u github.com/swaggo/swag/cmd/[email protected]
go get github.com/g3co/go-swagger-merger
swagger_auto_dir=$(swagger_dir)"/swagger-auto"
modules_dir = ./x
swagger-ui-build: $(modules_dir)/*
@echo "--> Building Swagger API specificaion, merging it to Cosmos SDK"
@echo "-> Build swagger.yaml"
rm -rf $(swagger_auto_dir)
mkdir -p $(swagger_auto_dir)/x
@echo "swagger: '2.0'"> $(swagger_auto_dir)/swagger.yaml
# generate swagger files for the each module
# creates tmp dirs for sdk types in the each dir and removes it after work
for file in $^ ; do \
cp -r $(cosmos_dir)/types ./$${file}/tmp_sdk; \
mkdir -p ./$${file}/tmp_auth; \
cp $(cosmos_dir)/x/auth/types/stdtx.go ./$${file}/tmp_auth; \
swag init --dir ./$${file} --output $(swagger_auto_dir)/$${file} --generalInfo ./module.go; \
rm -rf ./$${file}/tmp_sdk ./$${file}/tmp_auth; \
done
# merge autogenerated module swaggers
for file in $(swagger_auto_dir)/x/* ; do \
go-swagger-merger -o $(swagger_auto_dir)/swagger.yaml $(swagger_auto_dir)/swagger.yaml $${file}/swagger.yaml; \
done
# merge with the cosmos-sdk swagger
go-swagger-merger -o ./cmd/dncli/docs/swagger.yaml \
$(cosmos_dir)/client/lcd/swagger-auto/swagger.yaml \
$(swagger_auto_dir)/swagger.yaml
@echo "-> Building swagger.go file"
echo "// Code generated by Makefile. DO NOT EDIT.\n" > ./cmd/dncli/docs/swagger.go
echo "package docs\n\nconst Swagger = \`" >> ./cmd/dncli/docs/swagger.go
cat ./cmd/dncli/docs/swagger.yaml | sed "s/\`/'/g" >> ./cmd/dncli/docs/swagger.go
echo "\`" >> ./cmd/dncli/docs/swagger.go
rm ./cmd/dncli/docs/swagger.yaml
## binaries builds (xgo required: https://github.com/karalabe/xgo)
binaries: go.sum
@echo ${git_tag}
@echo "Prepare XGO dependencies"
mkdir -p ./builds
go get github.com/crazy-max/xgo
@echo "Build targets (Go 1.14): windows/amd64, linux/amd64, darwin/amd64"
xgo -go 1.14.x --ldflags='$(tags)' --tags='ledger' --out='./builds/dncli-${git_tag}' -targets='windows/amd64,linux/amd64,darwin/amd64' ${dncli}
## Legacy builds (as a reference)
#GOOS=darwin GOARCH=amd64 GO111MODULE=on go build --ldflags "$(tags)" -tags "$(build_tags)" -o ./builds/dncli-${git_tag}-darwin-amd64 ${dncli}
#GOOS=linux GOARCH=amd64 GO111MODULE=on go build --ldflags "$(tags)" -tags "$(build_tags)" -o ./builds/dncli-${git_tag}-linux-amd64 ${dncli}
#GOOS=windows GOARCH=amd64 GO111MODULE=on go build --ldflags "$(tags)" -tags "$(build_tags)" -o ./builds/dncli-${git_tag}-windows-amd64.exe ${dncli}