2020-09-18 08:25:11 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
SHELL = bash
|
|
|
|
|
2022-09-06 07:50:50 +00:00
|
|
|
VERSION ?= $(shell git describe --tags --match "v*" --abbrev=8 --dirty --always)
|
2024-06-24 09:58:37 +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)
|
2020-09-21 18:17:49 +00:00
|
|
|
|
2024-08-16 14:11:08 +00:00
|
|
|
.PHONY: dep fmts fumpt imports protoc test lint version help $(BIN)/protogen protoc-test
|
2020-09-18 08:25:11 +00:00
|
|
|
|
|
|
|
# Pull go dependencies
|
|
|
|
dep:
|
|
|
|
@printf "⇒ Tidy requirements : "
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
go mod tidy -v && echo OK
|
|
|
|
@printf "⇒ Download requirements: "
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
go mod download && echo OK
|
|
|
|
@printf "⇒ Install test requirements: "
|
|
|
|
CGO_ENABLED=0 \
|
2021-12-02 13:15:44 +00:00
|
|
|
go test ./... && echo OK
|
2020-09-18 08:25:11 +00:00
|
|
|
|
2020-12-30 09:32:29 +00:00
|
|
|
# Run all code formatters
|
2024-03-14 07:31:18 +00:00
|
|
|
fmts: fumpt imports
|
2019-11-20 13:40:06 +00:00
|
|
|
|
2020-09-18 08:25:11 +00:00
|
|
|
# Reformat imports
|
|
|
|
imports:
|
|
|
|
@echo "⇒ Processing goimports check"
|
2024-08-08 14:31:58 +00:00
|
|
|
@for f in `find . -type f -name '*.go' -not -name '*.pb.go' -prune`; do \
|
2024-03-14 07:25:23 +00:00
|
|
|
goimports -w $$f; \
|
2019-11-20 13:40:06 +00:00
|
|
|
done
|
|
|
|
|
2024-03-14 07:31:18 +00:00
|
|
|
# Run gofumpt
|
|
|
|
fumpt:
|
|
|
|
@echo "⇒ Processing gofumpt check"
|
|
|
|
@gofumpt -l -w .
|
|
|
|
|
2024-06-24 09:58:37 +00:00
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
2020-09-21 18:17:49 +00:00
|
|
|
# Regenerate code for proto files
|
2020-08-12 09:49:11 +00:00
|
|
|
protoc:
|
2024-06-24 09:58:37 +00:00
|
|
|
@if [ ! -d "$(PROTOC_DIR)" ] || [ ! -d "$(PROTOC_GEN_GO_DIR)" ]; then \
|
|
|
|
make protoc-install; \
|
|
|
|
fi
|
2020-09-18 08:25:11 +00:00
|
|
|
# Protoc generate
|
2024-04-25 12:13:10 +00:00
|
|
|
@for f in `find . -type f -name '*.proto' -not -path './bin/*' -not -path './util/proto/test/*'`; do \
|
2020-09-18 08:25:11 +00:00
|
|
|
echo "⇒ Processing $$f "; \
|
2024-06-24 09:58:37 +00:00
|
|
|
$(PROTOC_DIR)/bin/protoc \
|
2024-08-08 15:02:30 +00:00
|
|
|
--proto_path=.:$(PROTOC_DIR)/include:/usr/local/include \
|
2024-04-25 12:13:10 +00:00
|
|
|
--plugin=protoc-gen-go-frostfs=$(abspath ./bin/protogen) \
|
|
|
|
--go-frostfs_out=fuzz=true:. \
|
|
|
|
--go-frostfs_opt=paths=source_relative \
|
2021-09-28 15:10:48 +00:00
|
|
|
--go-grpc_opt=require_unimplemented_servers=false \
|
|
|
|
--go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \
|
2019-11-20 13:40:06 +00:00
|
|
|
done
|
2020-09-21 18:17:49 +00:00
|
|
|
|
2024-08-16 14:11:08 +00:00
|
|
|
$(BIN)/protogen:
|
2024-08-09 07:44:14 +00:00
|
|
|
@go build -v -trimpath \
|
|
|
|
-o $(BIN)/protogen \
|
|
|
|
./util/protogen
|
|
|
|
|
2024-08-16 14:11:08 +00:00
|
|
|
protoc-test: protoc $(BIN)/protogen
|
2024-08-09 07:44:14 +00:00
|
|
|
@$(PROTOC_DIR)/bin/protoc \
|
2024-08-26 11:15:00 +00:00
|
|
|
--go_out=. --go_opt=paths=source_relative \
|
2024-08-09 07:44:14 +00:00
|
|
|
--plugin=protoc-gen-go-frostfs=$(abspath $(BIN)/protogen) \
|
2024-04-25 12:13:10 +00:00
|
|
|
--go-frostfs_opt=Mutil/proto/test/test.proto=git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/test/custom \
|
|
|
|
--go-frostfs_opt=module=git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 \
|
|
|
|
--go-frostfs_out=. --go-frostfs_opt=paths=import \
|
2024-08-09 07:44:14 +00:00
|
|
|
./util/proto/test/test.proto
|
|
|
|
|
2020-09-21 18:17:49 +00:00
|
|
|
# Run Unit Test with go test
|
2024-03-14 07:24:04 +00:00
|
|
|
test: GOFLAGS ?= "-count=1"
|
2020-09-21 18:17:49 +00:00
|
|
|
test:
|
2020-12-30 09:32:29 +00:00
|
|
|
@echo "⇒ Running go test"
|
2024-03-14 07:24:04 +00:00
|
|
|
@GOFLAGS="$(GOFLAGS)" go test ./...
|
2020-09-21 18:17:49 +00:00
|
|
|
|
|
|
|
# Run linters
|
|
|
|
lint:
|
|
|
|
@golangci-lint run
|
|
|
|
|
|
|
|
# Print version
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
|
|
|
# Show this help prompt
|
|
|
|
help:
|
|
|
|
@echo ' Usage:'
|
|
|
|
@echo ''
|
|
|
|
@echo ' make <target>'
|
|
|
|
@echo ''
|
|
|
|
@echo ' Targets:'
|
|
|
|
@echo ''
|
|
|
|
@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
|