2020-03-25 23:47:17 +02:00
|
|
|
# Copyright The OpenTelemetry Authors
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2020-09-09 18:14:03 +02:00
|
|
|
TOOLS_MOD_DIR := ./internal/tools
|
2019-09-19 18:16:09 +02:00
|
|
|
|
2019-08-02 19:44:32 +02:00
|
|
|
ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
|
2022-02-16 00:03:38 +02:00
|
|
|
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
|
|
|
|
OTEL_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR), $(ALL_GO_MOD_DIRS))
|
2020-02-06 20:51:00 +02:00
|
|
|
ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./example|^$(TOOLS_MOD_DIR)' | sort)
|
2019-08-02 19:44:32 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
GO = go
|
|
|
|
TIMEOUT = 60
|
2019-07-03 01:21:24 +02:00
|
|
|
|
|
|
|
.DEFAULT_GOAL := precommit
|
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
.PHONY: precommit ci
|
2022-02-17 17:45:10 +02:00
|
|
|
precommit: dependabot-generate license-check misspell go-mod-tidy golangci-lint-fix test-default
|
2022-02-16 00:03:38 +02:00
|
|
|
ci: dependabot-check license-check lint vanity-import-check build test-default check-clean-work-tree test-coverage
|
2019-06-19 02:09:49 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
# Tools
|
2019-06-19 02:09:49 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
TOOLS = $(CURDIR)/.tools
|
2019-06-19 02:09:49 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
$(TOOLS):
|
|
|
|
@mkdir -p $@
|
|
|
|
$(TOOLS)/%: | $(TOOLS)
|
2020-02-06 20:51:00 +02:00
|
|
|
cd $(TOOLS_MOD_DIR) && \
|
2021-03-01 18:38:23 +02:00
|
|
|
$(GO) build -o $@ $(PACKAGE)
|
2019-08-02 19:44:32 +02:00
|
|
|
|
2021-10-01 22:20:32 +02:00
|
|
|
MULTIMOD = $(TOOLS)/multimod
|
|
|
|
$(TOOLS)/multimod: PACKAGE=go.opentelemetry.io/build-tools/multimod
|
|
|
|
|
2021-08-02 20:39:18 +02:00
|
|
|
SEMCONVGEN = $(TOOLS)/semconvgen
|
|
|
|
$(TOOLS)/semconvgen: PACKAGE=go.opentelemetry.io/build-tools/semconvgen
|
2021-05-13 01:10:56 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
CROSSLINK = $(TOOLS)/crosslink
|
|
|
|
$(TOOLS)/crosslink: PACKAGE=go.opentelemetry.io/otel/$(TOOLS_MOD_DIR)/crosslink
|
2019-08-22 20:16:51 +02:00
|
|
|
|
2022-02-17 17:45:10 +02:00
|
|
|
DBOTCONF = $(TOOLS)/dbotconf
|
|
|
|
$(TOOLS)/dbotconf: PACKAGE=go.opentelemetry.io/otel/$(TOOLS_MOD_DIR)/dbotconf
|
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
GOLANGCI_LINT = $(TOOLS)/golangci-lint
|
|
|
|
$(TOOLS)/golangci-lint: PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint
|
2020-03-30 22:10:18 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
MISSPELL = $(TOOLS)/misspell
|
2021-09-28 04:37:26 +02:00
|
|
|
$(TOOLS)/misspell: PACKAGE=github.com/client9/misspell/cmd/misspell
|
2019-07-03 01:21:24 +02:00
|
|
|
|
2021-08-14 17:10:15 +02:00
|
|
|
GOCOVMERGE = $(TOOLS)/gocovmerge
|
2021-09-28 04:37:26 +02:00
|
|
|
$(TOOLS)/gocovmerge: PACKAGE=github.com/wadey/gocovmerge
|
2021-08-14 17:10:15 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
STRINGER = $(TOOLS)/stringer
|
|
|
|
$(TOOLS)/stringer: PACKAGE=golang.org/x/tools/cmd/stringer
|
2020-08-24 18:43:29 +02:00
|
|
|
|
2021-09-28 04:37:26 +02:00
|
|
|
PORTO = $(TOOLS)/porto
|
|
|
|
$(TOOLS)/porto: PACKAGE=github.com/jcchavezs/porto/cmd/porto
|
|
|
|
|
2021-10-01 22:20:32 +02:00
|
|
|
GOJQ = $(TOOLS)/gojq
|
2021-03-01 18:38:23 +02:00
|
|
|
$(TOOLS)/gojq: PACKAGE=github.com/itchyny/gojq/cmd/gojq
|
2019-07-03 01:21:24 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
.PHONY: tools
|
2022-02-17 17:45:10 +02:00
|
|
|
tools: $(CROSSLINK) $(DBOTCONF) $(GOLANGCI_LINT) $(MISSPELL) $(GOCOVMERGE) $(STRINGER) $(PORTO) $(GOJQ) $(SEMCONVGEN) $(MULTIMOD)
|
2019-07-03 01:21:24 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
# Build
|
|
|
|
|
2022-02-16 00:03:38 +02:00
|
|
|
.PHONY: generate build
|
|
|
|
|
|
|
|
generate: $(OTEL_GO_MOD_DIRS:%=generate/%)
|
|
|
|
generate/%: DIR=$*
|
|
|
|
generate/%: | $(STRINGER) $(PORTO)
|
|
|
|
@echo "$(GO) generate $(DIR)/..." \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& PATH="$(TOOLS):$${PATH}" $(GO) generate ./... && $(PORTO) -w .
|
|
|
|
|
|
|
|
build: generate $(OTEL_GO_MOD_DIRS:%=build/%) $(OTEL_GO_MOD_DIRS:%=build-tests/%)
|
|
|
|
build/%: DIR=$*
|
|
|
|
build/%:
|
|
|
|
@echo "$(GO) build $(DIR)/..." \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GO) build ./...
|
|
|
|
|
|
|
|
build-tests/%: DIR=$*
|
|
|
|
build-tests/%:
|
|
|
|
@echo "$(GO) build tests $(DIR)/..." \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GO) list ./... \
|
|
|
|
| grep -v third_party \
|
|
|
|
| xargs $(GO) test -vet=off -run xxxxxMatchNothingxxxxx >/dev/null
|
2019-11-22 20:48:53 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
# Tests
|
2019-07-03 01:21:24 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
TEST_TARGETS := test-default test-bench test-short test-verbose test-race
|
|
|
|
.PHONY: $(TEST_TARGETS) test
|
2022-02-16 00:03:38 +02:00
|
|
|
test-default test-race: ARGS=-race
|
2021-03-01 18:38:23 +02:00
|
|
|
test-bench: ARGS=-run=xxxxxMatchNothingxxxxx -test.benchtime=1ms -bench=.
|
|
|
|
test-short: ARGS=-short
|
2022-02-16 00:03:38 +02:00
|
|
|
test-verbose: ARGS=-v -race
|
2021-03-01 18:38:23 +02:00
|
|
|
$(TEST_TARGETS): test
|
2022-02-16 00:03:38 +02:00
|
|
|
test: $(OTEL_GO_MOD_DIRS:%=test/%)
|
|
|
|
test/%: DIR=$*
|
|
|
|
test/%:
|
|
|
|
@echo "$(GO) test -timeout $(TIMEOUT)s $(ARGS) $(DIR)/..." \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GO) list ./... \
|
|
|
|
| grep -v third_party \
|
|
|
|
| xargs $(GO) test -timeout $(TIMEOUT)s $(ARGS)
|
2020-09-25 22:27:03 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
COVERAGE_MODE = atomic
|
|
|
|
COVERAGE_PROFILE = coverage.out
|
|
|
|
.PHONY: test-coverage
|
2021-08-14 17:10:15 +02:00
|
|
|
test-coverage: | $(GOCOVMERGE)
|
2021-03-01 18:38:23 +02:00
|
|
|
@set -e; \
|
|
|
|
printf "" > coverage.txt; \
|
|
|
|
for dir in $(ALL_COVERAGE_MOD_DIRS); do \
|
2021-08-14 17:10:15 +02:00
|
|
|
echo "$(GO) test -coverpkg=go.opentelemetry.io/otel/... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_PROFILE)" $${dir}/..."; \
|
2021-03-01 18:38:23 +02:00
|
|
|
(cd "$${dir}" && \
|
2021-03-03 20:24:57 +02:00
|
|
|
$(GO) list ./... \
|
|
|
|
| grep -v third_party \
|
|
|
|
| xargs $(GO) test -coverpkg=./... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_PROFILE)" && \
|
|
|
|
$(GO) tool cover -html=coverage.out -o coverage.html); \
|
2021-03-01 18:38:23 +02:00
|
|
|
done; \
|
2021-08-14 17:10:15 +02:00
|
|
|
$(GOCOVMERGE) $$(find . -name coverage.out) > coverage.txt
|
2021-03-01 18:38:23 +02:00
|
|
|
|
2022-02-16 00:03:38 +02:00
|
|
|
.PHONY: golangci-lint golangci-lint-fix
|
|
|
|
golangci-lint-fix: ARGS=--fix
|
|
|
|
golangci-lint-fix: golangci-lint
|
|
|
|
golangci-lint: $(OTEL_GO_MOD_DIRS:%=golangci-lint/%)
|
|
|
|
golangci-lint/%: DIR=$*
|
|
|
|
golangci-lint/%: | $(GOLANGCI_LINT)
|
|
|
|
@echo 'golangci-lint $(if $(ARGS),$(ARGS) ,)$(DIR)' \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GOLANGCI_LINT) run --allow-serial-runners $(ARGS)
|
|
|
|
|
|
|
|
.PHONY: crosslink
|
|
|
|
crosslink: | $(CROSSLINK)
|
|
|
|
@echo "cross-linking all go modules" \
|
|
|
|
&& $(CROSSLINK)
|
|
|
|
|
|
|
|
.PHONY: go-mod-tidy
|
|
|
|
go-mod-tidy: $(ALL_GO_MOD_DIRS:%=go-mod-tidy/%)
|
|
|
|
go-mod-tidy/%: DIR=$*
|
|
|
|
go-mod-tidy/%: | crosslink
|
|
|
|
@echo "$(GO) mod tidy in $(DIR)" \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GO) mod tidy
|
|
|
|
|
|
|
|
.PHONY: lint-modules
|
|
|
|
lint-modules: go-mod-tidy
|
|
|
|
|
2019-11-27 21:27:41 +02:00
|
|
|
.PHONY: lint
|
2022-02-16 00:03:38 +02:00
|
|
|
lint: misspell lint-modules golangci-lint
|
2021-03-01 18:38:23 +02:00
|
|
|
|
2021-09-28 04:37:26 +02:00
|
|
|
.PHONY: vanity-import-check
|
|
|
|
vanity-import-check: | $(PORTO)
|
2022-02-16 00:03:38 +02:00
|
|
|
@$(PORTO) --include-internal -l .
|
2021-09-28 04:37:26 +02:00
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
.PHONY: misspell
|
|
|
|
misspell: | $(MISSPELL)
|
2022-02-16 00:03:38 +02:00
|
|
|
@$(MISSPELL) -w $(ALL_DOCS)
|
2020-03-25 23:47:17 +02:00
|
|
|
|
|
|
|
.PHONY: license-check
|
|
|
|
license-check:
|
2021-06-11 17:18:17 +02:00
|
|
|
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path '**/third_party/*') ; do \
|
2020-03-25 23:47:17 +02:00
|
|
|
awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=3 { found=1; next } END { if (!found) print FILENAME }' $$f; \
|
|
|
|
done); \
|
|
|
|
if [ -n "$${licRes}" ]; then \
|
|
|
|
echo "license header checking failed:"; echo "$${licRes}"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
2020-08-27 01:34:41 +02:00
|
|
|
|
2022-02-16 00:03:38 +02:00
|
|
|
DEPENDABOT_PATH=./.github/dependabot.yml
|
2020-08-27 01:34:41 +02:00
|
|
|
.PHONY: dependabot-check
|
|
|
|
dependabot-check:
|
|
|
|
@result=$$( \
|
2021-06-16 17:32:42 +02:00
|
|
|
for f in $$( find . -type f -name go.mod -exec dirname {} \; | sed 's/^.//' ); \
|
2022-02-16 00:03:38 +02:00
|
|
|
do grep -q "directory: \+$$f" $(DEPENDABOT_PATH) \
|
2020-08-27 01:34:41 +02:00
|
|
|
|| echo "$$f"; \
|
|
|
|
done; \
|
|
|
|
); \
|
|
|
|
if [ -n "$$result" ]; then \
|
2022-02-16 00:03:38 +02:00
|
|
|
echo "missing dependabot entry:"; echo "$$result"; \
|
|
|
|
echo "new modules need to be added to the $(DEPENDABOT_PATH) file"; \
|
2022-02-17 17:45:10 +02:00
|
|
|
echo "(run: make dependabot-generate)"; \
|
2020-08-27 01:34:41 +02:00
|
|
|
exit 1; \
|
|
|
|
fi
|
2021-03-01 18:38:23 +02:00
|
|
|
|
2022-02-17 17:45:10 +02:00
|
|
|
.PHONY: dependabot-generate
|
|
|
|
dependabot-generate: $(DBOTCONF)
|
|
|
|
@echo "gerating dependabot configuration"; \
|
|
|
|
$(DBOTCONF)
|
|
|
|
|
2021-03-01 18:38:23 +02:00
|
|
|
.PHONY: check-clean-work-tree
|
|
|
|
check-clean-work-tree:
|
|
|
|
@if ! git diff --quiet; then \
|
|
|
|
echo; \
|
|
|
|
echo 'Working tree is not clean, did you forget to run "make precommit"?'; \
|
|
|
|
echo; \
|
|
|
|
git status; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
2021-10-01 22:20:32 +02:00
|
|
|
|
|
|
|
.PHONY: prerelease
|
|
|
|
prerelease: | $(MULTIMOD)
|
|
|
|
@[ "${MODSET}" ] || ( echo ">> env var MODSET is not set"; exit 1 )
|
|
|
|
$(MULTIMOD) verify && $(MULTIMOD) prerelease -m ${MODSET}
|
|
|
|
|
|
|
|
COMMIT ?= "HEAD"
|
|
|
|
.PHONY: add-tags
|
|
|
|
add-tags: | $(MULTIMOD)
|
|
|
|
@[ "${MODSET}" ] || ( echo ">> env var MODSET is not set"; exit 1 )
|
|
|
|
$(MULTIMOD) verify && $(MULTIMOD) tag -m ${MODSET} -c ${COMMIT}
|