@@ -5,7 +5,12 @@ TOOLS_DIR := tools
55
66GOTEST := GO111MODULE=on go test -v
77
8+
9+ GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
10+
811GO_BIN := ${GOPATH}/bin
12+ GOIMPORTS_BIN := $(GO_BIN ) /gosimports
13+
914GOBUILD := GO111MODULE=on go build -v
1015GOINSTALL := GO111MODULE=on go install -v
1116GOMOD := GO111MODULE=on go mod
@@ -14,7 +19,7 @@ COMMIT := $(shell git describe --abbrev=40 --dirty)
1419LDFLAGS := -ldflags "-X $(PKG ) .Commit=$(COMMIT ) "
1520DEV_TAGS = dev
1621
17- GOFILES_NOVENDOR = $(shell find . -type f -name '* .go' -not -path "./vendor/* ")
22+ GOFILES_NOVENDOR = $(shell find . -type f -name '* .go' -not -path "./vendor/* " -not -name " * pb.go" -not -name " * pb.gw.go" -not -name " * .pb.json.go" )
1823GOLIST := go list $(PKG ) /... | grep -v '/vendor/'
1924
2025XARGS := xargs -L 1
@@ -37,34 +42,14 @@ define print
3742 echo $(GREEN ) $1$(NC )
3843endef
3944
40- $(LINT_BIN ) :
41- @$(call print, "Fetching linter")
42- $(DEPGET ) $(LINT_PKG ) @$(LINT_COMMIT )
43-
44- unit :
45- @$(call print, "Running unit tests.")
46- $(UNIT )
47-
48- fmt :
49- @$(call print, "Formatting source.")
50- gofmt -l -w -s $(GOFILES_NOVENDOR )
51-
52- lint : docker-tools
53- @$(call print, "Linting source.")
54- $(DOCKER_TOOLS ) golangci-lint run -v $(LINT_WORKERS )
55-
56- docker-tools :
57- @$(call print, "Building tools docker image.")
58- docker build -q -t loop-tools $(TOOLS_DIR )
45+ # ============
46+ # DEPENDENCIES
47+ # ============
5948
60- mod-tidy :
61- @$(call print, "Tidying modules .")
62- $( GOMOD ) tidy
49+ $( GOIMPORTS_BIN ) :
50+ @$(call print, "Installing goimports .")
51+ cd $( TOOLS_DIR ) ; go install -trimpath $( GOIMPORTS_PKG )
6352
64- mod-check :
65- @$(call print, "Checking modules.")
66- $(GOMOD ) tidy
67- if test -n " $$ (git status | grep -e " go.mod\| go.sum" )" ; then echo " Running go mod tidy changes go.mod/go.sum" ; git status; git diff; exit 1; fi
6853
6954# ============
7055# INSTALLATION
@@ -101,3 +86,40 @@ clean:
10186 @$(call print, "Cleaning up.")
10287 rm -f ./loop-debug ./loopd-debug
10388 rm -rf ./vendor
89+
90+ # =======
91+ # TESTING
92+ # =======
93+
94+ unit :
95+ @$(call print, "Running unit tests.")
96+ $(UNIT )
97+
98+ # =========
99+ # UTILITIES
100+ # =========
101+
102+ fmt : $(GOIMPORTS_BIN )
103+ @$(call print, "Fixing imports.")
104+ gosimports -w $(GOFILES_NOVENDOR )
105+ @$(call print, "Formatting source.")
106+ gofmt -l -w -s $(GOFILES_NOVENDOR )
107+
108+ lint : docker-tools
109+ @$(call print, "Linting source.")
110+ $(DOCKER_TOOLS ) golangci-lint run -v $(LINT_WORKERS )
111+
112+ docker-tools :
113+ @$(call print, "Building tools docker image.")
114+ docker build -q -t loop-tools $(TOOLS_DIR )
115+
116+ mod-tidy :
117+ @$(call print, "Tidying modules.")
118+ $(GOMOD ) tidy
119+
120+ mod-check :
121+ @$(call print, "Checking modules.")
122+ $(GOMOD ) tidy
123+ if test -n " $$ (git status | grep -e " go.mod\| go.sum" )" ; then echo " Running go mod tidy changes go.mod/go.sum" ; git status; git diff; exit 1; fi
124+
125+
0 commit comments