Skip to content

Commit 4ed3197

Browse files
committed
make+tools: tidy makefile, add gosimports
1 parent a1271fe commit 4ed3197

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

Makefile

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ TOOLS_DIR := tools
55

66
GOTEST := GO111MODULE=on go test -v
77

8+
9+
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
10+
811
GO_BIN := ${GOPATH}/bin
12+
GOIMPORTS_BIN := $(GO_BIN)/gosimports
13+
914
GOBUILD := GO111MODULE=on go build -v
1015
GOINSTALL := GO111MODULE=on go install -v
1116
GOMOD := GO111MODULE=on go mod
@@ -14,7 +19,7 @@ COMMIT := $(shell git describe --abbrev=40 --dirty)
1419
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT)"
1520
DEV_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")
1823
GOLIST := go list $(PKG)/... | grep -v '/vendor/'
1924

2025
XARGS := xargs -L 1
@@ -37,34 +42,14 @@ define print
3742
echo $(GREEN)$1$(NC)
3843
endef
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+

tools/go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module github.com/lightninglabs/loop/tools
22

33
go 1.16
44

5-
require github.com/golangci/golangci-lint v1.46.2 // indirect
5+
require (
6+
github.com/golangci/golangci-lint v1.46.2 // indirect
7+
github.com/rinchsan/gosimports v0.1.5 // indirect
8+
)

tools/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567/go.mod h1:DWNGW8
696696
github.com/remyoudompheng/go-dbus v0.0.0-20121104212943-b7232d34b1d5/go.mod h1:+u151txRmLpwxBmpYn9z3d1sdJdjRPQpsXuYeY9jNls=
697697
github.com/remyoudompheng/go-liblzma v0.0.0-20190506200333-81bf2d431b96/go.mod h1:90HvCY7+oHHUKkbeMCiHt1WuFR2/hPJ9QrljDG+v6ls=
698698
github.com/remyoudompheng/go-misc v0.0.0-20190427085024-2d6ac652a50e/go.mod h1:80FQABjoFzZ2M5uEa6FUaJYEmqU2UOKojlFVak1UAwI=
699+
github.com/rinchsan/gosimports v0.1.5 h1:Z/l9lS79z0xgKC6fLJYmDdY44D0LFwo3MzaMtWvMKpY=
700+
github.com/rinchsan/gosimports v0.1.5/go.mod h1:102/jU2cwf9fpa/YM9D9o4gSen2Vg8Jl80Sxctgd9N0=
699701
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
700702
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
701703
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

tools/tools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ package loop
55

66
import (
77
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
8+
_ "github.com/rinchsan/gosimports/cmd/gosimports"
89
)

0 commit comments

Comments
 (0)