From 2f84d8ee2b025f3418efad8ddb890b37e21fff5c Mon Sep 17 00:00:00 2001 From: Chakib Benziane Date: Mon, 29 Jan 2018 17:11:03 +0100 Subject: [PATCH 1/5] add a basic makefile Included commands: - deps: install glide and dependencies - install: install lnd - fmt: run `go fmt` excluding vendor - test: run `go test` as per documentation --- Makefile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..aa3f8e7e --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: all glidebin glide deps install fmt test + +all: install + +glidebin: + go get -u github.com/Masterminds/glide + +glide: glidebin + glide install + +deps: glide + +install: deps + go install . ./cmd/... + +fmt: + go fmt ./... $$(go list ./... | grep -v '/vendor/') + +test: + go test -v -p 1 $$(go list ./... | grep -v '/vendor/') From e549a79eb3bbd99fab33a2f1320223af4045f8b5 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 28 Mar 2018 04:22:52 -0700 Subject: [PATCH 2/5] 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 aa3f8e7e..d39c21b4 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 From 3d29e9dc6668d127dd735abd1a2d4264d905f9b6 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 28 Mar 2018 14:09:42 -0700 Subject: [PATCH 3/5] lnd: add Commit hook for git hash -ldflag --- lnd.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lnd.go b/lnd.go index 9a0e1e71..11c77bdd 100644 --- a/lnd.go +++ b/lnd.go @@ -57,6 +57,10 @@ const ( ) var ( + //Commit stores the current commit hash of this build. This should be + //set using -ldflags during compilation. + Commit string + cfg *config shutdownChannel = make(chan struct{}) registeredChains = newChainRegistry() From 70038754ff2357137bace13cedb6737f7c5a79bf Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 28 Mar 2018 14:10:01 -0700 Subject: [PATCH 4/5] version: append commit hash to version string --- version.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/version.go b/version.go index 8e4ef787..77030ec6 100644 --- a/version.go +++ b/version.go @@ -55,6 +55,9 @@ func version() string { version = fmt.Sprintf("%s+%s", version, build) } + // Append commit hash of current build to version. + version = fmt.Sprintf("%s commit=%s", version, Commit) + return version } From b13970da706c097fcd95193142e38c2b797b574a Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 28 Mar 2018 14:10:23 -0700 Subject: [PATCH 5/5] cmd/lncli: add commit version hook and print in version --- cmd/lncli/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 142ca5ae..d6bb7cc4 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -29,6 +29,10 @@ const ( ) var ( + //Commit stores the current commit hash of this build. This should be + //set using -ldflags during compilation. + Commit string + defaultLndDir = btcutil.AppDataDir("lnd", false) defaultTLSCertPath = filepath.Join(defaultLndDir, defaultTLSCertFilename) defaultMacaroonPath = filepath.Join(defaultLndDir, defaultMacaroonFilename) @@ -150,7 +154,7 @@ func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn { func main() { app := cli.NewApp() app.Name = "lncli" - app.Version = "0.4" + app.Version = fmt.Sprintf("%s commit=%s", "0.4", Commit) app.Usage = "control plane for your Lightning Network Daemon (lnd)" app.Flags = []cli.Flag{ cli.StringFlag{