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
|
2019-01-24 16:51:06 +03:00
|
|
|
MOBILE_PKG := $(PKG)/mobile
|
2018-03-29 08:16:18 +03:00
|
|
|
|
2018-06-05 04:35:45 +03:00
|
|
|
BTCD_PKG := github.com/btcsuite/btcd
|
2018-03-29 08:16:18 +03:00
|
|
|
GOVERALLS_PKG := github.com/mattn/goveralls
|
2019-09-19 00:05:11 +03:00
|
|
|
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
|
2019-01-18 14:17:58 +03:00
|
|
|
GOACC_PKG := github.com/ory/go-acc
|
2018-03-29 08:16:18 +03:00
|
|
|
|
|
|
|
GO_BIN := ${GOPATH}/bin
|
|
|
|
BTCD_BIN := $(GO_BIN)/btcd
|
2019-01-24 16:51:06 +03:00
|
|
|
GOMOBILE_BIN := GO111MODULE=off $(GO_BIN)/gomobile
|
2018-03-29 08:16:18 +03:00
|
|
|
GOVERALLS_BIN := $(GO_BIN)/goveralls
|
2019-07-22 12:05:57 +03:00
|
|
|
LINT_BIN := $(GO_BIN)/golangci-lint
|
2019-01-18 14:17:58 +03:00
|
|
|
GOACC_BIN := $(GO_BIN)/go-acc
|
2018-03-29 08:16:18 +03:00
|
|
|
|
|
|
|
BTCD_DIR :=${GOPATH}/src/$(BTCD_PKG)
|
2019-01-24 16:51:06 +03:00
|
|
|
MOBILE_BUILD_DIR :=${GOPATH}/src/$(MOBILE_PKG)/build
|
|
|
|
IOS_BUILD_DIR := $(MOBILE_BUILD_DIR)/ios
|
|
|
|
IOS_BUILD := $(IOS_BUILD_DIR)/Lndmobile.framework
|
2019-01-24 16:51:06 +03:00
|
|
|
ANDROID_BUILD_DIR := $(MOBILE_BUILD_DIR)/android
|
|
|
|
ANDROID_BUILD := $(ANDROID_BUILD_DIR)/Lndmobile.aar
|
2018-03-29 08:16:18 +03:00
|
|
|
|
2018-10-08 09:00:07 +03:00
|
|
|
COMMIT := $(shell git describe --abbrev=40 --dirty)
|
2020-04-10 03:04:25 +03:00
|
|
|
COMMIT_HASH := $(shell git rev-parse HEAD)
|
2018-01-29 19:11:03 +03:00
|
|
|
|
2018-12-04 15:50:46 +03:00
|
|
|
BTCD_COMMIT := $(shell cat go.mod | \
|
2018-11-29 04:17:38 +03:00
|
|
|
grep $(BTCD_PKG) | \
|
2018-03-29 08:16:18 +03:00
|
|
|
tail -n1 | \
|
2018-11-29 04:17:38 +03:00
|
|
|
awk -F " " '{ print $$2 }' | \
|
|
|
|
awk -F "/" '{ print $$1 }')
|
2018-03-29 08:16:18 +03:00
|
|
|
|
2019-09-19 00:05:11 +03:00
|
|
|
LINT_COMMIT := v1.18.0
|
2019-01-18 14:17:58 +03:00
|
|
|
GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5
|
|
|
|
|
2019-09-19 00:03:18 +03:00
|
|
|
DEPGET := cd /tmp && GO111MODULE=on go get -v
|
2019-09-20 00:34:38 +03:00
|
|
|
GOBUILD := GO111MODULE=on go build -v
|
|
|
|
GOINSTALL := GO111MODULE=on go install -v
|
2019-11-22 16:12:09 +03:00
|
|
|
GOTEST := GO111MODULE=on go test
|
2018-03-29 08:16:18 +03:00
|
|
|
|
2020-04-10 03:05:24 +03:00
|
|
|
GOVERSION := $(shell go version | awk '{print $$3}')
|
2018-10-25 05:06:58 +03:00
|
|
|
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
|
2019-08-08 07:33:06 +03:00
|
|
|
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
|
|
|
|
GOLISTCOVER := $(shell go list -deps -f '{{.ImportPath}}' ./... | grep '$(PKG)' | sed -e 's/^$(ESCPKG)/./')
|
2018-03-29 08:16:18 +03:00
|
|
|
|
2018-08-10 09:17:07 +03:00
|
|
|
RM := rm -f
|
|
|
|
CP := cp
|
|
|
|
MAKE := make
|
2018-10-26 03:10:49 +03:00
|
|
|
XARGS := xargs -L 1
|
2018-08-10 09:17:07 +03:00
|
|
|
|
|
|
|
include make/testing_flags.mk
|
2020-04-21 11:19:58 +03:00
|
|
|
include make/release_flags.mk
|
2018-08-10 09:17:07 +03:00
|
|
|
|
2018-09-26 14:31:40 +03:00
|
|
|
DEV_TAGS := $(if ${tags},$(DEV_TAGS) ${tags},$(DEV_TAGS))
|
|
|
|
|
2020-04-21 11:19:58 +03:00
|
|
|
# We only return the part inside the double quote here to avoid escape issues
|
|
|
|
# when calling the external release script. The second parameter can be used to
|
|
|
|
# add additional ldflags if needed (currently only used for the release).
|
|
|
|
make_ldflags = $(2) -X $(PKG)/build.Commit=$(COMMIT) \
|
2020-04-10 03:04:55 +03:00
|
|
|
-X $(PKG)/build.CommitHash=$(COMMIT_HASH) \
|
2020-04-10 03:05:24 +03:00
|
|
|
-X $(PKG)/build.GoVersion=$(GOVERSION) \
|
2020-04-21 11:19:58 +03:00
|
|
|
-X $(PKG)/build.RawTags=$(shell echo $(1) | sed -e 's/ /,/g')
|
2020-04-10 03:04:55 +03:00
|
|
|
|
2020-04-21 11:19:58 +03:00
|
|
|
LDFLAGS := -ldflags "$(call make_ldflags, ${tags})"
|
|
|
|
DEV_LDFLAGS := -ldflags "$(call make_ldflags, $(DEV_TAGS))"
|
|
|
|
ITEST_LDFLAGS := -ldflags "$(call make_ldflags, $(ITEST_TAGS))"
|
|
|
|
|
|
|
|
# For the release, we want to remove the symbol table and debug information (-s)
|
|
|
|
# and omit the DWARF symbol table (-w). Also we clear the build ID.
|
|
|
|
RELEASE_LDFLAGS := $(call make_ldflags, $(RELEASE_TAGS), -s -w -buildid=)
|
2020-04-10 03:04:55 +03:00
|
|
|
|
2020-03-28 12:39:17 +03:00
|
|
|
# Linting uses a lot of memory, so keep it under control by limiting the number
|
|
|
|
# of workers if requested.
|
|
|
|
ifneq ($(workers),)
|
|
|
|
LINT_WORKERS = --concurrency=$(workers)
|
|
|
|
endif
|
|
|
|
|
|
|
|
LINT = $(LINT_BIN) run -v $(LINT_WORKERS)
|
2018-03-29 08:16:18 +03:00
|
|
|
|
|
|
|
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):
|
2019-07-22 12:05:57 +03:00
|
|
|
@$(call print, "Fetching linter")
|
2019-09-19 00:05:11 +03:00
|
|
|
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
|
2018-03-29 08:16:18 +03:00
|
|
|
|
2019-01-18 14:17:58 +03:00
|
|
|
$(GOACC_BIN):
|
|
|
|
@$(call print, "Fetching go-acc")
|
2019-09-19 00:03:18 +03:00
|
|
|
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
|
2019-01-18 14:17:58 +03:00
|
|
|
|
2018-12-03 02:43:26 +03:00
|
|
|
btcd:
|
2018-12-01 02:20:50 +03:00
|
|
|
@$(call print, "Installing btcd.")
|
2019-09-19 00:03:18 +03:00
|
|
|
$(DEPGET) $(BTCD_PKG)@$(BTCD_COMMIT)
|
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.")
|
2020-04-10 03:04:55 +03:00
|
|
|
$(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(DEV_LDFLAGS) $(PKG)/cmd/lnd
|
|
|
|
$(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(DEV_LDFLAGS) $(PKG)/cmd/lncli
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-11-02 11:49:32 +03:00
|
|
|
build-itest:
|
|
|
|
@$(call print, "Building itest lnd and lncli.")
|
2020-04-10 03:04:55 +03:00
|
|
|
$(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(ITEST_LDFLAGS) $(PKG)/cmd/lnd
|
|
|
|
$(GOBUILD) -tags="$(ITEST_TAGS)" -o lncli-itest $(ITEST_LDFLAGS) $(PKG)/cmd/lncli
|
2018-11-02 11:49:32 +03:00
|
|
|
|
2018-03-28 14:22:52 +03:00
|
|
|
install:
|
2018-03-29 08:16:18 +03:00
|
|
|
@$(call print, "Installing lnd and lncli.")
|
2019-01-24 16:28:26 +03:00
|
|
|
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lnd
|
2018-12-01 02:20:47 +03:00
|
|
|
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lncli
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2020-04-21 11:19:58 +03:00
|
|
|
release:
|
|
|
|
@$(call print, "Releasing lnd and lncli binaries.")
|
|
|
|
$(VERSION_CHECK)
|
2020-04-24 15:27:48 +03:00
|
|
|
./scripts/release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_TAGS)" "$(RELEASE_LDFLAGS)"
|
2020-04-21 11:19:58 +03:00
|
|
|
|
2018-11-29 04:17:38 +03:00
|
|
|
scratch: 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-12-03 02:43:26 +03:00
|
|
|
itest-only:
|
2019-05-24 15:17:48 +03:00
|
|
|
@$(call print, "Running integration tests with ${backend} backend.")
|
2018-03-29 08:16:18 +03:00
|
|
|
$(ITEST)
|
2020-04-07 18:22:26 +03:00
|
|
|
lntest/itest/log_check_errors.sh
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-11-02 11:49:32 +03:00
|
|
|
itest: btcd build-itest itest-only
|
2018-10-11 11:31:04 +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
|
|
|
|
2019-01-18 14:17:58 +03:00
|
|
|
unit-cover: $(GOACC_BIN)
|
2018-03-29 08:16:18 +03:00
|
|
|
@$(call print, "Running unit coverage tests.")
|
2019-05-21 13:33:07 +03:00
|
|
|
$(GOACC_BIN) $(COVER_PKG) -- -test.tags="$(DEV_TAGS) $(LOG_TAGS)"
|
|
|
|
|
2018-12-03 02:43:26 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
unit-race:
|
|
|
|
@$(call print, "Running unit race tests.")
|
2018-12-03 02:24:14 +03:00
|
|
|
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE)
|
2018-03-29 08:16:18 +03:00
|
|
|
|
2018-10-11 11:31:04 +03:00
|
|
|
goveralls: $(GOVERALLS_BIN)
|
|
|
|
@$(call print, "Sending coverage report.")
|
2019-01-18 14:17:58 +03:00
|
|
|
$(GOVERALLS_BIN) -coverprofile=coverage.txt -service=travis-ci
|
2018-10-11 11:31:04 +03:00
|
|
|
|
2018-12-01 02:20:45 +03:00
|
|
|
|
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 06:53:20 +03:00
|
|
|
travis-race: btcd unit-race
|
2019-02-01 02:36:56 +03:00
|
|
|
|
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 06:53:20 +03:00
|
|
|
travis-cover: btcd unit-cover goveralls
|
2018-12-01 02:20:45 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
# =============
|
|
|
|
# FLAKE HUNTING
|
|
|
|
# =============
|
|
|
|
|
2019-01-17 12:24:32 +03:00
|
|
|
flakehunter: build-itest
|
2019-05-24 15:17:48 +03:00
|
|
|
@$(call print, "Flake hunting ${backend} 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.")
|
2019-03-07 04:30:28 +03:00
|
|
|
while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done
|
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.")
|
2018-10-25 05:06:58 +03:00
|
|
|
gofmt -l -w -s $(GOFILES_NOVENDOR)
|
2018-03-28 14:22:52 +03:00
|
|
|
|
2018-03-29 08:16:18 +03:00
|
|
|
lint: $(LINT_BIN)
|
|
|
|
@$(call print, "Linting source.")
|
2019-07-22 12:05:57 +03:00
|
|
|
$(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
|
|
|
|
2019-05-23 01:24:40 +03:00
|
|
|
rpc-format:
|
|
|
|
@$(call print, "Formatting protos.")
|
|
|
|
cd ./lnrpc; find . -name "*.proto" | xargs clang-format --style=file -i
|
|
|
|
|
2020-03-11 12:17:45 +03:00
|
|
|
rpc-check: rpc
|
2019-05-23 01:24:40 +03:00
|
|
|
@$(call print, "Verifying protos.")
|
2020-06-03 12:14:33 +03:00
|
|
|
for rpc in $$(find lnrpc/ -name "*.proto" | $(XARGS) awk '/ rpc /{print $$2}'); do if ! grep -q $$rpc lnrpc/rest-annotations.yaml; then echo "RPC $$rpc not added to lnrpc/rest-annotations.yaml"; exit 1; fi; done
|
2019-05-23 01:24:40 +03:00
|
|
|
if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with v3.4.0"; git status; git diff; exit 1; fi
|
|
|
|
|
2019-01-24 16:51:05 +03:00
|
|
|
mobile-rpc:
|
|
|
|
@$(call print, "Creating mobile RPC from protos.")
|
|
|
|
cd ./mobile; ./gen_bindings.sh
|
|
|
|
|
2019-01-24 16:51:06 +03:00
|
|
|
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)
|
|
|
|
|
2019-01-24 16:51:06 +03:00
|
|
|
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
|
|
|
|
|
2018-03-28 14:22:52 +03:00
|
|
|
clean:
|
2018-03-29 08:16:18 +03:00
|
|
|
@$(call print, "Cleaning source.$(NC)")
|
2018-09-14 00:17:33 +03:00
|
|
|
$(RM) ./lnd-debug ./lncli-debug
|
2018-11-02 11:49:32 +03:00
|
|
|
$(RM) ./lnd-itest ./lncli-itest
|
2018-09-14 00:17:33 +03:00
|
|
|
$(RM) -r ./vendor .vendor-new
|
2018-03-29 08:16:18 +03:00
|
|
|
|
|
|
|
|
|
|
|
.PHONY: all \
|
2018-09-09 11:48:37 +03:00
|
|
|
btcd \
|
2018-03-29 08:16:18 +03:00
|
|
|
default \
|
|
|
|
build \
|
|
|
|
install \
|
|
|
|
scratch \
|
|
|
|
check \
|
2018-10-11 11:31:04 +03:00
|
|
|
itest-only \
|
2018-03-29 08:16:18 +03:00
|
|
|
itest \
|
|
|
|
unit \
|
|
|
|
unit-cover \
|
|
|
|
unit-race \
|
2018-10-11 11:31:04 +03:00
|
|
|
goveralls \
|
2018-12-01 02:20:45 +03:00
|
|
|
travis-race \
|
|
|
|
travis-cover \
|
2019-02-01 02:36:56 +03:00
|
|
|
travis-itest \
|
2018-03-29 08:16:18 +03:00
|
|
|
flakehunter \
|
|
|
|
flake-unit \
|
|
|
|
fmt \
|
|
|
|
lint \
|
|
|
|
list \
|
|
|
|
rpc \
|
2019-05-23 01:24:40 +03:00
|
|
|
rpc-format \
|
|
|
|
rpc-check \
|
2019-01-24 16:51:05 +03:00
|
|
|
mobile-rpc \
|
2019-01-24 16:51:06 +03:00
|
|
|
vendor \
|
|
|
|
ios \
|
2019-01-24 16:51:06 +03:00
|
|
|
android \
|
|
|
|
mobile \
|
2018-03-29 08:16:18 +03:00
|
|
|
clean
|