2021-05-20 20:57:51 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
|
2024-09-17 07:29:16 +00:00
|
|
|
ANTLR_VERSION=4.13.1
|
2023-10-23 15:05:03 +00:00
|
|
|
TMP_DIR := .cache
|
2024-08-21 13:42:58 +00:00
|
|
|
LINT_VERSION ?= 1.60.1
|
2024-10-31 06:35:27 +00:00
|
|
|
TRUECLOUDLAB_LINT_VERSION ?= 0.0.7
|
2023-10-23 15:05:03 +00:00
|
|
|
OUTPUT_LINT_DIR ?= $(shell pwd)/bin
|
|
|
|
LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION)
|
2023-05-30 12:48:19 +00:00
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
PROTOC_VERSION ?= 27.2
|
|
|
|
PROTOC_GEN_GO_VERSION ?= $(shell go list -f '{{.Version}}' -m google.golang.org/protobuf)
|
|
|
|
PROTOC_OS_VERSION=osx-x86_64
|
|
|
|
ifeq ($(shell uname), Linux)
|
|
|
|
PROTOC_OS_VERSION=linux-x86_64
|
|
|
|
endif
|
|
|
|
|
|
|
|
BIN = bin
|
|
|
|
PROTOBUF_DIR ?= $(abspath $(BIN))/protobuf
|
|
|
|
PROTOC_DIR ?= $(PROTOBUF_DIR)/protoc-v$(PROTOC_VERSION)
|
|
|
|
PROTOC_GEN_GO_DIR ?= $(PROTOBUF_DIR)/protoc-gen-go-$(PROTOC_GEN_GO_VERSION)
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: dep imports protoc test lint help $(BIN)/protogen protoc-test
|
|
|
|
|
2021-05-20 20:57:51 +00:00
|
|
|
# Run tests
|
2024-03-14 09:29:00 +00:00
|
|
|
test: GOFLAGS ?= "-cover -count=1"
|
2021-05-20 20:57:51 +00:00
|
|
|
test:
|
2024-03-14 09:29:00 +00:00
|
|
|
@GOFLAGS=$(GOFLAGS) go test ./...
|
2021-05-20 20:57:51 +00:00
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
# Reformat imports
|
|
|
|
imports:
|
|
|
|
@echo "⇒ Processing goimports check"
|
|
|
|
@for f in `find . -type f -name '*.go' -not -name '*.pb.go' -prune`; do \
|
|
|
|
goimports -w $$f; \
|
|
|
|
done
|
|
|
|
|
|
|
|
# Install protoc
|
|
|
|
protoc-install:
|
|
|
|
@rm -rf $(PROTOBUF_DIR)
|
|
|
|
@mkdir -p $(PROTOBUF_DIR)
|
|
|
|
@echo "⇒ Installing protoc... "
|
|
|
|
@wget -q -O $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip 'https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS_VERSION).zip'
|
|
|
|
@unzip -q -o $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip -d $(PROTOC_DIR)
|
|
|
|
@rm $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip
|
|
|
|
@echo "⇒ Installing protoc-gen-go..."
|
|
|
|
@GOBIN=$(PROTOC_GEN_GO_DIR) go install -v google.golang.org/protobuf/...@$(PROTOC_GEN_GO_VERSION)
|
|
|
|
|
|
|
|
|
|
|
|
# Regenerate code for proto files
|
|
|
|
protoc:
|
|
|
|
@if [ ! -d "$(PROTOC_DIR)" ] || [ ! -d "$(PROTOC_GEN_GO_DIR)" ]; then \
|
|
|
|
make protoc-install; \
|
|
|
|
fi
|
|
|
|
# Protoc generate
|
|
|
|
@for f in `find . -type f -name '*.proto' -not -path './bin/*' -not -path './api/util/proto/test/*'`; do \
|
|
|
|
echo "⇒ Processing $$f "; \
|
|
|
|
$(PROTOC_DIR)/bin/protoc \
|
|
|
|
--proto_path=.:$(PROTOC_DIR)/include:/usr/local/include \
|
|
|
|
--plugin=protoc-gen-go-frostfs=$(abspath ./bin/protogen) \
|
|
|
|
--go-frostfs_out=fuzz=true:. \
|
|
|
|
--go-frostfs_opt=paths=source_relative \
|
|
|
|
--go-grpc_opt=require_unimplemented_servers=false \
|
|
|
|
--go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \
|
|
|
|
done
|
|
|
|
|
|
|
|
$(BIN)/protogen:
|
|
|
|
@go build -v -trimpath \
|
|
|
|
-o $(BIN)/protogen \
|
|
|
|
./api/util/protogen
|
|
|
|
|
|
|
|
protoc-test: protoc $(BIN)/protogen
|
|
|
|
@$(PROTOC_DIR)/bin/protoc \
|
|
|
|
--go_out=. --go_opt=paths=source_relative \
|
|
|
|
--plugin=protoc-gen-go-frostfs=$(abspath $(BIN)/protogen) \
|
|
|
|
--go-frostfs_opt=Mapi/util/proto/test/test.proto=git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/util/proto/test/custom \
|
|
|
|
--go-frostfs_opt=module=git.frostfs.info/TrueCloudLab/frostfs-sdk-go \
|
|
|
|
--go-frostfs_out=. --go-frostfs_opt=paths=import \
|
|
|
|
./api/util/proto/test/test.proto
|
|
|
|
|
2021-05-20 20:57:51 +00:00
|
|
|
# Pull go dependencies
|
|
|
|
dep:
|
|
|
|
@printf "⇒ Download requirements: "
|
|
|
|
@CGO_ENABLED=0 \
|
|
|
|
go mod download && echo OK
|
|
|
|
@printf "⇒ Tidy requirements: "
|
|
|
|
@CGO_ENABLED=0 \
|
|
|
|
go mod tidy -v && echo OK
|
|
|
|
|
2023-10-23 15:05:03 +00:00
|
|
|
# Install linters
|
|
|
|
lint-install:
|
|
|
|
@mkdir -p $(TMP_DIR)
|
|
|
|
@rm -rf $(TMP_DIR)/linters
|
|
|
|
@git -c advice.detachedHead=false clone --branch v$(TRUECLOUDLAB_LINT_VERSION) https://git.frostfs.info/TrueCloudLab/linters.git $(TMP_DIR)/linters
|
|
|
|
@@make -C $(TMP_DIR)/linters lib CGO_ENABLED=1 OUT_DIR=$(OUTPUT_LINT_DIR)
|
|
|
|
@rm -rf $(TMP_DIR)/linters
|
|
|
|
@rmdir $(TMP_DIR) 2>/dev/null || true
|
|
|
|
@CGO_ENABLED=1 GOBIN=$(LINT_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION)
|
|
|
|
|
2021-05-20 20:57:51 +00:00
|
|
|
# Run linters
|
|
|
|
lint:
|
2023-10-23 15:05:03 +00:00
|
|
|
@if [ ! -d "$(LINT_DIR)" ]; then \
|
|
|
|
echo "Run make lint-install"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
$(LINT_DIR)/golangci-lint run
|
2021-05-20 20:57:51 +00:00
|
|
|
|
|
|
|
# Run tests with race detection and produce coverage output
|
|
|
|
cover:
|
|
|
|
@go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic
|
|
|
|
@go tool cover -html=coverage.txt -o coverage.html
|
|
|
|
|
|
|
|
# Reformat code
|
|
|
|
format:
|
|
|
|
@echo "⇒ Processing gofmt check"
|
|
|
|
@gofmt -s -w ./
|
|
|
|
@echo "⇒ Processing goimports check"
|
|
|
|
@goimports -w ./
|
|
|
|
|
2023-05-30 12:48:19 +00:00
|
|
|
policy:
|
|
|
|
@wget -q https://www.antlr.org/download/antlr-${ANTLR_VERSION}-complete.jar -O antlr4-tool.jar
|
2024-09-17 07:11:12 +00:00
|
|
|
@java -Xmx500M -cp antlr4-tool.jar org.antlr.v4.Tool -Dlanguage=Go \
|
|
|
|
-no-listener -visitor netmap/parser/Query.g4 netmap/parser/QueryLexer.g4
|
2023-05-30 12:48:19 +00:00
|
|
|
|
|
|
|
# Run `make %` in truecloudlab/frostfs-sdk-go container(Golang+Java)
|
|
|
|
docker/%:
|
|
|
|
@docker build -t truecloudlab/frostfs-sdk-go --platform linux/amd64 . > /dev/null
|
|
|
|
@docker run --rm -t \
|
|
|
|
-v `pwd`:/work \
|
|
|
|
-u "$$(id -u):$$(id -g)" \
|
|
|
|
--env HOME=/work \
|
|
|
|
truecloudlab/frostfs-sdk-go make $*
|
|
|
|
|
2023-06-06 06:27:28 +00:00
|
|
|
# Synchronize tree service
|
|
|
|
sync-tree:
|
|
|
|
@./syncTree.sh
|
|
|
|
|
2021-05-20 20:57:51 +00:00
|
|
|
# Show this help prompt
|
|
|
|
help:
|
|
|
|
@echo ' Usage:'
|
|
|
|
@echo ''
|
|
|
|
@echo ' make <target>'
|
|
|
|
@echo ''
|
|
|
|
@echo ' Targets:'
|
|
|
|
@echo ''
|
2023-03-03 09:29:33 +00:00
|
|
|
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort -u
|
2024-09-09 08:37:15 +00:00
|
|
|
|
|
|
|
# Activate pre-commit hooks
|
|
|
|
pre-commit:
|
|
|
|
pre-commit install --hook-type pre-commit
|
|
|
|
|
|
|
|
# Deactivate pre-commit hooks
|
|
|
|
unpre-commit:
|
|
|
|
pre-commit uninstall --hook-type pre-commit
|
|
|
|
|
|
|
|
# Run pre-commit hooks
|
|
|
|
pre-commit-run:
|
|
|
|
@pre-commit run --all-files --hook-stage manual
|