From e549a79eb3bbd99fab33a2f1320223af4045f8b5 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 28 Mar 2018 04:22:52 -0700 Subject: [PATCH] Makefile: update #689 to use dep in Makefile This commit continues the work started by @sp4ke, in createing a simple Makefile for lnd. The following commands are included: * make - builds everything (deps, lnd, and lncli) from scratch * make deps - installs dep if needed, then runs dep ensure * make install - builds lnd and lncli * make check - runs unit and itests * make unit - runs the unit tests for all packages * make itest - installs lnd and runs integration tests * make fmt - go fmt's all files --- Makefile | 96 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index aa3f8e7e9..d39c21b46 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,92 @@ -.PHONY: all glidebin glide deps install fmt test +PKG := github.com/lightningnetwork/lnd +HAVE_DEP := $(shell command -v dep 2> /dev/null) +COMMIT := $(shell git rev-parse HEAD) +LDFLAGS := -ldflags "-X main.Commit=$(COMMIT)" +RM := rm -all: install +all: scratch -glidebin: - go get -u github.com/Masterminds/glide -glide: glidebin - glide install +# ============================================================================== +# INSTALLATION +# ============================================================================== -deps: glide +deps: +ifndef HAVE_DEP + @echo "Fetching dep." + go get -u github.com/golang/dep/cmd/dep +endif + @echo "Building dependencies." + dep ensure -v -install: deps - go install . ./cmd/... +build: + @echo "Building lnd and lncli." + go build -v -o lnd $(LDFLAGS) $(PKG) + go build -v -o lncli $(LDFLAGS) $(PKG)/cmd/lncli + +install: + @echo "Installing lnd and lncli." + go install -v $(LDFLAGS) $(PKG) + go install -v $(LDFLAGS) $(PKG)/cmd/lncli + +scratch: deps 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) + +unit: + @echo "Running unit tests." + $(UNIT) + + +# ============================================================================== +# UTILITIES +# ============================================================================== fmt: - go fmt ./... $$(go list ./... | grep -v '/vendor/') + go list $(PKG)/... | grep -v '/vendor/' | xargs go fmt -x -test: - go test -v -p 1 $$(go list ./... | grep -v '/vendor/') +clean: + $(RM) ./lnd ./lncli + $(RM) -rf vendor + + +.PHONY: all deps build install scratch check itest unit fmt clean