Makefile: fix tab expansion and add timeout config
This commit is contained in:
parent
2526827b6d
commit
1a36a2b1cb
271
Makefile
271
Makefile
@ -1,92 +1,241 @@
|
||||
PKG := github.com/lightningnetwork/lnd
|
||||
HAVE_DEP := $(shell command -v dep 2> /dev/null)
|
||||
ESCPKG := github.com\/lightningnetwork\/lnd
|
||||
|
||||
DEP_PKG := github.com/golang/dep/cmd/dep
|
||||
BTCD_PKG := github.com/roasbeef/btcd
|
||||
GLIDE_PKG := github.com/Masterminds/glide
|
||||
GOVERALLS_PKG := github.com/mattn/goveralls
|
||||
LINT_PKG := gopkg.in/alecthomas/gometalinter.v1
|
||||
|
||||
GO_BIN := ${GOPATH}/bin
|
||||
DEP_BIN := $(GO_BIN)/dep
|
||||
BTCD_BIN := $(GO_BIN)/btcd
|
||||
GLIDE_BIN := $(GO_BIN)/glide
|
||||
GOVERALLS_BIN := $(GO_BIN)/goveralls
|
||||
LINT_BIN := $(GO_BIN)/gometalinter.v1
|
||||
|
||||
HAVE_DEP := $(shell command -v $(DEP_BIN) 2> /dev/null)
|
||||
HAVE_BTCD := $(shell command -v $(BTCD_BIN) 2> /dev/null)
|
||||
HAVE_GLIDE := $(shell command -v $(GLIDE_BIN) 2> /dev/null)
|
||||
HAVE_GOVERALLS := $(shell command -v $(GOVERALLS_BIN) 2> /dev/null)
|
||||
HAVE_LINTER := $(shell command -v $(LINT_BIN) 2> /dev/null)
|
||||
|
||||
BTCD_DIR :=${GOPATH}/src/$(BTCD_PKG)
|
||||
|
||||
COMMIT := $(shell git rev-parse HEAD)
|
||||
LDFLAGS := -ldflags "-X main.Commit=$(COMMIT)"
|
||||
RM := rm
|
||||
|
||||
all: scratch
|
||||
GLIDE_COMMIT := 84607742b10f492430762d038e954236bbaf23f7
|
||||
BTCD_COMMIT := $(shell cat Gopkg.toml | \
|
||||
grep -A1 $(BTCD_PKG) | \
|
||||
tail -n1 | \
|
||||
awk '{ print $$3 }' | \
|
||||
tr -d '"')
|
||||
|
||||
GOBUILD := go build -v
|
||||
GOINSTALL := go install -v
|
||||
GOTEST := go test -v
|
||||
|
||||
# ==============================================================================
|
||||
# INSTALLATION
|
||||
# ==============================================================================
|
||||
GOLIST := go list $(PKG)/... | grep -v '/vendor/'
|
||||
GOLISTCOVER := $(shell go list -f '{{.ImportPath}}' ./... | sed -e 's/^$(ESCPKG)/./')
|
||||
GOLISTLINT := $(shell go list -f '{{.Dir}}' ./... | grep -v 'lnrpc')
|
||||
|
||||
deps:
|
||||
ifndef HAVE_DEP
|
||||
@echo "Fetching dep."
|
||||
go get -u github.com/golang/dep/cmd/dep
|
||||
endif
|
||||
@echo "Building dependencies."
|
||||
COVER = for dir in $(GOLISTCOVER); do \
|
||||
$(GOTEST) $(TEST_FLAGS) \
|
||||
-covermode=count \
|
||||
-coverprofile=$$dir/profile.tmp $$dir; \
|
||||
\
|
||||
if [ -f $$dir/profile.tmp ]; then \
|
||||
cat $$dir/profile.tmp | \
|
||||
tail -n +2 >> profile.cov; \
|
||||
$(RM) $$dir/profile.tmp; \
|
||||
fi \
|
||||
done
|
||||
|
||||
LINT = $(LINT_BIN) \
|
||||
--disable-all \
|
||||
--enable=gofmt \
|
||||
--enable=vet \
|
||||
--enable=golint \
|
||||
--line-length=72 \
|
||||
--deadline=4m $(GOLISTLINT) 2>&1 | \
|
||||
grep -v 'ALL_CAPS\|OP_' 2>&1 | \
|
||||
tee /dev/stderr
|
||||
|
||||
CGO_STATUS_QUO := ${CGO_ENABLED}
|
||||
|
||||
RM := rm -f
|
||||
CP := cp
|
||||
MAKE := make
|
||||
XARGS := xargs -L 1
|
||||
|
||||
GREEN := "\\033[0;32m"
|
||||
NC := "\\033[0m"
|
||||
define print
|
||||
echo $(GREEN)$1$(NC)
|
||||
endef
|
||||
|
||||
include make/testing_flags.mk
|
||||
|
||||
default: scratch
|
||||
|
||||
all: scratch check install
|
||||
|
||||
# ============
|
||||
# DEPENDENCIES
|
||||
# ============
|
||||
|
||||
$(DEP_BIN):
|
||||
@$(call print, "Fetching dep.")
|
||||
go get -u $(DEP_PKG)
|
||||
|
||||
$(GLIDE_BIN):
|
||||
@$(call print, "Fetching glide.")
|
||||
go get -d $(GLIDE_PKG)
|
||||
cd ${GOPATH}/src/$(GLIDE_PKG) && git checkout $(GLIDE_COMMIT)
|
||||
$(GOINSTALL) $(GLIDE_PKG)
|
||||
|
||||
$(GOVERALLS_BIN):
|
||||
@$(call print, "Fetching goveralls.")
|
||||
go get -u $(GOVERALLS_PKG)
|
||||
|
||||
$(LINT_BIN):
|
||||
@$(call print, "Fetching gometalinter.v1")
|
||||
go get -u $(LINT_PKG)
|
||||
$(GOINSTALL) $(LINT_PKG)
|
||||
|
||||
dep: $(DEP_BIN)
|
||||
@$(call print, "Compiling dependencies.")
|
||||
dep ensure -v
|
||||
|
||||
$(BTCD_DIR):
|
||||
@$(call print, "Fetching btcd.")
|
||||
go get -d github.com/roasbeef/btcd
|
||||
|
||||
btcd: $(GLIDE_BIN) $(BTCD_DIR)
|
||||
@$(call print, "Compiling btcd dependencies.")
|
||||
cd $(BTCD_DIR) && git checkout $(BTCD_COMMIT) && glide install
|
||||
@$(call print, "Installing btcd and btcctl.")
|
||||
$(GOINSTALL) $(BTCD_PKG)
|
||||
$(GOINSTALL) $(BTCD_PKG)/cmd/btcctl
|
||||
|
||||
# ============
|
||||
# INSTALLATION
|
||||
# ============
|
||||
|
||||
build:
|
||||
@echo "Building lnd and lncli."
|
||||
go build -v -o lnd $(LDFLAGS) $(PKG)
|
||||
go build -v -o lncli $(LDFLAGS) $(PKG)/cmd/lncli
|
||||
@$(call print, "Building lnd and lncli.")
|
||||
$(GOBUILD) -o lnd $(LDFLAGS) $(PKG)
|
||||
$(GOBUILD) -o lncli $(LDFLAGS) $(PKG)/cmd/lncli
|
||||
|
||||
install:
|
||||
@echo "Installing lnd and lncli."
|
||||
go install -v $(LDFLAGS) $(PKG)
|
||||
go install -v $(LDFLAGS) $(PKG)/cmd/lncli
|
||||
@$(call print, "Installing lnd and lncli.")
|
||||
$(CP) ./lnd $(LND_BIN)
|
||||
$(CP) ./lncli $(LNCLI_BIN)
|
||||
|
||||
scratch: deps build
|
||||
scratch: dep build
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# =======
|
||||
# TESTING
|
||||
# ==============================================================================
|
||||
|
||||
# Define the integration test.run filter if the icase argument was provided.
|
||||
ifneq ($(icase),)
|
||||
ITESTCASE := -test.run=TestLightningNetworkDaemon/$(icase)
|
||||
endif
|
||||
|
||||
# UNIT_TARGTED is defined iff a specific package and/or unit test case is being
|
||||
# targeted.
|
||||
UNIT_TARGETED =
|
||||
|
||||
# If specific package is being unit tested, construct the full name of the
|
||||
# subpackage.
|
||||
ifneq ($(pkg),)
|
||||
UNITPKG := $(PKG)/$(pkg)
|
||||
UNIT_TARGETED = yes
|
||||
endif
|
||||
|
||||
# If a specific unit test case is being target, construct test.run filter.
|
||||
ifneq ($(case),)
|
||||
UNITCASE := -test.run=$(case)
|
||||
UNIT_TARGETED = yes
|
||||
endif
|
||||
|
||||
# If no unit targeting was input, default to running all tests. Otherwise,
|
||||
# construct the command to run the specific package/test case.
|
||||
ifndef UNIT_TARGETED
|
||||
UNIT := go list $(PKG)/... | grep -v '/vendor/' | xargs go test
|
||||
else
|
||||
UNIT := go test -test.v $(UNITPKG) $(UNITCASE)
|
||||
endif
|
||||
# =======
|
||||
|
||||
check: unit itest
|
||||
|
||||
itest: install
|
||||
@echo "Running integration tests."
|
||||
go test -v -tags rpctest -logoutput $(ITESTCASE)
|
||||
itest: btcd build
|
||||
@$(call print, "Running integration tests.")
|
||||
$(ITEST)
|
||||
|
||||
unit:
|
||||
@echo "Running unit tests."
|
||||
unit: btcd
|
||||
@$(call print, "Running unit tests.")
|
||||
$(UNIT)
|
||||
|
||||
unit-cover:
|
||||
@$(call print, "Running unit coverage tests.")
|
||||
echo "mode: count" > profile.cov
|
||||
$(COVER)
|
||||
|
||||
# ==============================================================================
|
||||
unit-race:
|
||||
@$(call print, "Running unit race tests.")
|
||||
export CGO_ENABLED=1; env GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE)
|
||||
export CGO_ENABLED=$(CGO_STATUS_QUO)
|
||||
|
||||
# =============
|
||||
# FLAKE HUNTING
|
||||
# =============
|
||||
|
||||
flakehunter: build
|
||||
@$(call print, "Flake hunting integration tests.")
|
||||
$(ITEST)
|
||||
while [ $$? -eq 0 ]; do /bin/sh -c "$(ITEST)"; done
|
||||
|
||||
flake-unit:
|
||||
@$(call print, "Flake hunting unit tests.")
|
||||
$(UNIT) -count=1
|
||||
while [ $$? -eq 0 ]; do /bin/sh -c "$(UNIT) -count=1"; done
|
||||
|
||||
# ======
|
||||
# TRAVIS
|
||||
# ======
|
||||
|
||||
ifeq ($(RACE), false)
|
||||
travis: lint scratch itest unit-cover $(GOVERALLS_BIN)
|
||||
@$(call print, "Sending coverage report.")
|
||||
$(GOVERALLS_BIN) -coverprofile=profile.cov -service=travis-ci
|
||||
endif
|
||||
|
||||
ifeq ($(RACE), true)
|
||||
travis: lint dep btcd unit-race
|
||||
endif
|
||||
|
||||
|
||||
# =========
|
||||
# UTILITIES
|
||||
# ==============================================================================
|
||||
# =========
|
||||
|
||||
fmt:
|
||||
go list $(PKG)/... | grep -v '/vendor/' | xargs go fmt -x
|
||||
@$(call print, "Formatting source.")
|
||||
$(GOLIST) | $(XARGS) go fmt -x
|
||||
|
||||
lint: $(LINT_BIN)
|
||||
@$(call print, "Linting source.")
|
||||
$(LINT_BIN) --install 1> /dev/null
|
||||
test -z "$($(LINT))"
|
||||
|
||||
list:
|
||||
@$(call print, "Listing commands.")
|
||||
@$(MAKE) -qp | \
|
||||
awk -F':' '/^[a-zA-Z0-9][^$$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)print A[i]}' | \
|
||||
grep -v Makefile | \
|
||||
sort
|
||||
|
||||
rpc:
|
||||
@$(call print, "Compiling protos.")
|
||||
cd ./lnrpc; ./gen_protos.sh
|
||||
|
||||
clean:
|
||||
@$(call print, "Cleaning source.$(NC)")
|
||||
$(RM) ./lnd ./lncli
|
||||
$(RM) -rf vendor
|
||||
$(RM) -r ./vendor
|
||||
|
||||
|
||||
.PHONY: all deps build install scratch check itest unit fmt clean
|
||||
.PHONY: all \
|
||||
btcd\
|
||||
default \
|
||||
dep \
|
||||
build \
|
||||
install \
|
||||
scratch \
|
||||
check \
|
||||
itest \
|
||||
unit \
|
||||
unit-cover \
|
||||
unit-race \
|
||||
flakehunter \
|
||||
flake-unit \
|
||||
travis \
|
||||
fmt \
|
||||
lint \
|
||||
list \
|
||||
rpc \
|
||||
clean
|
||||
|
Loading…
Reference in New Issue
Block a user