github.com/pure-x-eth/consensus_tm@v0.0.0-20230502163723-e3c2ff987250/Makefile (about)

     1  PACKAGES=$(shell go list ./...)
     2  OUTPUT?=build/tendermint
     3  
     4  BUILD_TAGS?=tendermint
     5  
     6  # If building a release, please checkout the version tag to get the correct version setting
     7  ifneq ($(shell git symbolic-ref -q --short HEAD),)
     8  VERSION := unreleased-$(shell git symbolic-ref -q --short HEAD)-$(shell git rev-parse HEAD)
     9  else
    10  VERSION := $(shell git describe)
    11  endif
    12  
    13  LD_FLAGS = -X github.com/pure-x-eth/consensus_tm/version.TMCoreSemVer=$(VERSION)
    14  BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
    15  HTTPS_GIT := https://github.com/pure-x-eth/consensus_tm.git
    16  CGO_ENABLED ?= 0
    17  
    18  # handle nostrip
    19  ifeq (,$(findstring nostrip,$(TENDERMINT_BUILD_OPTIONS)))
    20    BUILD_FLAGS += -trimpath
    21    LD_FLAGS += -s -w
    22  endif
    23  
    24  # handle race
    25  ifeq (race,$(findstring race,$(TENDERMINT_BUILD_OPTIONS)))
    26    CGO_ENABLED=1
    27    BUILD_FLAGS += -race
    28  endif
    29  
    30  # handle cleveldb
    31  ifeq (cleveldb,$(findstring cleveldb,$(TENDERMINT_BUILD_OPTIONS)))
    32    CGO_ENABLED=1
    33    BUILD_TAGS += cleveldb
    34  endif
    35  
    36  # handle badgerdb
    37  ifeq (badgerdb,$(findstring badgerdb,$(TENDERMINT_BUILD_OPTIONS)))
    38    BUILD_TAGS += badgerdb
    39  endif
    40  
    41  # handle rocksdb
    42  ifeq (rocksdb,$(findstring rocksdb,$(TENDERMINT_BUILD_OPTIONS)))
    43    CGO_ENABLED=1
    44    BUILD_TAGS += rocksdb
    45  endif
    46  
    47  # handle boltdb
    48  ifeq (boltdb,$(findstring boltdb,$(TENDERMINT_BUILD_OPTIONS)))
    49    BUILD_TAGS += boltdb
    50  endif
    51  
    52  # allow users to pass additional flags via the conventional LDFLAGS variable
    53  LD_FLAGS += $(LDFLAGS)
    54  
    55  all: check build test install
    56  .PHONY: all
    57  
    58  include tests.mk
    59  
    60  ###############################################################################
    61  ###                                Build Tendermint                        ###
    62  ###############################################################################
    63  
    64  build:
    65  	CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(OUTPUT) ./cmd/tendermint/
    66  .PHONY: build
    67  
    68  install:
    69  	CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tendermint
    70  .PHONY: install
    71  
    72  
    73  ###############################################################################
    74  ###                                Mocks                                    ###
    75  ###############################################################################
    76  
    77  mockery:
    78  	go generate -run="./scripts/mockery_generate.sh" ./...
    79  .PHONY: mockery
    80  
    81  ###############################################################################
    82  ###                                Protobuf                                 ###
    83  ###############################################################################
    84  
    85  check-proto-deps:
    86  ifeq (,$(shell which protoc-gen-gogofaster))
    87  	@go install github.com/gogo/protobuf/protoc-gen-gogofaster@latest
    88  endif
    89  .PHONY: check-proto-deps
    90  
    91  check-proto-format-deps:
    92  ifeq (,$(shell which clang-format))
    93  	$(error "clang-format is required for Protobuf formatting. See instructions for your platform on how to install it.")
    94  endif
    95  .PHONY: check-proto-format-deps
    96  
    97  proto-gen: check-proto-deps
    98  	@echo "Generating Protobuf files"
    99  	@go run github.com/bufbuild/buf/cmd/buf generate
   100  	@mv ./proto/tendermint/abci/types.pb.go ./abci/types/
   101  .PHONY: proto-gen
   102  
   103  # These targets are provided for convenience and are intended for local
   104  # execution only.
   105  proto-lint: check-proto-deps
   106  	@echo "Linting Protobuf files"
   107  	@go run github.com/bufbuild/buf/cmd/buf lint
   108  .PHONY: proto-lint
   109  
   110  proto-format: check-proto-format-deps
   111  	@echo "Formatting Protobuf files"
   112  	@find . -name '*.proto' -path "./proto/*" -exec clang-format -i {} \;
   113  .PHONY: proto-format
   114  
   115  proto-check-breaking: check-proto-deps
   116  	@echo "Checking for breaking changes in Protobuf files against local branch"
   117  	@echo "Note: This is only useful if your changes have not yet been committed."
   118  	@echo "      Otherwise read up on buf's \"breaking\" command usage:"
   119  	@echo "      https://docs.buf.build/breaking/usage"
   120  	@go run github.com/bufbuild/buf/cmd/buf breaking --against ".git"
   121  .PHONY: proto-check-breaking
   122  
   123  proto-check-breaking-ci:
   124  	@go run github.com/bufbuild/buf/cmd/buf breaking --against $(HTTPS_GIT)#branch=v0.34.x
   125  .PHONY: proto-check-breaking-ci
   126  
   127  ###############################################################################
   128  ###                              Build ABCI                                 ###
   129  ###############################################################################
   130  
   131  build_abci:
   132  	@go build -mod=readonly -i ./abci/cmd/...
   133  .PHONY: build_abci
   134  
   135  install_abci:
   136  	@go install -mod=readonly ./abci/cmd/...
   137  .PHONY: install_abci
   138  
   139  ###############################################################################
   140  ###                              Distribution                               ###
   141  ###############################################################################
   142  
   143  # dist builds binaries for all platforms and packages them for distribution
   144  # TODO add abci to these scripts
   145  dist:
   146  	@BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'"
   147  .PHONY: dist
   148  
   149  go-mod-cache: go.sum
   150  	@echo "--> Download go modules to local cache"
   151  	@go mod download
   152  .PHONY: go-mod-cache
   153  
   154  go.sum: go.mod
   155  	@echo "--> Ensure dependencies have not been modified"
   156  	@go mod verify
   157  	@go mod tidy
   158  
   159  draw_deps:
   160  	@# requires brew install graphviz or apt-get install graphviz
   161  	go get github.com/RobotsAndPencils/goviz
   162  	@goviz -i github.com/pure-x-eth/consensus_tm/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
   163  .PHONY: draw_deps
   164  
   165  get_deps_bin_size:
   166  	@# Copy of build recipe with additional flags to perform binary size analysis
   167  	$(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/ 2>&1))
   168  	@find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
   169  	@echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
   170  .PHONY: get_deps_bin_size
   171  
   172  ###############################################################################
   173  ###                                  Libs                                   ###
   174  ###############################################################################
   175  
   176  # generates certificates for TLS testing in remotedb and RPC server
   177  gen_certs: clean_certs
   178  	certstrap init --common-name "tendermint.com" --passphrase ""
   179  	certstrap request-cert --common-name "server" -ip "127.0.0.1" --passphrase ""
   180  	certstrap sign "server" --CA "tendermint.com" --passphrase ""
   181  	mv out/server.crt rpc/jsonrpc/server/test.crt
   182  	mv out/server.key rpc/jsonrpc/server/test.key
   183  	rm -rf out
   184  .PHONY: gen_certs
   185  
   186  # deletes generated certificates
   187  clean_certs:
   188  	rm -f rpc/jsonrpc/server/test.crt
   189  	rm -f rpc/jsonrpc/server/test.key
   190  .PHONY: clean_certs
   191  
   192  ###############################################################################
   193  ###                  Formatting, linting, and vetting                       ###
   194  ###############################################################################
   195  
   196  format:
   197  	find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s
   198  	find . -name '*.go' -type f -not -path "*.git*"  -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/pure-x-eth/consensus_tm
   199  .PHONY: format
   200  
   201  lint:
   202  	@echo "--> Running linter"
   203  	@go run github.com/golangci/golangci-lint/cmd/golangci-lint run
   204  .PHONY: lint
   205  
   206  DESTINATION = ./index.html.md
   207  
   208  ###############################################################################
   209  ###                           Documentation                                 ###
   210  ###############################################################################
   211  
   212  build-docs:
   213  	@cd docs && \
   214  	while read -r branch path_prefix; do \
   215  		(git checkout $${branch} && npm ci && VUEPRESS_BASE="/$${path_prefix}/" npm run build) ; \
   216  		mkdir -p ~/output/$${path_prefix} ; \
   217  		cp -r .vuepress/dist/* ~/output/$${path_prefix}/ ; \
   218  		cp ~/output/$${path_prefix}/index.html ~/output ; \
   219  	done < versions ;
   220  .PHONY: build-docs
   221  
   222  sync-docs:
   223  	cd ~/output && \
   224  	echo "role_arn = ${DEPLOYMENT_ROLE_ARN}" >> /root/.aws/config ; \
   225  	echo "CI job = ${CIRCLE_BUILD_URL}" >> version.html ; \
   226  	aws s3 sync . s3://${WEBSITE_BUCKET} --profile terraform --delete ; \
   227  	aws cloudfront create-invalidation --distribution-id ${CF_DISTRIBUTION_ID} --profile terraform --path "/*" ;
   228  .PHONY: sync-docs
   229  
   230  ###############################################################################
   231  ###                            Docker image                                 ###
   232  ###############################################################################
   233  
   234  build-docker: build-linux
   235  	cp $(OUTPUT) DOCKER/tendermint
   236  	docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
   237  	rm -rf DOCKER/tendermint
   238  .PHONY: build-docker
   239  
   240  ###############################################################################
   241  ###                       Local testnet using docker                        ###
   242  ###############################################################################
   243  
   244  # Build linux binary on other platforms
   245  build-linux:
   246  	GOOS=linux GOARCH=amd64 $(MAKE) build
   247  .PHONY: build-linux
   248  
   249  build-docker-localnode:
   250  	@cd networks/local && make
   251  .PHONY: build-docker-localnode
   252  
   253  # Runs `make build TENDERMINT_BUILD_OPTIONS=cleveldb` from within an Amazon
   254  # Linux (v2)-based Docker build container in order to build an Amazon
   255  # Linux-compatible binary. Produces a compatible binary at ./build/tendermint
   256  build_c-amazonlinux:
   257  	$(MAKE) -C ./DOCKER build_amazonlinux_buildimage
   258  	docker run --rm -it -v `pwd`:/tendermint tendermint/tendermint:build_c-amazonlinux
   259  .PHONY: build_c-amazonlinux
   260  
   261  # Run a 4-node testnet locally
   262  localnet-start: localnet-stop build-docker-localnode
   263  	@if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --config /etc/tendermint/config-template.toml --o . --starting-ip-address 192.167.10.2; fi
   264  	docker-compose up
   265  .PHONY: localnet-start
   266  
   267  # Stop testnet
   268  localnet-stop:
   269  	docker-compose down
   270  .PHONY: localnet-stop
   271  
   272  # Build hooks for dredd, to skip or add information on some steps
   273  build-contract-tests-hooks:
   274  ifeq ($(OS),Windows_NT)
   275  	go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests.exe ./cmd/contract_tests
   276  else
   277  	go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests ./cmd/contract_tests
   278  endif
   279  .PHONY: build-contract-tests-hooks
   280  
   281  # Run a nodejs tool to test endpoints against a localnet
   282  # The command takes care of starting and stopping the network
   283  # prerequisits: build-contract-tests-hooks build-linux
   284  # the two build commands were not added to let this command run from generic containers or machines.
   285  # The binaries should be built beforehand
   286  contract-tests:
   287  	dredd
   288  .PHONY: contract-tests