SHELL = /bin/bash # ALL_PKGS is the list of all packages where ALL_SRC files reside. ALL_PKGS := $(sort $(shell go list ./...)) # COVER_PKGS is the list of packages to include in the coverage COVER_PKGS := $(shell go list ./... | tr "\n" ",") CURR_MOD := $(shell go list -m | tr '/' '-' ) GOTEST_TIMEOUT?=240s GOTEST_OPT?= -race -timeout $(GOTEST_TIMEOUT) GOCMD?= go GOOS := $(shell $(GOCMD) env GOOS) GOARCH := $(shell $(GOCMD) env GOARCH) # SRC_ROOT is the top of the source tree. SRC_ROOT := $(shell git rev-parse --show-toplevel) TOOLS_MOD_DIR := $(SRC_ROOT)/internal/tools TOOLS_BIN_DIR := $(SRC_ROOT)/.tools TOOLS_MOD_REGEX := "\s+_\s+\".*\"" TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"" | grep -vE '/v[0-9]+$$') TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(shell echo $(TOOLS_PKG_NAMES)))) CHLOGGEN_CONFIG := .chloggen/config.yaml # no trailing slash JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults ACTIONLINT := $(TOOLS_BIN_DIR)/actionlint ADDLICENSE := $(TOOLS_BIN_DIR)/addlicense APIDIFF := $(TOOLS_BIN_DIR)/apidiff CHECKAPI := $(TOOLS_BIN_DIR)/checkapi CHECKFILE := $(TOOLS_BIN_DIR)/checkfile CHLOGGEN := $(TOOLS_BIN_DIR)/chloggen CROSSLINK := $(TOOLS_BIN_DIR)/crosslink ENVSUBST := $(TOOLS_BIN_DIR)/envsubst GITHUBGEN := $(TOOLS_BIN_DIR)/githubgen GOFUMPT := $(TOOLS_BIN_DIR)/gofumpt GOIMPORTS := $(TOOLS_BIN_DIR)/goimports GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck LINT := $(TOOLS_BIN_DIR)/golangci-lint PDATAGEN := $(TOOLS_BIN_DIR)/pdatagen IMPI := $(TOOLS_BIN_DIR)/impi MISSPELL := $(TOOLS_BIN_DIR)/misspell MULTIMOD := $(TOOLS_BIN_DIR)/multimod PORTO := $(TOOLS_BIN_DIR)/porto GOTESTSUM := $(TOOLS_BIN_DIR)/gotestsum .PHONY: install-tools install-tools: $(TOOLS_BIN_NAMES) $(TOOLS_BIN_DIR): mkdir -p $@ $(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod cd $(TOOLS_MOD_DIR) && $(GOCMD) build -o $@ -trimpath $(filter %/$(notdir $@),$(TOOLS_PKG_NAMES)) .PHONY: test test: $(GOTESTSUM) $(GOTESTSUM) --packages="./..." -- $(GOTEST_OPT) .PHONY: test-with-cover test-with-cover: $(GOTESTSUM) mkdir -p $(PWD)/coverage/unit $(GOTESTSUM) --packages="./..." -- $(GOTEST_OPT) -cover -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(PWD)/coverage/unit" .PHONY: test-with-junit test-with-junit: $(GOTESTSUM) mkdir -p $(JUNIT_OUT_DIR) $(GOTESTSUM) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT) ./... .PHONY: benchmark benchmark: $(GOTESTSUM) $(GOTESTSUM) --packages="$(ALL_PKGS)" -- -bench=. -run=notests ./... | tee benchmark.txt .PHONY: fmt fmt: common/gofmt common/goimports common/gofumpt .PHONY: tidy tidy: rm -fr go.sum $(GOCMD) mod tidy -compat=1.23.0 .PHONY: lint lint: $(LINT) $(LINT) run .PHONY: common/gofmt common/gofmt: gofmt -w -s ./ .PHONY: common/goimports common/goimports: $(GOIMPORTS) $(GOIMPORTS) -w -local go.opentelemetry.io/collector ./ .PHONY: common/gofumpt common/gofumpt: $(GOFUMPT) $(GOFUMPT) -l -w -extra . .PHONY: govulncheck govulncheck: $(GOVULNCHECK) $(GOVULNCHECK) ./... .PHONY: generate generate: $(GOCMD) generate ./... .PHONY: impi impi: $(IMPI) @$(IMPI) --local go.opentelemetry.io/collector --scheme stdThirdPartyLocal ./... .PHONY: moddownload moddownload: $(GOCMD) mod download