|
|
|
@ -5,7 +5,12 @@ TOOLS_DIR := tools
|
|
|
|
|
|
|
|
|
|
GOTEST := GO111MODULE=on go test -v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
|
|
|
|
|
|
|
|
|
|
GO_BIN := ${GOPATH}/bin
|
|
|
|
|
GOIMPORTS_BIN := $(GO_BIN)/gosimports
|
|
|
|
|
|
|
|
|
|
GOBUILD := GO111MODULE=on go build -v
|
|
|
|
|
GOINSTALL := GO111MODULE=on go install -v
|
|
|
|
|
GOMOD := GO111MODULE=on go mod
|
|
|
|
@ -14,7 +19,7 @@ COMMIT := $(shell git describe --abbrev=40 --dirty)
|
|
|
|
|
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT)"
|
|
|
|
|
DEV_TAGS = dev
|
|
|
|
|
|
|
|
|
|
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
|
|
|
|
|
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")
|
|
|
|
|
GOLIST := go list $(PKG)/... | grep -v '/vendor/'
|
|
|
|
|
|
|
|
|
|
XARGS := xargs -L 1
|
|
|
|
@ -37,34 +42,14 @@ define print
|
|
|
|
|
echo $(GREEN)$1$(NC)
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
$(LINT_BIN):
|
|
|
|
|
@$(call print, "Fetching linter")
|
|
|
|
|
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
|
|
|
|
|
|
|
|
|
|
unit:
|
|
|
|
|
@$(call print, "Running unit tests.")
|
|
|
|
|
$(UNIT)
|
|
|
|
|
|
|
|
|
|
fmt:
|
|
|
|
|
@$(call print, "Formatting source.")
|
|
|
|
|
gofmt -l -w -s $(GOFILES_NOVENDOR)
|
|
|
|
|
|
|
|
|
|
lint: docker-tools
|
|
|
|
|
@$(call print, "Linting source.")
|
|
|
|
|
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
|
|
|
|
|
|
|
|
|
|
docker-tools:
|
|
|
|
|
@$(call print, "Building tools docker image.")
|
|
|
|
|
docker build -q -t loop-tools $(TOOLS_DIR)
|
|
|
|
|
# ============
|
|
|
|
|
# DEPENDENCIES
|
|
|
|
|
# ============
|
|
|
|
|
|
|
|
|
|
mod-tidy:
|
|
|
|
|
@$(call print, "Tidying modules.")
|
|
|
|
|
$(GOMOD) tidy
|
|
|
|
|
$(GOIMPORTS_BIN):
|
|
|
|
|
@$(call print, "Installing goimports.")
|
|
|
|
|
cd $(TOOLS_DIR); go install -trimpath $(GOIMPORTS_PKG)
|
|
|
|
|
|
|
|
|
|
mod-check:
|
|
|
|
|
@$(call print, "Checking modules.")
|
|
|
|
|
$(GOMOD) tidy
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
# ============
|
|
|
|
|
# INSTALLATION
|
|
|
|
@ -101,3 +86,40 @@ clean:
|
|
|
|
|
@$(call print, "Cleaning up.")
|
|
|
|
|
rm -f ./loop-debug ./loopd-debug
|
|
|
|
|
rm -rf ./vendor
|
|
|
|
|
|
|
|
|
|
# =======
|
|
|
|
|
# TESTING
|
|
|
|
|
# =======
|
|
|
|
|
|
|
|
|
|
unit:
|
|
|
|
|
@$(call print, "Running unit tests.")
|
|
|
|
|
$(UNIT)
|
|
|
|
|
|
|
|
|
|
# =========
|
|
|
|
|
# UTILITIES
|
|
|
|
|
# =========
|
|
|
|
|
|
|
|
|
|
fmt: $(GOIMPORTS_BIN)
|
|
|
|
|
@$(call print, "Fixing imports.")
|
|
|
|
|
gosimports -w $(GOFILES_NOVENDOR)
|
|
|
|
|
@$(call print, "Formatting source.")
|
|
|
|
|
gofmt -l -w -s $(GOFILES_NOVENDOR)
|
|
|
|
|
|
|
|
|
|
lint: docker-tools
|
|
|
|
|
@$(call print, "Linting source.")
|
|
|
|
|
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
|
|
|
|
|
|
|
|
|
|
docker-tools:
|
|
|
|
|
@$(call print, "Building tools docker image.")
|
|
|
|
|
docker build -q -t loop-tools $(TOOLS_DIR)
|
|
|
|
|
|
|
|
|
|
mod-tidy:
|
|
|
|
|
@$(call print, "Tidying modules.")
|
|
|
|
|
$(GOMOD) tidy
|
|
|
|
|
|
|
|
|
|
mod-check:
|
|
|
|
|
@$(call print, "Checking modules.")
|
|
|
|
|
$(GOMOD) tidy
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|