faraday/Makefile
2022-04-29 14:20:47 +02:00

178 lines
4.3 KiB
Makefile

PKG := github.com/lightninglabs/faraday
ESCPKG := github.com\/lightninglabs\/faraday
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
GOVERALLS_PKG := github.com/mattn/goveralls
GOACC_PKG := github.com/ory/go-acc
IMPORTS_PKG := github.com/pavius/impi/cmd/impi
IMPORTS_COMMIT := 3cdbde3d3cbb0ead2b9491272bccb5c652174656
GO_BIN := ${GOPATH}/bin
GOVERALLS_BIN := $(GO_BIN)/goveralls
LINT_BIN := $(GO_BIN)/golangci-lint
GOACC_BIN := $(GO_BIN)/go-acc
IMPORTS_BIN := $(GO_BIN)/impi
COMMIT := $(shell git describe --abbrev=40 --dirty)
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT)"
LINT_COMMIT := v1.18.0
GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5
DEPGET := cd /tmp && GO111MODULE=on go get -v
GOBUILD := GO111MODULE=on go build -v
GOINSTALL := GO111MODULE=on go install -v
GOTEST := GO111MODULE=on go test -v
GOMOD := GO111MODULE=on go mod
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/' | grep -v '/itest'
GOLISTCOVER := $(shell go list -deps -f '{{.ImportPath}}' ./... | grep '$(PKG)' | sed -e 's/^$(ESCPKG)/./')
RM := rm -f
CP := cp
MAKE := make
XARGS := xargs -L 1
include make/testing_flags.mk
LINT = $(LINT_BIN) run -v
default: scratch
all: scratch check install
# ============
# DEPENDENCIES
# ============
$(GOVERALLS_BIN):
@$(call print, "Fetching goveralls.")
go get -u $(GOVERALLS_PKG)
$(LINT_BIN):
@$(call print, "Fetching linter")
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
$(GOACC_BIN):
@$(call print, "Fetching go-acc")
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
$(IMPORTS_BIN):
@$(call print, "Fetching imports check")
$(DEPGET) $(IMPORTS_PKG)@$(IMPORTS_COMMIT)
# ============
# INSTALLATION
# ============
build:
@$(call print, "Building faraday.")
$(GOBUILD) $(LDFLAGS) $(PKG)/cmd/faraday
$(GOBUILD) $(LDFLAGS) $(PKG)/cmd/frcli
install:
@$(call print, "Installing faraday.")
$(GOINSTALL) $(LDFLAGS) $(PKG)/cmd/faraday
$(GOINSTALL) $(LDFLAGS) $(PKG)/cmd/frcli
scratch: build
# =======
# TESTING
# =======
check: unit
itest:
@$(call print, "Running integration tests.")
./run_itest.sh
unit:
@$(call print, "Running unit tests.")
$(UNIT)
unit-cover: $(GOACC_BIN)
@$(call print, "Running unit coverage tests.")
$(GOACC_BIN) $(COVER_PKG)
unit-race:
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE)
goveralls: $(GOVERALLS_BIN)
@$(call print, "Sending coverage report.")
$(GOVERALLS_BIN) -coverprofile=coverage.txt -service=travis-ci
travis-race: lint unit-race
travis-cover: lint unit-cover goveralls
travis-itest: lint
# =============
# FLAKE HUNTING
# =============
flake-unit:
@$(call print, "Flake hunting unit tests.")
while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done
# =========
# UTILITIES
# =========
fmt:
@$(call print, "Formatting source.")
gofmt -l -w -s $(GOFILES_NOVENDOR)
imports: $(IMPORTS_BIN)
@$(call print, "Checking imports.")
$(IMPORTS_BIN) --local github.com/lightninglabs/faraday/ --scheme stdThirdPartyLocal --ignore-generated=true *
lint: $(LINT_BIN)
@$(call print, "Linting source.")
$(LINT)
mod:
@$(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
rpc:
@$(call print, "Compiling protos.")
cd ./frdrpc; ./gen_protos_docker.sh
rpc-check: rpc
@$(call print, "Verifying protos.")
if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with v3.4.0"; git status; git diff; exit 1; fi
rpc-format:
@$(call print, "Formatting protos.")
cd ./frdrpc; find . -name "*.proto" | xargs clang-format --style=file -i
rpc-js-compile:
@$(call print, "Compiling JSON/WASM stubs.")
GOOS=js GOARCH=wasm $(GOBUILD) $(PKG)/frdrpc
list:
@$(call print, "Listing commands.")
@$(MAKE) -qp | \
awk -F':' '/^[a-zA-Z0-9][^$$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)print A[i]}' | \
grep -v Makefile | \
sort
clean:
@$(call print, "Cleaning source.$(NC)")
$(RM) ./faraday
$(RM) ./frcli
$(RM) coverage.txt
# Instruct make to not interpret these as file/folder related targets, otherwise
# it will behave weirdly if a file or folder exists with that name.
.PHONY: itest