github.com/iotexproject/iotex-core@v1.14.1-rc1/Makefile (about) 1 ######################################################################################################################## 2 # Copyright (c) 2019 IoTeX Foundation 3 # This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 4 # or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 5 # This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 6 ######################################################################################################################## 7 8 # Go parameters 9 GOCMD=go 10 GOVET=$(GOCMD) vet 11 GOBUILD=$(GOCMD) build 12 GOINSTALL=$(GOCMD) install 13 GOCLEAN=$(GOCMD) clean 14 GOTEST=$(GOCMD) test 15 GOGET=$(GOCMD) get 16 GOPATH=$(shell go env GOPATH) 17 BUILD_TARGET_SERVER=server 18 BUILD_TARGET_ACTINJV2=actioninjectorv2 19 BUILD_TARGET_ADDRGEN=addrgen 20 BUILD_TARGET_IOCTL=ioctl 21 BUILD_TARGET_NEWIOCTL=newioctl 22 BUILD_TARGET_XCTL=xctl 23 BUILD_TARGET_NEWXCTL=newxctl 24 BUILD_TARGET_MINICLUSTER=minicluster 25 BUILD_TARGET_RECOVER=recover 26 BUILD_TARGET_READTIP=readtip 27 BUILD_TARGET_IOMIGRATER=iomigrater 28 BUILD_TARGET_OS=$(shell go env GOOS) 29 BUILD_TARGET_ARCH=$(shell go env GOARCH) 30 31 # Pkgs 32 ALL_PKGS := $(shell go list ./... ) 33 PKGS := $(shell go list ./... | grep -v /test/ ) 34 ROOT_PKG := "github.com/iotexproject/iotex-core" 35 36 # Docker parameters 37 DOCKERCMD=docker 38 39 # Package Info 40 ifndef PACKAGE_VERSION 41 PACKAGE_VERSION := $(shell git describe --tags) 42 endif 43 ifndef PACKAGE_COMMIT_ID 44 PACKAGE_COMMIT_ID := $(shell git rev-parse HEAD) 45 endif 46 ifndef GIT_STATUS 47 GIT_STATUS := $(shell git status --porcelain) 48 ifdef GIT_STATUS 49 GIT_STATUS := "dirty" 50 else 51 GIT_STATUS := "clean" 52 endif 53 endif 54 GO_VERSION := $(shell go version) 55 BUILD_TIME=$(shell date +%F-%Z/%T) 56 VersionImportPath := github.com/iotexproject/iotex-core/pkg/version 57 PackageFlags += -X '$(VersionImportPath).PackageVersion=$(PACKAGE_VERSION)' 58 PackageFlags += -X '$(VersionImportPath).PackageCommitID=$(PACKAGE_COMMIT_ID)' 59 PackageFlags += -X '$(VersionImportPath).GitStatus=$(GIT_STATUS)' 60 PackageFlags += -X '$(VersionImportPath).GoVersion=$(GO_VERSION)' 61 PackageFlags += -X '$(VersionImportPath).BuildTime=$(BUILD_TIME)' 62 PackageFlags += -s -w 63 64 TEST_IGNORE= ".git,vendor" 65 COV_OUT := profile.coverprofile 66 COV_REPORT := overalls.coverprofile 67 COV_HTML := coverage.html 68 69 LINT_LOG := lint.log 70 71 V ?= 0 72 ifeq ($(V),0) 73 ECHO_V = @ 74 else 75 VERBOSITY_FLAG = -v 76 DEBUG_FLAG = -debug 77 endif 78 79 default: clean build test 80 all: clean build-all test 81 82 .PHONY: build 83 build: ioctl 84 $(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_SERVER) -v ./$(BUILD_TARGET_SERVER) 85 86 .PHONY: build-all 87 build-all: build build-actioninjector build-addrgen build-minicluster build-staterecoverer build-readtip 88 89 .PHONY: build-actioninjector 90 build-actioninjector: 91 $(GOBUILD) -o ./bin/$(BUILD_TARGET_ACTINJV2) -v ./tools/actioninjector.v2 92 93 .PHONY: build-addrgen 94 build-addrgen: 95 $(GOBUILD) -o ./bin/$(BUILD_TARGET_ADDRGEN) -v ./tools/addrgen 96 97 .PHONY: build-minicluster 98 build-minicluster: 99 $(GOBUILD) -o ./bin/$(BUILD_TARGET_MINICLUSTER) -v ./tools/minicluster 100 101 .PHONY: build-staterecoverer 102 build-staterecoverer: 103 $(GOBUILD) -o ./bin/$(BUILD_TARGET_RECOVER) -v ./tools/staterecoverer 104 105 .PHONY: build-readtip 106 build-readtip: 107 $(GOBUILD) -o ./bin/$(BUILD_TARGET_READTIP) -v ./tools/readtip 108 109 .PHONY: fmt 110 fmt: 111 $(GOCMD) fmt ./... 112 $(GOCMD) mod tidy 113 114 .PHONY: lint 115 lint: 116 go list ./... | xargs $(GOVET) 117 118 .PHONY: lint-rich 119 lint-rich: 120 $(ECHO_V)rm -rf $(LINT_LOG) 121 @echo "Running golangcli lint..." 122 $(ECHO_V)golangci-lint run $(VERBOSITY_FLAG)--enable-all -D gochecknoglobals -D prealloc -D lll -D interfacer -D scopelint -D maligned -D dupl| tee -a $(LINT_LOG) 123 124 .PHONY: test 125 test: fmt 126 $(GOTEST) -short -race ./... 127 128 .PHONY: test-rich 129 test-rich: 130 @echo "Running test cases..." 131 $(ECHO_V)rm -f $(COV_REPORT) 132 $(ECHO_V)touch $(COV_OUT) 133 $(ECHO_V)RICHGO_FORCE_COLOR=1 overalls \ 134 -project=$(ROOT_PKG) \ 135 -go-binary=richgo \ 136 -ignore $(TEST_IGNORE) \ 137 $(DEBUG_FLAG) -- \ 138 $(VERBOSITY_FLAG) -short | \ 139 grep -v -e "Test args" -e "Processing" 140 141 .PHONY: test-html 142 test-html: test-rich 143 @echo "Generating test report html..." 144 $(ECHO_V)gocov convert $(COV_REPORT) | gocov-html > $(COV_HTML) 145 $(ECHO_V)open $(COV_HTML) 146 147 .PHONY: mockgen 148 mockgen: 149 @./misc/scripts/mockgen.sh 150 151 .PHONY: stringer 152 stringer: 153 sh ./misc/scripts/stringer.sh 154 155 .PHONY: license 156 license: 157 @./misc/scripts/licenseheader.sh 158 159 .PHONY: dev-deps 160 dev-deps: 161 @echo "Installing dev dependencies..." 162 $(ECHO_V)go get -u github.com/golangci/golangci-lint/cmd/golangci-lint 163 $(ECHO_V)go get -u github.com/kyoh86/richgo 164 $(ECHO_V)go get -u github.com/axw/gocov/gocov 165 $(ECHO_V)go get -u gopkg.in/matm/v1/gocov-html 166 $(ECHO_V)go get -u github.com/go-playground/overalls 167 168 .PHONY: clean 169 clean: 170 @echo "Cleaning..." 171 $(ECHO_V)rm -rf ./bin/$(BUILD_TARGET_SERVER) 172 $(ECHO_V)rm -rf ./bin/$(BUILD_TARGET_ADDRGEN) 173 $(ECHO_V)rm -rf ./bin/$(BUILD_TARGET_IOTC) 174 $(ECHO_V)rm -rf ./e2etest/*chain*.db 175 $(ECHO_V)rm -rf *chain*.db 176 $(ECHO_V)rm -rf *trie*.db 177 $(ECHO_V)rm -rf *index*.db 178 $(ECHO_V)rm -rf *systemlog*.db 179 $(ECHO_V)rm -rf *candidate.index*.db 180 $(ECHO_V)rm -rf $(COV_REPORT) $(COV_HTML) $(LINT_LOG) 181 $(ECHO_V)find . -name $(COV_OUT) -delete 182 $(ECHO_V)find . -name $(TESTBED_COV_OUT) -delete 183 $(ECHO_V)$(GOCLEAN) -i $(PKGS) 184 185 .PHONY: reboot 186 reboot: 187 $(ECHO_V)rm -rf *chain*.db 188 $(ECHO_V)rm -rf *trie*.db 189 $(ECHO_V)rm -rf *index*.db 190 $(ECHO_V)rm -rf *candidate.index*.db 191 $(ECHO_V)rm -rf ./e2etest/*chain*.db 192 $(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_SERVER) -v ./$(BUILD_TARGET_SERVER) 193 ./bin/$(BUILD_TARGET_SERVER) -plugin=gateway -config-path=./config/standalone-config.yaml -genesis-path=./config/standalone-genesis.yaml 194 195 .PHONY: run 196 run: 197 $(ECHO_V)rm -rf ./e2etest/*chain*.db 198 $(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_SERVER) -v ./$(BUILD_TARGET_SERVER) 199 sudo mkdir -p /var/data /var/log 200 sudo chown ${USER} /var/data /var/log 201 ./bin/$(BUILD_TARGET_SERVER) -plugin=gateway -config-path=./config/standalone-config.yaml -genesis-path=./config/standalone-genesis.yaml 202 203 .PHONY: docker 204 docker: 205 DOCKER_BUILDKIT=1 $(DOCKERCMD) build -t $(USER)/iotex-core:latest . 206 207 .PHONY: docker-scan 208 docker-scan: docker 209 DOCKER_BUILDKIT=1 $(DOCKERCMD) login 210 DOCKER_BUILDKIT=1 $(DOCKERCMD) scan $(USER)/iotex-core:latest . 211 212 .PHONY: minicluster 213 minicluster: 214 $(ECHO_V)rm -rf *chain*.db 215 $(ECHO_V)rm -rf *trie*.db 216 $(ECHO_V)rm -rf *index*.db 217 $(ECHO_V)rm -rf *candidate.index*.db 218 $(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_MINICLUSTER) -v ./tools/minicluster 219 ./bin/$(BUILD_TARGET_MINICLUSTER) 220 221 .PHONY: nightlybuild 222 nightlybuild: 223 $(ECHO_V)rm -rf *chain*.db 224 $(ECHO_V)rm -rf *trie*.db 225 $(ECHO_V)rm -rf *index*.db 226 $(ECHO_V)rm -rf *candidate.index*.db 227 $(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_MINICLUSTER) -v ./tools/minicluster 228 ./bin/$(BUILD_TARGET_MINICLUSTER) -timeout=14400 -fp-token=true 229 230 .PHONY: recover 231 recover: 232 $(ECHO_V)rm -rf ./e2etest/*chain*.db 233 $(GOBUILD) -o ./bin/$(BUILD_TARGET_RECOVER) -v ./tools/staterecoverer 234 ./bin/$(BUILD_TARGET_RECOVER) -plugin=gateway 235 236 .PHONY: ioctl 237 ioctl: 238 $(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_IOCTL) -v ./tools/ioctl 239 240 .PHONY: newioctl 241 newioctl: 242 $(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_NEWIOCTL) -v ./tools/newioctl 243 244 .PHONY: ioctl-cross 245 ioctl-cross: 246 $(DOCKERCMD) pull techknowlogick/xgo:latest 247 $(GOCMD) get src.techknowlogick.com/xgo 248 mkdir -p $(GOPATH)/src 249 sudo cp ./tools/ioctl/ioctl.go $(GOPATH)/src 250 cd $(GOPATH)/src && sudo rm -f go.mod && $(GOCMD) mod init main && $(GOCMD) mod tidy 251 cd $(GOPATH)/src && $(GOPATH)/bin/xgo --targets=$(BUILD_TARGET_OS)/$(BUILD_TARGET_ARCH) . 252 mkdir -p ./bin/$(BUILD_TARGET_IOCTL) && sudo mv $(GOPATH)/src/main-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH) ./bin/$(BUILD_TARGET_IOCTL)/ioctl-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH) 253 254 .PHONY: newioctl-cross 255 newioctl-cross: 256 $(DOCKERCMD) pull techknowlogick/xgo:latest 257 $(GOCMD) get src.techknowlogick.com/xgo 258 mkdir -p $(GOPATH)/src 259 sudo cp ./tools/newioctl/ioctl.go $(GOPATH)/src 260 cd $(GOPATH)/src && sudo rm -f go.mod && $(GOCMD) mod init main && $(GOCMD) mod tidy 261 cd $(GOPATH)/src && $(GOPATH)/bin/xgo --targets=$(BUILD_TARGET_OS)/$(BUILD_TARGET_ARCH) . 262 mkdir -p ./bin/$(BUILD_TARGET_NEWIOCTL) && sudo mv $(GOPATH)/src/main-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH) ./bin/$(BUILD_TARGET_NEWIOCTL)/ioctl-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH) 263 264 .PHONY: xctl 265 xctl: 266 $(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_XCTL) -v ./tools/xctl 267 268 .PHONY: newxctl 269 newxctl: 270 $(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_NEWXCTL) -v ./tools/newxctl 271 272 .PHONY: iomigrater 273 iomigrater: 274 $(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_IOMIGRATER) -v ./tools/iomigrater