Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
VERSION := $(shell echo $(shell git describe --tags))
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
STATIC_PIE ?= false
BINDIR ?= $(GOPATH)/bin
BUILDDIR ?= $(CURDIR)/build
APP_DIR = ./app
Expand All @@ -15,6 +16,10 @@ PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)

export GO111MODULE = on

# Resolve the target OS used by Go.
# This works both for native builds and explicit cross-compilation.
BUILD_GOOS := $(shell go env GOOS)

# process build tags

build_tags = netgo
Expand Down Expand Up @@ -63,10 +68,32 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=fetch \
ifeq ($(WITH_CLEVELDB),yes)
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif

# PIE is enabled for all builds.
#
# PIE and static linking are *independent* properties:
# -buildmode=pie -> position-independent executable (platform *independent*)
# -static-pie -> *Linux* only *static* linking of the PIE executable
buildmode_flags += -buildmode=pie

# Static PIE is supported here only for Linux.
#
# STATIC_PIE=true requests a statically linked PIE executable.
# The Linux-specific external linker flags must not be passed to
# macOS or Windows builds.
ifeq ($(STATIC_PIE),true)
ifeq ($(BUILD_GOOS),linux)
extldflags += -Wl,-z,muldefs -static-pie -z noexecstack
ldflags += -linkmode=external -extldflags "$(extldflags)"
else
$(warning STATIC_PIE=true requested for $(BUILD_GOOS); Linux static-PIE linker flags will not be applied)
endif
endif

ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags $(build_tags_comma_sep) -ldflags '$(ldflags)' -trimpath
BUILD_FLAGS := -tags "$(build_tags_comma_sep)" -ldflags '$(ldflags)' -trimpath $(buildmode_flags)

# The below include contains the tools target.
#include contrib/devtools/Makefile
Expand All @@ -80,8 +107,14 @@ else
go build -mod=readonly $(BUILD_FLAGS) -o build/fetchd ./cmd/fetchd
endif

# Build for Linux while preserving the target architecture supplied by
# the environment (or Go's native GOARCH default).
build-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
GOOS=linux $(MAKE) build

# Build a Linux static PIE while preserving the target architecture.
build-linux-static: go.sum
GOOS=linux STATIC_PIE=true $(MAKE) build

build-contract-tests-hooks:
ifeq ($(OS),Windows_NT)
Expand Down Expand Up @@ -123,21 +156,21 @@ test: test-unit
test-all: test-unit test-ledger-mock test-race test-cover

TEST_PACKAGES=./...
TEST_TARGETS := test-unit test-unit-amino test-unit-proto test-ledger-mock test-race test-ledger test-race
TEST_TARGETS := test-unit test-unit-amino test-ledger-mock test-race test-ledger test-race

# Test runs-specific rules. To add a new test target, just add
# a new rule, customise ARGS or TEST_PACKAGES ad libitum, and
# append the new rule to the TEST_TARGETS list.
# Test runs-specific rules. To add a new test target, customise ARGS or
# TEST_PACKAGES ad libitum, and append the new rule to the TEST_TARGETS list.
UNIT_TEST_ARGS = cgo ledger test_ledger_mock norace
AMINO_TEST_ARGS = ledger test_ledger_mock test_amino norace
LEDGER_TEST_ARGS = cgo ledger norace
LEDGER_MOCK_ARGS = ledger test_ledger_mock norace
TEST_RACE_ARGS = cgo ledger test_ledger_mock

ifeq ($(EXPERIMENTAL),true)
UNIT_TEST_ARGS += experimental
AMINO_TEST_ARGS += experimental
LEDGER_TEST_ARGS += experimental
LEDGER_MOCK_ARGS += experimental
LEDGER_TEST_ARGS += experimental
LEDGER_MOCK_ARGS += experimental
TEST_RACE_ARGS += experimental
endif

Expand All @@ -152,6 +185,7 @@ $(TEST_TARGETS): run-tests

SUB_MODULES = $(shell find . -type f -name 'go.mod' -print0 | xargs -0 -n1 dirname | sort)
CURRENT_DIR = $(shell pwd)

run-tests:
ifneq (,$(shell which tparse 2>/dev/null))
@echo "Unit tests"; \
Expand Down Expand Up @@ -190,11 +224,11 @@ localnet-start: build-linux localnet-stop
@if ! [ -f build/node0/fetchd/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/fetchd:Z tendermint/fetchdnode testnet --v 4 -o . --starting-ip-address 192.168.10.2 ; fi
docker-compose up -d

# Stop testnet
# Stop local testnet
localnet-stop:
docker-compose down

.PHONY: all build-linux install install-debug \
.PHONY: all build-linux build-linux-static install install-debug \
go-mod-cache draw-deps clean build \
test test-all test-cover test-unit test-race

Expand All @@ -210,7 +244,7 @@ containerProtoFmt=${PROJECT_NAME}-proto-fmt-$(containerProtoVer)
containerProtoGenSwagger=${PROJECT_NAME}-proto-gen-swagger-$(containerProtoVer)

proto-all: proto-gen proto-lint proto-check-breaking proto-format
.PHONY: proto-all proto-gen proto-gen-docker proto-lint proto-check-breaking proto-format
.PHONY: proto-all proto-gen proto-lint proto-check-breaking proto-format

proto-gen:
@echo "Generating Protobuf files"
Expand All @@ -234,7 +268,7 @@ proto-check-breaking:
@$(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=master

proto-check-breaking-direct:
@buf breaking --against '.git#branch=master'
@$(DOCKER_BUF) breaking --against '.git#branch=master'

GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos
REGEN_COSMOS_PROTO_URL = https://raw.githubusercontent.com/regen-network/cosmos-proto/master
Expand All @@ -253,4 +287,6 @@ proto-update-deps:

@mkdir -p $(COSMOS_PROTO_TYPES)/base/query/v1beta1/
@curl -sSL $(COSMOS_PROTO_URL)/base/query/v1beta1/pagination.proto > $(COSMOS_PROTO_TYPES)/base/query/v1beta1/pagination.proto

@mkdir -p $(COSMOS_PROTO_TYPES)/base/v1beta1/
@curl -sSL $(COSMOS_PROTO_URL)/base/v1beta1/coin.proto > $(COSMOS_PROTO_TYPES)/base/v1beta1/coin.proto
Loading