#!/usr/bin/make -f SHELL = bash VERSION ?= $(shell git describe --tags --match "v*" --abbrev=8 --dirty --always) 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 LINT_VERSION ?= 1.60.3 TRUECLOUDLAB_LINT_VERSION ?= 0.0.7 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) OUTPUT_LINT_DIR ?= $(abspath $(BIN))/linters LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION) TMP_DIR := .cache .PHONY: dep fmts fumpt imports protoc test version help $(BIN)/protogen protoc-test # 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 \ go test ./... && echo OK # Run all code formatters fmts: fumpt imports # 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 # Run gofumpt fumpt: @echo "⇒ Processing gofumpt check" @gofumpt -l -w . # 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 './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 \ ./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=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 \ ./util/proto/test/test.proto # Run Unit Test with go test test: GOFLAGS ?= "-count=1" test: @echo "⇒ Running go test" @GOFLAGS="$(GOFLAGS)" go test ./... .PHONY: lint-install lint # Install linters lint-install: @rm -rf $(OUTPUT_LINT_DIR) @mkdir $(OUTPUT_LINT_DIR) @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 -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION) # Run linters lint: @if [ ! -d "$(LINT_DIR)" ]; then \ make lint-install; \ fi $(LINT_DIR)/golangci-lint run .PHONY: pre-commit unpre-commit pre-commit-run # 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 # Print version version: @echo $(VERSION) # Show this help prompt help: @echo ' Usage:' @echo '' @echo ' make ' @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