github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/Makefile (about)

     1  #!/usr/bin/make -f
     2  
     3  BUILDDIR ?= $(CURDIR)/build
     4  
     5  BUILD_TAGS?=tendermint
     6  
     7  # If building a release, please checkout the version tag to get the correct version setting
     8  ifneq ($(shell git symbolic-ref -q --short HEAD),)
     9  VERSION := unreleased-$(shell git symbolic-ref -q --short HEAD)-$(shell git rev-parse HEAD)
    10  else
    11  VERSION := $(shell git describe)
    12  endif
    13  
    14  LD_FLAGS = -X github.com/tendermint/tendermint/version.TMVersion=$(VERSION)
    15  BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
    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 test/Makefile
    59  
    60  ###############################################################################
    61  ###                                Build Tendermint                         ###
    62  ###############################################################################
    63  
    64  build: $(BUILDDIR)/
    65  	CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(BUILDDIR)/ ./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  $(BUILDDIR)/:
    73  	mkdir -p $@
    74  
    75  ###############################################################################
    76  ###                                Protobuf                                 ###
    77  ###############################################################################
    78  
    79  check-proto-deps:
    80  ifeq (,$(shell which protoc-gen-gogofaster))
    81  	$(error "gogofaster plugin for protoc is required. Run 'go install github.com/gogo/protobuf/protoc-gen-gogofaster@latest' to install")
    82  endif
    83  .PHONY: check-proto-deps
    84  
    85  check-proto-format-deps:
    86  ifeq (,$(shell which clang-format))
    87  	$(error "clang-format is required for Protobuf formatting. See instructions for your platform on how to install it.")
    88  endif
    89  .PHONY: check-proto-format-deps
    90  
    91  proto-gen: check-proto-deps
    92  	@echo "Generating Protobuf files"
    93  	@go run github.com/bufbuild/buf/cmd/buf generate
    94  	@mv ./proto/tendermint/abci/types.pb.go ./abci/types/
    95  .PHONY: proto-gen
    96  
    97  # These targets are provided for convenience and are intended for local
    98  # execution only.
    99  proto-lint: check-proto-deps
   100  	@echo "Linting Protobuf files"
   101  	@go run github.com/bufbuild/buf/cmd/buf lint
   102  .PHONY: proto-lint
   103  
   104  proto-format: check-proto-format-deps
   105  	@echo "Formatting Protobuf files"
   106  	@find . -name '*.proto' -path "./proto/*" -exec clang-format -i {} \;
   107  .PHONY: proto-format
   108  
   109  proto-check-breaking: check-proto-deps
   110  	@echo "Checking for breaking changes in Protobuf files against local branch"
   111  	@echo "Note: This is only useful if your changes have not yet been committed."
   112  	@echo "      Otherwise read up on buf's \"breaking\" command usage:"
   113  	@echo "      https://docs.buf.build/breaking/usage"
   114  	@go run github.com/bufbuild/buf/cmd/buf breaking --against ".git"
   115  .PHONY: proto-check-breaking
   116  
   117  ###############################################################################
   118  ###                              Build ABCI                                 ###
   119  ###############################################################################
   120  
   121  build_abci:
   122  	@go build -mod=readonly -i ./abci/cmd/...
   123  .PHONY: build_abci
   124  
   125  install_abci:
   126  	@go install -mod=readonly ./abci/cmd/...
   127  .PHONY: install_abci
   128  
   129  ###############################################################################
   130  ###				Privval Server                              ###
   131  ###############################################################################
   132  
   133  build_privval_server:
   134  	@go build -mod=readonly -o $(BUILDDIR)/ -i ./cmd/priv_val_server/...
   135  .PHONY: build_privval_server
   136  
   137  generate_test_cert:
   138  	# generate self signing ceritificate authority
   139  	@certstrap init --common-name "root CA" --expires "20 years"
   140  	# generate server cerificate
   141  	@certstrap request-cert -cn server -ip 127.0.0.1
   142  	# self-sign server cerificate with rootCA
   143  	@certstrap sign server --CA "root CA"
   144  	# generate client cerificate
   145  	@certstrap request-cert -cn client -ip 127.0.0.1
   146  	# self-sign client cerificate with rootCA
   147  	@certstrap sign client --CA "root CA"
   148  .PHONY: generate_test_cert
   149  
   150  ###############################################################################
   151  ###                              Distribution                               ###
   152  ###############################################################################
   153  
   154  # dist builds binaries for all platforms and packages them for distribution
   155  # TODO add abci to these scripts
   156  dist:
   157  	@BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'"
   158  .PHONY: dist
   159  
   160  go-mod-cache: go.sum
   161  	@echo "--> Download go modules to local cache"
   162  	@go mod download
   163  .PHONY: go-mod-cache
   164  
   165  go.sum: go.mod
   166  	@echo "--> Ensure dependencies have not been modified"
   167  	@go mod verify
   168  	@go mod tidy
   169  
   170  draw_deps:
   171  	@# requires brew install graphviz or apt-get install graphviz
   172  	go install github.com/RobotsAndPencils/goviz@latest
   173  	@goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
   174  .PHONY: draw_deps
   175  
   176  get_deps_bin_size:
   177  	@# Copy of build recipe with additional flags to perform binary size analysis
   178  	$(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(BUILDDIR)/ ./cmd/tendermint/ 2>&1))
   179  	@find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
   180  	@echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
   181  .PHONY: get_deps_bin_size
   182  
   183  ###############################################################################
   184  ###                                  Libs                                   ###
   185  ###############################################################################
   186  
   187  # generates certificates for TLS testing in remotedb and RPC server
   188  gen_certs: clean_certs
   189  	certstrap init --common-name "tendermint.com" --passphrase ""
   190  	certstrap request-cert --common-name "server" -ip "127.0.0.1" --passphrase ""
   191  	certstrap sign "server" --CA "tendermint.com" --passphrase ""
   192  	mv out/server.crt rpc/jsonrpc/server/test.crt
   193  	mv out/server.key rpc/jsonrpc/server/test.key
   194  	rm -rf out
   195  .PHONY: gen_certs
   196  
   197  # deletes generated certificates
   198  clean_certs:
   199  	rm -f rpc/jsonrpc/server/test.crt
   200  	rm -f rpc/jsonrpc/server/test.key
   201  .PHONY: clean_certs
   202  
   203  ###############################################################################
   204  ###                  Formatting, linting, and vetting                       ###
   205  ###############################################################################
   206  
   207  format:
   208  	find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s
   209  	find . -name '*.go' -type f -not -path "*.git*"  -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/tendermint/tendermint
   210  .PHONY: format
   211  
   212  lint:
   213  	@echo "--> Running linter"
   214  	go run github.com/golangci/golangci-lint/cmd/golangci-lint run
   215  .PHONY: lint
   216  
   217  DESTINATION = ./index.html.md
   218  
   219  ###############################################################################
   220  ###                           Documentation                                 ###
   221  ###############################################################################
   222  # todo remove once tendermint.com DNS is solved
   223  build-docs:
   224  	@cd docs && \
   225  	while read -r branch path_prefix; do \
   226  		( git checkout $${branch} && npm ci --quiet && \
   227  			VUEPRESS_BASE="/$${path_prefix}/" npm run build --quiet ) ; \
   228  		mkdir -p ~/output/$${path_prefix} ; \
   229  		cp -r .vuepress/dist/* ~/output/$${path_prefix}/ ; \
   230  		cp ~/output/$${path_prefix}/index.html ~/output ; \
   231  	done < versions ;
   232  .PHONY: build-docs
   233  
   234  ###############################################################################
   235  ###                            Docker image                                 ###
   236  ###############################################################################
   237  
   238  build-docker:
   239  	docker build --label=tendermint --tag="tendermint/tendermint" -f DOCKER/Dockerfile .
   240  .PHONY: build-docker
   241  
   242  
   243  ###############################################################################
   244  ###                                Mocks                                    ###
   245  ###############################################################################
   246  
   247  mockery:
   248  	go generate -run="./scripts/mockery_generate.sh" ./...
   249  .PHONY: mockery
   250  
   251  ###############################################################################
   252  ###                               Metrics                                   ###
   253  ###############################################################################
   254  
   255  metrics: testdata-metrics
   256  	go generate -run="scripts/metricsgen" ./...
   257  .PHONY: metrics
   258  
   259  	# By convention, the go tool ignores subdirectories of directories named
   260  	# 'testdata'. This command invokes the generate command on the folder directly
   261  	# to avoid this.
   262  testdata-metrics:
   263  	ls ./scripts/metricsgen/testdata | xargs -I{} go generate -run="scripts/metricsgen" ./scripts/metricsgen/testdata/{}
   264  .PHONY: testdata-metrics
   265  
   266  ###############################################################################
   267  ###                       Local testnet using docker                        ###
   268  ###############################################################################
   269  
   270  # Build linux binary on other platforms
   271  build-linux:
   272  	GOOS=linux GOARCH=amd64 $(MAKE) build
   273  .PHONY: build-linux
   274  
   275  build-docker-localnode:
   276  	@cd networks/local && make
   277  .PHONY: build-docker-localnode
   278  
   279  # Runs `make build TENDERMINT_BUILD_OPTIONS=cleveldb` from within an Amazon
   280  # Linux (v2)-based Docker build container in order to build an Amazon
   281  # Linux-compatible binary. Produces a compatible binary at ./build/tendermint
   282  build_c-amazonlinux:
   283  	$(MAKE) -C ./DOCKER build_amazonlinux_buildimage
   284  	docker run --rm -it -v `pwd`:/tendermint tendermint/tendermint:build_c-amazonlinux
   285  .PHONY: build_c-amazonlinux
   286  
   287  # Run a 4-node testnet locally
   288  localnet-start: localnet-stop build-docker-localnode
   289  	@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
   290  	docker-compose up
   291  .PHONY: localnet-start
   292  
   293  # Stop testnet
   294  localnet-stop:
   295  	docker-compose down
   296  .PHONY: localnet-stop
   297  
   298  # Build hooks for dredd, to skip or add information on some steps
   299  build-contract-tests-hooks:
   300  ifeq ($(OS),Windows_NT)
   301  	go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests.exe ./cmd/contract_tests
   302  else
   303  	go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests ./cmd/contract_tests
   304  endif
   305  .PHONY: build-contract-tests-hooks
   306  
   307  # Run a nodejs tool to test endpoints against a localnet
   308  # The command takes care of starting and stopping the network
   309  # prerequisits: build-contract-tests-hooks build-linux
   310  # the two build commands were not added to let this command run from generic containers or machines.
   311  # The binaries should be built beforehand
   312  contract-tests:
   313  	dredd
   314  .PHONY: contract-tests
   315  
   316  clean:
   317  	rm -rf $(CURDIR)/artifacts/ $(BUILDDIR)/
   318  
   319  build-reproducible:
   320  	docker rm latest-build || true
   321  	docker run --volume=$(CURDIR):/sources:ro \
   322  		--env TARGET_PLATFORMS='linux/amd64 linux/arm64 darwin/amd64 windows/amd64' \
   323  		--env APP=tendermint \
   324  		--env COMMIT=$(shell git rev-parse --short=8 HEAD) \
   325  		--env VERSION=$(shell git describe --tags) \
   326  		--name latest-build cosmossdk/rbuilder:latest
   327  	docker cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/
   328  .PHONY: build-reproducible
   329  
   330  # Implements test splitting and running. This is pulled directly from
   331  # the github action workflows for better local reproducibility.
   332  
   333  GO_TEST_FILES != find $(CURDIR) -name "*_test.go"
   334  
   335  # default to four splits by default
   336  NUM_SPLIT ?= 4
   337  
   338  $(BUILDDIR):
   339  	mkdir -p $@
   340  
   341  # The format statement filters out all packages that don't have tests.
   342  # Note we need to check for both in-package tests (.TestGoFiles) and
   343  # out-of-package tests (.XTestGoFiles).
   344  $(BUILDDIR)/packages.txt:$(GO_TEST_FILES) $(BUILDDIR)
   345  	go list -f "{{ if (or .TestGoFiles .XTestGoFiles) }}{{ .ImportPath }}{{ end }}" ./... | sort > $@
   346  
   347  split-test-packages:$(BUILDDIR)/packages.txt
   348  	split -d -n l/$(NUM_SPLIT) $< $<.
   349  test-group-%:split-test-packages
   350  	cat $(BUILDDIR)/packages.txt.$* | xargs go test -mod=readonly -timeout=10m -race -coverprofile=$(BUILDDIR)/$*.profile.out