From a03c5c9ac3898766230baa4f0469b8476b20b5f8 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Wed, 21 Dec 2016 11:42:53 -0600 Subject: [PATCH 1/4] Makefile,cmd: set version and fail if it's blank --- Makefile | 2 +- cmd/version.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2fe90c507..60714ea98 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ SRCFILES = $(eval SRCFILES := main.go $(shell find ${SRCDIRS} -name '*.go'))$(va # binaries converge: vendor ${SRCFILES} rpc/pb/root.pb.go rpc/pb/root.pb.gw.go - go build -ldflags="-X ${REPO}/cmd.Version=${PACKAGE}" + go build -ldflags="-X ${REPO}/cmd.Version=${VERSION}" rpc/pb/root.pb.go: rpc/pb/root.proto protoc -I rpc/pb \ diff --git a/cmd/version.go b/cmd/version.go index 7758e6b98..ae26bbc2e 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -17,6 +17,7 @@ package cmd import ( "fmt" + "github.com/Sirupsen/logrus" "github.com/spf13/cobra" ) @@ -34,4 +35,8 @@ var versionCmd = &cobra.Command{ func init() { RootCmd.AddCommand(versionCmd) + + if Version == "" { + logrus.Fatal("version is set to blank") + } } From 3bd770676cbaa0cae86b88537ddd16185acad9f7 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Wed, 21 Dec 2016 11:43:22 -0600 Subject: [PATCH 2/4] Makefile: use subst instead of another subshell --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 60714ea98..bf3c07007 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ REPO = $(eval REPO := $(shell go list -f '{{.ImportPath}}' .))$(value REPO) NAME = $(eval NAME := $(shell basename ${REPO}))$(value NAME) VERSION = $(eval VERSION := $(shell git describe --dirty))$(value VERSION) -PACKAGE_VERSION = $(eval PACKAGE_VERSION := $(shell git describe))$(value PACKAGE_VERSION) +PACKAGE_VERSION = $(eval PACKAGE_VERSION := $(subst -dirty,,${VERSION}))$(value PACKAGE_VERSION) # sources to evaluate SRCDIRS = $(eval SRCDIRS := $(shell glide novendor --no-subdir | grep -v '^.$$' | sed 's|/$$||g'))$(value SRCDIRS) From 4c9abdc0f402d8d99283613a7ad5c4d2371f2f8f Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Wed, 21 Dec 2016 11:43:37 -0600 Subject: [PATCH 3/4] Makefile: make SRCDIRS and SRCFILES eagerly evaluated They're effectively strict because they're listed in the converge target, so there's no point in making them lazy. Plus it seems like Make on some platforms is expanding them too much and causing syntax errors. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bf3c07007..f92d7d3dd 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,8 @@ VERSION = $(eval VERSION := $(shell git describe --dirty))$(value VERSION) PACKAGE_VERSION = $(eval PACKAGE_VERSION := $(subst -dirty,,${VERSION}))$(value PACKAGE_VERSION) # sources to evaluate -SRCDIRS = $(eval SRCDIRS := $(shell glide novendor --no-subdir | grep -v '^.$$' | sed 's|/$$||g'))$(value SRCDIRS) -SRCFILES = $(eval SRCFILES := main.go $(shell find ${SRCDIRS} -name '*.go'))$(value SRCFILES) +SRCDIRS := $(shell find . -maxdepth 1 -mindepth 1 -type d -not -path './vendor') +SRCFILES := main.go $(shell find ${SRCDIRS} -name '*.go') # binaries converge: vendor ${SRCFILES} rpc/pb/root.pb.go rpc/pb/root.pb.gw.go From c9e5cc629615372ff268c66efe5323c5d6f86330 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Wed, 21 Dec 2016 11:49:55 -0600 Subject: [PATCH 4/4] Makefile: stop early expansion in lazy variables --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index f92d7d3dd..a28627791 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ # this way will be evaluated exactly once, and only if used. # # meta information about the project -REPO = $(eval REPO := $(shell go list -f '{{.ImportPath}}' .))$(value REPO) -NAME = $(eval NAME := $(shell basename ${REPO}))$(value NAME) -VERSION = $(eval VERSION := $(shell git describe --dirty))$(value VERSION) -PACKAGE_VERSION = $(eval PACKAGE_VERSION := $(subst -dirty,,${VERSION}))$(value PACKAGE_VERSION) +REPO = $(eval REPO := $$(shell go list -f '{{.ImportPath}}' .))$(value REPO) +NAME = $(eval NAME := $$(shell basename ${REPO}))$(value NAME) +VERSION = $(eval VERSION := $$(shell git describe --dirty))$(value VERSION) +PACKAGE_VERSION = $(eval PACKAGE_VERSION := $$(subst -dirty,,$${VERSION}))$(value PACKAGE_VERSION) # sources to evaluate SRCDIRS := $(shell find . -maxdepth 1 -mindepth 1 -type d -not -path './vendor') @@ -89,7 +89,7 @@ bench: go test -run '^$$' -bench=${BENCH} -benchmem ${BENCHDIRS} # linting -LINTDIRS = $(eval LINTDIRS := $(shell find ${SRCDIRS} -type d -not -path './rpc/pb' -not -path './docs*'))$(value LINTDIRS) +LINTDIRS = $(eval LINTDIRS := $$(shell find ${SRCDIRS} -type d -not -path './rpc/pb' -not -path './docs*'))$(value LINTDIRS) .PHONY: lint lint: @echo '=== golint ==='