lnd/Makefile
Conner Fromknecht d7af7934b8
travis: staged travis builds
This PR introduces staging to our travis pipeline. Currently all
instances perform:

 - compilation of lnd
 - linting
 - compilation and installation of btcd binaries
 - installation of bitcoind binaries

In total this adds about 3 minutes to each of our 5 instances, resulting in
roughly 12 minutes of redundant execution time. Additionally, if if a build
fails to compile or lint we detect this 5 separate times, consuming precious
instances from other builds.

We alleviate this by adding an initial Build phase, which runs a single
instance performing the actions above. This has the benefit of quickly sanity
checking the pr before moving on to the more expensive unit or integration test
suites, and failing faster for common mistakes. It also warms up the build
caches for the Test stage in one fell swoop.

For instance, if 5 people push changes at the same time, they can all get
immediate feedback regarding compilation or linting issues, and potentially
save hours waiting for other people's test to finish or fail before finding out
they had a spelling error. This doesn't alleviate all possible issues, e.g. the
5 instances may already be consumed by test suites, but it does make a sizable
step towards minimizing time-to-failure in common scenarios.
2019-12-05 14:36:01 -08:00

232 lines
5.4 KiB
Makefile

PKG := github.com/lightningnetwork/lnd
ESCPKG := github.com\/lightningnetwork\/lnd
MOBILE_PKG := $(PKG)/mobile
BTCD_PKG := github.com/btcsuite/btcd
GOVERALLS_PKG := github.com/mattn/goveralls
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
GOACC_PKG := github.com/ory/go-acc
GO_BIN := ${GOPATH}/bin
BTCD_BIN := $(GO_BIN)/btcd
GOMOBILE_BIN := GO111MODULE=off $(GO_BIN)/gomobile
GOVERALLS_BIN := $(GO_BIN)/goveralls
LINT_BIN := $(GO_BIN)/golangci-lint
GOACC_BIN := $(GO_BIN)/go-acc
BTCD_DIR :=${GOPATH}/src/$(BTCD_PKG)
MOBILE_BUILD_DIR :=${GOPATH}/src/$(MOBILE_PKG)/build
IOS_BUILD_DIR := $(MOBILE_BUILD_DIR)/ios
IOS_BUILD := $(IOS_BUILD_DIR)/Lndmobile.framework
ANDROID_BUILD_DIR := $(MOBILE_BUILD_DIR)/android
ANDROID_BUILD := $(ANDROID_BUILD_DIR)/Lndmobile.aar
COMMIT := $(shell git describe --abbrev=40 --dirty)
LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT)"
BTCD_COMMIT := $(shell cat go.mod | \
grep $(BTCD_PKG) | \
tail -n1 | \
awk -F " " '{ print $$2 }' | \
awk -F "/" '{ print $$1 }')
LINT_COMMIT := v1.18.0
GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5
DEPGET := cd /tmp && GO111MODULE=on go get -v
GOBUILD := GO111MODULE=on go build -v
GOINSTALL := GO111MODULE=on go install -v
GOTEST := GO111MODULE=on go test
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
GOLISTCOVER := $(shell go list -deps -f '{{.ImportPath}}' ./... | grep '$(PKG)' | sed -e 's/^$(ESCPKG)/./')
RM := rm -f
CP := cp
MAKE := make
XARGS := xargs -L 1
include make/testing_flags.mk
DEV_TAGS := $(if ${tags},$(DEV_TAGS) ${tags},$(DEV_TAGS))
LINT = $(LINT_BIN) run -v
GREEN := "\\033[0;32m"
NC := "\\033[0m"
define print
echo $(GREEN)$1$(NC)
endef
default: scratch
all: scratch check install
# ============
# DEPENDENCIES
# ============
$(GOVERALLS_BIN):
@$(call print, "Fetching goveralls.")
go get -u $(GOVERALLS_PKG)
$(LINT_BIN):
@$(call print, "Fetching linter")
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
$(GOACC_BIN):
@$(call print, "Fetching go-acc")
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
btcd:
@$(call print, "Installing btcd.")
$(DEPGET) $(BTCD_PKG)@$(BTCD_COMMIT)
# ============
# INSTALLATION
# ============
build:
@$(call print, "Building debug lnd and lncli.")
$(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(LDFLAGS) $(PKG)/cmd/lnd
$(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(LDFLAGS) $(PKG)/cmd/lncli
build-itest:
@$(call print, "Building itest lnd and lncli.")
$(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(LDFLAGS) $(PKG)/cmd/lnd
$(GOBUILD) -tags="$(ITEST_TAGS)" -o lncli-itest $(LDFLAGS) $(PKG)/cmd/lncli
install:
@$(call print, "Installing lnd and lncli.")
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lnd
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lncli
scratch: build
# =======
# TESTING
# =======
check: unit itest
itest-only:
@$(call print, "Running integration tests with ${backend} backend.")
$(ITEST)
itest: btcd build-itest itest-only
unit: btcd
@$(call print, "Running unit tests.")
$(UNIT)
unit-cover: $(GOACC_BIN)
@$(call print, "Running unit coverage tests.")
$(GOACC_BIN) $(COVER_PKG) -- -test.tags="$(DEV_TAGS) $(LOG_TAGS)"
unit-race:
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE)
goveralls: $(GOVERALLS_BIN)
@$(call print, "Sending coverage report.")
$(GOVERALLS_BIN) -coverprofile=coverage.txt -service=travis-ci
travis-race: btcd unit-race
travis-cover: btcd unit-cover goveralls
# =============
# FLAKE HUNTING
# =============
flakehunter: build-itest
@$(call print, "Flake hunting ${backend} integration tests.")
while [ $$? -eq 0 ]; do $(ITEST); done
flake-unit:
@$(call print, "Flake hunting unit tests.")
while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done
# =========
# UTILITIES
# =========
fmt:
@$(call print, "Formatting source.")
gofmt -l -w -s $(GOFILES_NOVENDOR)
lint: $(LINT_BIN)
@$(call print, "Linting source.")
$(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
mobile-rpc:
@$(call print, "Creating mobile RPC from protos.")
cd ./mobile; ./gen_bindings.sh
vendor:
@$(call print, "Re-creating vendor directory.")
rm -r vendor/; GO111MODULE=on go mod vendor
ios: vendor mobile-rpc
@$(call print, "Building iOS framework ($(IOS_BUILD)).")
mkdir -p $(IOS_BUILD_DIR)
$(GOMOBILE_BIN) bind -target=ios -tags="ios $(DEV_TAGS) autopilotrpc experimental" $(LDFLAGS) -v -o $(IOS_BUILD) $(MOBILE_PKG)
android: vendor mobile-rpc
@$(call print, "Building Android library ($(ANDROID_BUILD)).")
mkdir -p $(ANDROID_BUILD_DIR)
$(GOMOBILE_BIN) bind -target=android -tags="android $(DEV_TAGS) autopilotrpc experimental" $(LDFLAGS) -v -o $(ANDROID_BUILD) $(MOBILE_PKG)
mobile: ios android
clean:
@$(call print, "Cleaning source.$(NC)")
$(RM) ./lnd-debug ./lncli-debug
$(RM) ./lnd-itest ./lncli-itest
$(RM) -r ./vendor .vendor-new
.PHONY: all \
btcd \
default \
build \
install \
scratch \
check \
itest-only \
itest \
unit \
unit-cover \
unit-race \
goveralls \
travis-race \
travis-cover \
travis-itest \
flakehunter \
flake-unit \
fmt \
lint \
list \
rpc \
mobile-rpc \
vendor \
ios \
android \
mobile \
clean