2020-05-14 09:33:08 +00:00
|
|
|
.DEFAULT_GOAL := build
|
|
|
|
|
2019-03-07 09:19:27 +00:00
|
|
|
PKG := github.com/lightninglabs/loop
|
2022-05-20 06:56:21 +00:00
|
|
|
TOOLS_DIR := tools
|
2019-03-07 09:19:27 +00:00
|
|
|
|
|
|
|
GOTEST := GO111MODULE=on go test -v
|
|
|
|
|
2022-05-20 07:00:26 +00:00
|
|
|
|
|
|
|
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
|
|
|
|
|
2019-10-07 15:29:07 +00:00
|
|
|
GO_BIN := ${GOPATH}/bin
|
2022-05-20 07:00:26 +00:00
|
|
|
GOIMPORTS_BIN := $(GO_BIN)/gosimports
|
|
|
|
|
2020-04-15 07:10:08 +00:00
|
|
|
GOBUILD := GO111MODULE=on go build -v
|
|
|
|
GOINSTALL := GO111MODULE=on go install -v
|
2020-06-01 10:41:36 +00:00
|
|
|
GOMOD := GO111MODULE=on go mod
|
2020-04-15 07:10:08 +00:00
|
|
|
|
|
|
|
COMMIT := $(shell git describe --abbrev=40 --dirty)
|
2020-11-06 09:42:57 +00:00
|
|
|
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT)"
|
2020-10-15 11:49:05 +00:00
|
|
|
DEV_TAGS = dev
|
2019-10-07 15:29:07 +00:00
|
|
|
|
2022-05-20 07:00:26 +00:00
|
|
|
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")
|
2019-03-07 09:19:27 +00:00
|
|
|
GOLIST := go list $(PKG)/... | grep -v '/vendor/'
|
|
|
|
|
|
|
|
XARGS := xargs -L 1
|
|
|
|
|
|
|
|
TEST_FLAGS = -test.timeout=20m
|
|
|
|
|
|
|
|
UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS)
|
|
|
|
|
2022-05-20 06:56:21 +00:00
|
|
|
# Linting uses a lot of memory, so keep it under control by limiting the number
|
|
|
|
# of workers if requested.
|
|
|
|
ifneq ($(workers),)
|
|
|
|
LINT_WORKERS = --concurrency=$(workers)
|
|
|
|
endif
|
|
|
|
|
|
|
|
DOCKER_TOOLS = docker run -v $$(pwd):/build loop-tools
|
|
|
|
|
2020-06-01 10:41:36 +00:00
|
|
|
GREEN := "\\033[0;32m"
|
|
|
|
NC := "\\033[0m"
|
|
|
|
define print
|
|
|
|
echo $(GREEN)$1$(NC)
|
|
|
|
endef
|
|
|
|
|
2022-05-20 07:00:26 +00:00
|
|
|
# ============
|
|
|
|
# DEPENDENCIES
|
|
|
|
# ============
|
2020-04-15 07:10:08 +00:00
|
|
|
|
2022-05-20 07:00:26 +00:00
|
|
|
$(GOIMPORTS_BIN):
|
|
|
|
@$(call print, "Installing goimports.")
|
|
|
|
cd $(TOOLS_DIR); go install -trimpath $(GOIMPORTS_PKG)
|
2020-06-01 10:41:36 +00:00
|
|
|
|
|
|
|
|
2020-04-15 07:10:08 +00:00
|
|
|
# ============
|
|
|
|
# INSTALLATION
|
|
|
|
# ============
|
|
|
|
|
|
|
|
build:
|
|
|
|
@$(call print, "Building debug loop and loopd.")
|
2020-10-15 11:49:05 +00:00
|
|
|
$(GOBUILD) -tags="$(DEV_TAGS)" -o loop-debug $(LDFLAGS) $(PKG)/cmd/loop
|
|
|
|
$(GOBUILD) -tags="$(DEV_TAGS)" -o loopd-debug $(LDFLAGS) $(PKG)/cmd/loopd
|
2020-04-15 07:10:08 +00:00
|
|
|
|
|
|
|
install:
|
|
|
|
@$(call print, "Installing loop and loopd.")
|
2020-10-15 11:49:05 +00:00
|
|
|
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/loop
|
|
|
|
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/loopd
|
2020-11-06 09:42:56 +00:00
|
|
|
|
|
|
|
rpc:
|
2021-05-25 14:33:44 +00:00
|
|
|
@$(call print, "Compiling protos.")
|
2021-12-13 11:56:40 +00:00
|
|
|
cd ./swapserverrpc; ./gen_protos_docker.sh
|
2021-05-25 14:33:44 +00:00
|
|
|
cd ./looprpc; ./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 correct version!"; git status; git diff; exit 1; fi
|
2021-08-03 11:19:44 +00:00
|
|
|
|
|
|
|
rpc-js-compile:
|
|
|
|
@$(call print, "Compiling JSON/WASM stubs.")
|
|
|
|
GOOS=js GOARCH=wasm $(GOBUILD) $(PKG)/looprpc
|
2021-11-29 15:36:50 +00:00
|
|
|
|
2021-12-13 11:56:40 +00:00
|
|
|
rpc-format:
|
|
|
|
cd ./looprpc; find . -name "*.proto" | xargs clang-format --style=file -i
|
|
|
|
cd ./swapserverrpc; find . -name "*.proto" | xargs clang-format --style=file -i
|
2021-11-29 15:36:50 +00:00
|
|
|
|
|
|
|
clean:
|
|
|
|
@$(call print, "Cleaning up.")
|
|
|
|
rm -f ./loop-debug ./loopd-debug
|
|
|
|
rm -rf ./vendor
|
2022-05-20 07:00:26 +00:00
|
|
|
|
|
|
|
# =======
|
|
|
|
# TESTING
|
|
|
|
# =======
|
|
|
|
|
|
|
|
unit:
|
|
|
|
@$(call print, "Running unit tests.")
|
|
|
|
$(UNIT)
|
|
|
|
|
2023-05-30 07:30:58 +00:00
|
|
|
unit-postgres:
|
|
|
|
@$(call print, "Running unit tests with postgres.")
|
|
|
|
$(UNIT) -tags=test_db_postgres
|
|
|
|
|
2022-05-20 07:00:26 +00:00
|
|
|
# =========
|
|
|
|
# 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
|
|
|
|
|
2023-05-17 17:05:34 +00:00
|
|
|
sqlc:
|
|
|
|
@$(call print, "Generating sql models and queries in Go")
|
|
|
|
./scripts/gen_sqlc_docker.sh
|
|
|
|
|
|
|
|
sqlc-check: sqlc
|
|
|
|
@$(call print, "Verifying sql code generation.")
|
|
|
|
if test -n "$$(git status --porcelain '*.go')"; then echo "SQL models not properly generated!"; git status --porcelain '*.go'; exit 1; fi
|
|
|
|
|
2023-08-23 09:27:23 +00:00
|
|
|
fsm:
|
|
|
|
@$(call print, "Generating state machine docs")
|
|
|
|
./scripts/fsm-generate.sh;
|
|
|
|
.PHONY: fsm
|