# ALL_PKGS is the list of all packages where ALL_SRC files reside.
ALL_PKGS := $(sort $(shell go list ./...))

# Use a single process (-p 1) on go test to avoid tests clashing on machine
# wide resources, e.g. ports.
GOTEST_OPT?= -v -p 1 -race -timeout 60s
GOCMD?= go
GOTEST=$(GOCMD) test
GO_ACC=go-acc
LINT=golangci-lint
IMPI=impi

.PHONY: test
test:
	$(GOTEST) $(GOTEST_OPT) ./...

.PHONY: test-unstable
test-unstable:
	$(GOTEST) $(GOTEST_OPT) -tags enable_unstable ./...

.PHONY: test-with-cover
test-with-cover:
	$(GO_ACC) --output=coverage.out ./...

.PHONY: benchmark
benchmark:
	$(GOTEST) -bench=. -run=notests ./...

.PHONY: fmt
fmt:
	gofmt -w -s ./
	goimports -w  -local go.opentelemetry.io/collector ./

.PHONY: tidy
tidy:
	rm -fr go.sum
	$(GOCMD) mod tidy -compat=1.17

.PHONY: lint
lint:
	$(LINT) run --allow-parallel-runners

.PHONY: lint-unstable
lint-unstable:
	$(LINT) run --allow-parallel-runners --build-tags enable_unstable

.PHONY: generate
generate:
	$(GOCMD) generate ./...

.PHONY: impi
impi:
	@$(IMPI) --local go.opentelemetry.io/collector --scheme stdThirdPartyLocal ./...

.PHONY: moddownload
moddownload:
	$(GOCMD) mod download
