From cd27adecdb3a6ad7d4b491e39f536240eeec6ff6 Mon Sep 17 00:00:00 2001 From: Rico Date: Fri, 11 Feb 2022 17:31:10 +0800 Subject: [PATCH] ci: Tidy up Makefile refs oursky/likecoin-chain#1 --- Makefile | 144 ++++++++++++++++++++++--------------------------------- 1 file changed, 57 insertions(+), 87 deletions(-) diff --git a/Makefile b/Makefile index 0d1b50efca..00b369e50e 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ COMMIT := $(shell git rev-parse HEAD) LEDGER_ENABLED ?= true DOCKER := $(shell which docker) DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf +LIKE_HOME := '$(HOME)/.liked' IMAGE_TAG = likecoin/likecoin-chain:$(VERSION) RBUILDER_IMAGE_TAG = cf0d1a9f3731e30540bbfa36a36d13e4dcccf5eb BUILDDIR ?= $(CURDIR)/build @@ -19,73 +20,17 @@ COSMOS_PROTO_URL = https://raw.githubusercontent.com/regen-network/cosmos-pro GOGO_PROTO_TYPES = proto/gogoproto COSMOS_PROTO_TYPES = proto/cosmos_proto -export GO111MODULE = on - -# process build tags - -build_tags = netgo -ifeq ($(LEDGER_ENABLED),true) - ifeq ($(OS),Windows_NT) - GCCEXE = $(shell where gcc.exe 2> NUL) - ifeq ($(GCCEXE),) - $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false) - else - build_tags += ledger - endif - else - UNAME_S = $(shell uname -s) - ifeq ($(UNAME_S),OpenBSD) - $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)) - else - GCC = $(shell command -v gcc 2> /dev/null) - ifeq ($(GCC),) - $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false) - else - build_tags += ledger - endif - endif - endif -endif - -ifeq (cleveldb,$(findstring cleveldb,$(LIKE_BUILD_OPTIONS))) - build_tags += gcc -endif -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/cosmos/cosmos-sdk/version.Name=$(NAME) \ - -X github.com/cosmos/cosmos-sdk/version.AppName=$(APP) \ - -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ - -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ - -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" - -ifeq (cleveldb,$(findstring cleveldb,$(LIKE_BUILD_OPTIONS))) - ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb -endif -ifeq (,$(findstring nostrip,$(LIKE_BUILD_OPTIONS))) - ldflags += -w -s -endif -ldflags += $(LDFLAGS) -ldflags := $(strip $(ldflags)) - -BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' -# check for nostrip option -ifeq (,$(findstring nostrip,$(LIKE_BUILD_OPTIONS))) - BUILD_FLAGS += -trimpath -endif +############################################################################### +### Development ### +############################################################################### all: install test $(BUILDDIR)/: mkdir -p $(BUILDDIR)/ +$(BUILDDIR)/liked: build + vendor: go.sum @echo "--> Download go modules to work directory" go mod vendor @@ -94,17 +39,41 @@ download: go.sum @echo "--> Download go modules to local cache" go mod download -go-mod-cache: download - - go.sum: go.mod @echo "--> Ensure dependencies have not been modified" go mod verify +install: go.sum $(BUILDDIR)/ + go install -mod=readonly $(BUILD_FLAGS) ./... + +test: + go test -v ./... + +clean: + rm -rf $(BUILDDIR)/ artifacts/ + +init: $(BUILDDIR)/liked + $(BUILDDIR)/liked --home $(LIKE_HOME) init ${MONIKER} --chain-id "${CHAIN_ID}" + +lint: + golangci-lint run --disable-all -E errcheck --timeout 10m + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s + +format: + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofmt -w -s + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/cosmos/cosmos-sdk + +.PHONY: all vendor download install test clean lint format + +############################################################################### +### Build ### +############################################################################### + build-reproducible: go.sum $(DOCKER) rm latest-build || true $(DOCKER) run --volume=$(CURDIR):/sources:ro \ - --env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm64 windows/amd64' \ + --env TARGET_PLATFORMS='linux/amd64 darwin/amd64 darwin/arm64 linux/arm64 windows/amd64' \ --env APP=$(APP) \ --env VERSION=$(VERSION) \ --env COMMIT=$(COMMIT) \ @@ -124,32 +93,29 @@ docker-build: go.sum --tag $(IMAGE_TAG) \ . -build-docker: docker-build - docker-push: @echo "Pushing image $(IMAGE_TAG) to registry" $(DOCKER) push $(IMAGE_TAG) build: go.sum $(BUILDDIR)/ - go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./... + go build -mod=readonly \ + -ldflags "\ + -w -s \ + -X \"github.com/cosmos/cosmos-sdk/version.Name=$(NAME)\" \ + -X \"github.com/cosmos/cosmos-sdk/version.AppName=$(APP)\" \ + -X \"github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger\" \ + -X \"github.com/cosmos/cosmos-sdk/version.Version=${VERSION}\" \ + -X \"github.com/cosmos/cosmos-sdk/version.Commit=${COMMIT}\" \ + " \ + -tags "netgo,ledger" \ + -o $(BUILDDIR)/ ./... -install: go.sum $(BUILDDIR)/ - go install -mod=readonly $(BUILD_FLAGS) ./... +.PHONY: build-reproducible docker-login docker-build docker-push build -test: - go test -v ./... +############################################################################### +### Release ### +############################################################################### -clean: - rm -rf $(BUILDDIR)/ artifacts/ - -lint: - golangci-lint run --disable-all -E errcheck --timeout 10m - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s - -format: - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofmt -w -s - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/cosmos/cosmos-sdk release: @if [ ! -f ".release-env" ]; then \ @@ -166,10 +132,14 @@ release: -w /go/src/$(NAME) \ ghcr.io/troian/golang-cross:${GOLANG_CROSS_VERSION} \ release --rm-dist --skip-validate - -.PHONY: go-mod-cache gen-proto build-reproducible build-docker build install test clean lint format vendor release-dry-run release docker-build -proto-all: proto-format proto-lint +.PHONY: release + +############################################################################### +### Protobuf ### +############################################################################### + +proto-all: proto-format proto-lint gen-proto gen-proto: x/ ./gen_proto.sh @@ -191,4 +161,4 @@ proto-update-deps: @mkdir -p $(COSMOS_PROTO_TYPES) @curl -sSL $(COSMOS_PROTO_URL)/cosmos.proto > $(COSMOS_PROTO_TYPES)/cosmos.proto -.PHONY: proto-all proto-format proto-lint proto-check-breaking \ No newline at end of file +.PHONY: proto-all gen-proto proto-format proto-lint proto-check-breaking \ No newline at end of file