11PKG := github.com/lightninglabs/lndclient
22
3- LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
3+ TOOLS_DIR := tools
44
5- GO_BIN := ${GOPATH}/bin
6- LINT_BIN := $(GO_BIN ) /golangci-lint
5+ GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
76
8- LINT_COMMIT := v1.18.0
7+ GO_BIN := ${GOPATH}/bin
8+ GOIMPORTS_BIN := $(GO_BIN ) /gosimports
99
10- DEPGET := cd /tmp && go get -v
1110GOBUILD := go build -v
1211GOINSTALL := go install -v
1312GOTEST := go test -v
@@ -29,7 +28,7 @@ ifneq ($(workers),)
2928LINT_WORKERS = --concurrency=$(workers )
3029endif
3130
32- LINT = $( LINT_BIN ) run -v $( LINT_WORKERS )
31+ DOCKER_TOOLS = docker run -v $$( pwd ) :/build lndclient-tools
3332
3433GREEN := "\\033[0;32m"
3534NC := "\\033[0m"
@@ -44,9 +43,9 @@ all: build check install
4443# ============
4544# DEPENDENCIES
4645# ============
47- $(LINT_BIN ) :
48- @$(call print, "Fetching linter ")
49- $( DEPGET ) $( LINT_PKG ) @ $( LINT_COMMIT )
46+ $(GOIMPORTS_BIN ) :
47+ @$(call print, "Installing goimports. ")
48+ cd $( TOOLS_DIR ) ; go install -trimpath $( GOIMPORTS_PKG )
5049
5150# ============
5251# INSTALLATION
@@ -56,6 +55,10 @@ build:
5655 @$(call print, "Building lndclient.")
5756 $(GOBUILD ) -ldflags=" $( LDFLAGS) " $(PKG )
5857
58+ docker-tools :
59+ @$(call print, "Building tools docker image.")
60+ docker build -q -t lndclient-tools $(TOOLS_DIR )
61+
5962# =======
6063# TESTING
6164# =======
@@ -73,13 +76,15 @@ unit-race:
7376# =========
7477# UTILITIES
7578# =========
76- fmt :
79+ fmt : $(GOIMPORTS_BIN )
80+ @$(call print, "Fixing imports.")
81+ gosimports -w $(GOFILES_NOVENDOR )
7782 @$(call print, "Formatting source.")
7883 gofmt -l -w -s $(GOFILES_NOVENDOR )
7984
80- lint : $( LINT_BIN )
85+ lint : docker-tools
8186 @$(call print, "Linting source.")
82- $(LINT )
87+ $(DOCKER_TOOLS ) golangci-lint run -v $( LINT_WORKERS )
8388
8489.PHONY : default \
8590 build \
0 commit comments