2018-03-28 14:22:52 +03:00
|
|
|
PKG := github.com/lightningnetwork/lnd
|
2018-03-29 08:16:18 +03:00
|
|
|
ESCPKG := github.com\/lightningnetwork\/lnd
|
|
|
|
|
|
|
|
DEP_PKG := github.com/golang/dep/cmd/dep
|
2018-06-05 04:35:45 +03:00
|
|
|
BTCD_PKG := github.com/btcsuite/btcd
|
2018-03-29 08:16:18 +03:00
|
|
|
GLIDE_PKG := github.com/Masterminds/glide
|
|
|
|
GOVERALLS_PKG := github.com/mattn/goveralls
|
2018-08-03 23:28:16 +03:00
|
|
|
LINT_PKG := gopkg.in/alecthomas/gometalinter.v2
|
2018-03-29 08:16:18 +03:00
|
|
|
|
|
|
|
GO_BIN := ${GOPATH}/bin
|
|
|
|
DEP_BIN := $(GO_BIN)/dep
|
|
|
|
BTCD_BIN := $(GO_BIN)/btcd
|
|
|
|
GLIDE_BIN := $(GO_BIN)/glide
|
|
|
|
GOVERALLS_BIN := $(GO_BIN)/goveralls
|
2018-08-03 23:28:16 +03:00
|
|
|
LINT_BIN := $(GO_BIN)/gometalinter.v2
|
2018-03-29 08:16:18 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2018-03-28 14:22:52 +03:00
|
|
|
COMMIT := $(shell git rev-parse HEAD)
|
|
|
|
LDFLAGS := -ldflags "-X main.Commit=$(COMMIT)"
|
2018-01-29 19:11:03 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
2018-08-10 09:17:07 +03:00
|
|
|
RM := rm -f
|
|
|
|
CP := cp
|
|
|
|
MAKE := make
|
|
|
|
XARGS := xargs -L 1
|
|
|
|
|
|
|
|
include make/testing_flags.mk
|
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
COVER = for dir in $(GOLISTCOVER); do \
|
2018-08-10 09:17:07 +03:00
|
|
|
$(GOTEST) -tags="$(TEST_TAGS)" \
|
2018-03-29 08:16:18 +03:00
|
|
|
-covermode=count \
|
|
|
|
-coverprofile=$$dir/profile.tmp $$dir; \
|
|
|
|
\
|
2018-08-10 07:44:33 +03:00
|
|
|
if [ $$? != 0 ] ;\
|
|
|
|
then \
|
2018-08-10 09:17:07 +03:00
|
|
|
exit 1; \
|
2018-08-10 07:44:33 +03:00
|
|
|
fi ;\
|
|
|
|
\
|
2018-03-29 08:16:18 +03:00
|
|
|
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}
|
|
|
|
|
|
|
|
GREEN := "\\033[0;32m"
|
|
|
|
NC := "\\033[0m"
|
|
|
|
define print
|
|
|
|
echo $(GREEN)$1$(NC)
|
|
|
|
endef
|
|
|
|
|
|
|
|
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)
|
2018-08-21 02:35:10 +03:00
|
|
|
cd ${GOPATH}/src/$(GLIDE_PKG) && ( git checkout $(GLIDE_COMMIT) || ( git fetch --all && git checkout $(GLIDE_COMMIT) ) )
|
2018-03-29 08:16:18 +03:00
|
|
|
$(GOINSTALL) $(GLIDE_PKG)
|
|
|
|
|
|
|
|
$(GOVERALLS_BIN):
|
|
|
|
@$(call print, "Fetching goveralls.")
|
|
|
|
go get -u $(GOVERALLS_PKG)
|
|
|
|
|
|
|
|
$(LINT_BIN):
|
2018-08-03 23:28:16 +03:00
|
|
|
@$(call print, "Fetching gometalinter.v2")
|
2018-03-29 08:16:18 +03:00
|
|
|
go get -u $(LINT_PKG)
|
|
|
|
$(GOINSTALL) $(LINT_PKG)
|
|
|
|
|
|
|
|
dep: $(DEP_BIN)
|
|
|
|
@$(call print, "Compiling dependencies.")
|
|
|
|
dep ensure -v
|
2018-01-29 19:11:03 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
$(BTCD_DIR):
|
|
|
|
@$(call print, "Fetching btcd.")
|
2018-06-05 04:35:45 +03:00
|
|
|
go get -d github.com/btcsuite/btcd
|
2018-01-29 19:11:03 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
btcd: $(GLIDE_BIN) $(BTCD_DIR)
|
|
|
|
@$(call print, "Compiling btcd dependencies.")
|
2018-08-21 02:35:10 +03:00
|
|
|
cd $(BTCD_DIR) && ( git checkout $(BTCD_COMMIT) || ( git fetch --all && git checkout $(BTCD_COMMIT) ) ) && glide install
|
2018-03-29 08:16:18 +03:00
|
|
|
@$(call print, "Installing btcd and btcctl.")
|
|
|
|
$(GOINSTALL) $(BTCD_PKG)
|
|
|
|
$(GOINSTALL) $(BTCD_PKG)/cmd/btcctl
|
2018-01-29 19:11:03 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
# ============
|
|
|
|
# INSTALLATION
|
|
|
|
# ============
|
2018-01-29 19:11:03 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
build:
|
2018-04-29 14:49:14 +03:00
|
|
|
@$(call print, "Building debug lnd and lncli.")
|
2018-09-01 05:32:22 +03:00
|
|
|
$(GOBUILD) -tags="$(TEST_TAGS) ${tags}" -o lnd-debug $(LDFLAGS) $(PKG)
|
|
|
|
$(GOBUILD) -tags="$(TEST_TAGS) ${tags}" -o lncli-debug $(LDFLAGS) $(PKG)/cmd/lncli
|
2018-03-28 14:22:52 +03:00
|
|
|
|
|
|
|
install:
|
2018-03-29 08:16:18 +03:00
|
|
|
@$(call print, "Installing lnd and lncli.")
|
2018-09-01 05:32:22 +03:00
|
|
|
go install -v -tags="${tags}" $(LDFLAGS) $(PKG)
|
|
|
|
go install -v -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lncli
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
scratch: dep build
|
2018-03-28 14:22:52 +03:00
|
|
|
|
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
# =======
|
2018-03-28 14:22:52 +03:00
|
|
|
# TESTING
|
2018-03-29 08:16:18 +03:00
|
|
|
# =======
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
check: unit itest
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
itest: btcd build
|
|
|
|
@$(call print, "Running integration tests.")
|
|
|
|
$(ITEST)
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
unit: btcd
|
|
|
|
@$(call print, "Running unit tests.")
|
|
|
|
$(UNIT)
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
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.")
|
2018-05-09 10:53:35 +03:00
|
|
|
while [ $$? -eq 0 ]; do $(ITEST); done
|
2018-03-29 08:16:18 +03:00
|
|
|
|
|
|
|
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)
|
2018-08-03 23:28:16 +03:00
|
|
|
travis: dep lint build itest unit-cover $(GOVERALLS_BIN)
|
2018-03-29 08:16:18 +03:00
|
|
|
@$(call print, "Sending coverage report.")
|
|
|
|
$(GOVERALLS_BIN) -coverprofile=profile.cov -service=travis-ci
|
2018-03-28 14:22:52 +03:00
|
|
|
endif
|
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
ifeq ($(RACE), true)
|
2018-08-03 23:28:16 +03:00
|
|
|
travis: dep lint btcd unit-race
|
2018-03-28 14:22:52 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
# =========
|
|
|
|
# UTILITIES
|
|
|
|
# =========
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
fmt:
|
|
|
|
@$(call print, "Formatting source.")
|
|
|
|
$(GOLIST) | $(XARGS) go fmt -x
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
lint: $(LINT_BIN)
|
|
|
|
@$(call print, "Linting source.")
|
|
|
|
$(LINT_BIN) --install 1> /dev/null
|
2018-07-31 11:29:33 +03:00
|
|
|
test -z "$$($(LINT))"
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
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
|
2018-01-29 19:11:03 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
rpc:
|
|
|
|
@$(call print, "Compiling protos.")
|
|
|
|
cd ./lnrpc; ./gen_protos.sh
|
2018-03-28 14:22:52 +03:00
|
|
|
|
|
|
|
clean:
|
2018-03-29 08:16:18 +03:00
|
|
|
@$(call print, "Cleaning source.$(NC)")
|
2018-03-28 14:22:52 +03:00
|
|
|
$(RM) ./lnd ./lncli
|
2018-03-29 08:16:18 +03:00
|
|
|
$(RM) -r ./vendor
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: all \
|
|
|
|
btcd\
|
|
|
|
default \
|
|
|
|
dep \
|
|
|
|
build \
|
|
|
|
install \
|
|
|
|
scratch \
|
|
|
|
check \
|
|
|
|
itest \
|
|
|
|
unit \
|
|
|
|
unit-cover \
|
|
|
|
unit-race \
|
|
|
|
flakehunter \
|
|
|
|
flake-unit \
|
|
|
|
travis \
|
|
|
|
fmt \
|
|
|
|
lint \
|
|
|
|
list \
|
|
|
|
rpc \
|
|
|
|
clean
|