Alexander Chuprov
4f046bcfbc
Some checks failed
Tests and linters / Tests with -race (pull_request) Successful in 2m7s
Tests and linters / Tests (pull_request) Successful in 2m18s
DCO action / DCO (pull_request) Successful in 2m26s
Tests and linters / Lint (pull_request) Successful in 2m52s
Tests and linters / Check clang-format (pull_request) Failing after 8m15s
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
131 lines
3.6 KiB
Makefile
131 lines
3.6 KiB
Makefile
#!/usr/bin/make -f
|
|
|
|
# Common variables
|
|
REPO ?= $(shell go list -m)
|
|
VERSION ?= $(shell git describe --tags --dirty --match "v*" --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")
|
|
GO_VERSION ?= 1.22
|
|
LINT_VERSION ?= 1.60.3
|
|
LLVM_VERSION ?= 19.1.3
|
|
TRUECLOUDLAB_LINT_VERSION ?= 0.0.7
|
|
BINDIR = bin
|
|
|
|
OUTPUT_LINT_DIR ?= $(abspath $(BINDIR))/linters
|
|
LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION)
|
|
TMP_DIR := .cache
|
|
|
|
# Binaries to build
|
|
CMDS = $(addprefix frostfs-, $(notdir $(wildcard cmd/*)))
|
|
BINS = $(addprefix $(BINDIR)/, $(CMDS))
|
|
|
|
.PHONY: all $(BINS) $(BINDIR) dep docker/ test cover format lint docker/lint pre-commit unpre-commit version clean
|
|
|
|
# Make all binaries
|
|
all: $(BINS)
|
|
|
|
$(BINS): $(BINDIR) dep
|
|
@echo "⇒ Build $@"
|
|
CGO_ENABLED=0 \
|
|
go build -v -trimpath \
|
|
-ldflags "-X $(REPO)/internal/version.Version=$(VERSION)" \
|
|
-o $@ ./cmd/$(subst frostfs-,,$(notdir $@))
|
|
|
|
$(BINDIR):
|
|
@echo "⇒ Ensure dir: $@"
|
|
@mkdir -p $@
|
|
|
|
# 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
|
|
|
|
# Run `make %` in Golang container, for more information run `make help.docker/%`
|
|
docker/%:
|
|
$(if $(filter $*,all $(BINS)), \
|
|
@echo "=> Running 'make $*' in clean Docker environment" && \
|
|
docker run --rm -t \
|
|
-v `pwd`:/src \
|
|
-w /src \
|
|
-u `stat -c "%u:%g" .` \
|
|
--env HOME=/src \
|
|
golang:$(GO_VERSION) make $*,\
|
|
@echo "supported docker targets: all $(BINS) lint")
|
|
|
|
# Run tests
|
|
test:
|
|
@go test ./... -cover
|
|
|
|
# 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 ./
|
|
|
|
# Run linters
|
|
lint:
|
|
@if [ ! -d "$(LINT_DIR)" ]; then \
|
|
make lint-install; \
|
|
fi
|
|
$(LINT_DIR)/golangci-lint run --timeout=5m
|
|
|
|
clang:
|
|
@if [ ! -d "$(OUTPUT_LINT_DIR)/clang" ]; then \
|
|
make clang-install; \
|
|
fi
|
|
@$(OUTPUT_LINT_DIR)/clang/clang-format -i **/*.js
|
|
|
|
clang-install:
|
|
@mkdir -p $(TMP_DIR)/llvm
|
|
@curl -L -o $(TMP_DIR)/llvm/llv-$(LLVM_VERSION)-linux-x64.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-$(LLVM_VERSION)/LLVM-$(LLVM_VERSION)-Linux-X64.tar.xz
|
|
@mkdir -p $(OUTPUT_LINT_DIR)/clang
|
|
@tar -xJf $(TMP_DIR)/llvm/llv-$(LLVM_VERSION)-linux-x64.tar.xz --strip-components=2 -C $(OUTPUT_LINT_DIR)/clang LLVM-$(LLVM_VERSION)-Linux-X64/bin/clang-format
|
|
@rm -r $(TMP_DIR) 2>/dev/null || true
|
|
|
|
llvm-version:
|
|
@echo $(LLVM_VERSION)
|
|
|
|
# Install linters
|
|
lint-install:
|
|
@rm -rf $(OUTPUT_LINT_DIR)
|
|
@mkdir -p $(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 in Docker
|
|
docker/lint:
|
|
docker run --rm -it \
|
|
-v `pwd`:/src \
|
|
-u `stat -c "%u:%g" .` \
|
|
--env HOME=/src \
|
|
golangci/golangci-lint:v$(LINT_VERSION) bash -c 'cd /src/ && make lint'
|
|
|
|
# Activate pre-commit hooks
|
|
pre-commit:
|
|
pre-commit install -t pre-commit -t commit-msg
|
|
|
|
# Deactivate pre-commit hooks
|
|
unpre-commit:
|
|
pre-commit uninstall -t pre-commit -t commit-msg
|
|
|
|
# Show current version
|
|
version:
|
|
@echo $(VERSION)
|
|
|
|
# Clean up files
|
|
clean:
|
|
rm -rf .cache
|
|
rm -rf $(BINDIR)
|
|
|
|
include help.mk
|