Elia Battiston | c8d0d46 | 2022-02-22 16:30:51 +0100 | [diff] [blame] | 1 | PROJECT_ROOT=github.com/uber/jaeger-client-go |
| 2 | export GO111MODULE=off |
| 3 | PACKAGES := . $(shell GO111MODULE=off go list ./... | awk -F/ 'NR>1 {print "./"$$4"/..."}' | grep -v -e ./thrift-gen/... -e ./thrift/... | sort -u) |
| 4 | # all .go files that don't exist in hidden directories |
| 5 | ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor -e thrift-gen -e ./thrift/ \ |
| 6 | -e ".*/\..*" \ |
| 7 | -e ".*/_.*" \ |
| 8 | -e ".*/mocks.*") |
| 9 | |
| 10 | USE_DEP := true |
| 11 | |
| 12 | -include crossdock/rules.mk |
| 13 | |
| 14 | RACE=-race |
| 15 | GOTEST=go test -v $(RACE) |
| 16 | GOLINT=golint |
| 17 | GOVET=go vet |
| 18 | GOFMT=gofmt |
| 19 | FMT_LOG=fmt.log |
| 20 | LINT_LOG=lint.log |
| 21 | |
| 22 | THRIFT_VER=0.14 |
| 23 | THRIFT_IMG=jaegertracing/thrift:$(THRIFT_VER) |
| 24 | THRIFT=docker run -v "${PWD}:/data" $(THRIFT_IMG) thrift |
| 25 | THRIFT_GO_ARGS=thrift_import="github.com/apache/thrift/lib/go/thrift" |
| 26 | THRIFT_GEN_DIR=thrift-gen |
| 27 | |
| 28 | PASS=$(shell printf "\033[32mPASS\033[0m") |
| 29 | FAIL=$(shell printf "\033[31mFAIL\033[0m") |
| 30 | COLORIZE=sed ''/PASS/s//$(PASS)/'' | sed ''/FAIL/s//$(FAIL)/'' |
| 31 | |
| 32 | .DEFAULT_GOAL := test-and-lint |
| 33 | |
| 34 | .PHONY: test-and-lint |
| 35 | test-and-lint: test fmt lint |
| 36 | |
| 37 | .PHONY: test |
| 38 | test: |
| 39 | ifeq ($(USE_DEP),true) |
| 40 | dep check |
| 41 | endif |
| 42 | bash -c "set -e; set -o pipefail; $(GOTEST) $(PACKAGES) | $(COLORIZE)" |
| 43 | |
| 44 | .PHONY: fmt |
| 45 | fmt: |
| 46 | $(GOFMT) -e -s -l -w $(ALL_SRC) |
| 47 | ./scripts/updateLicenses.sh |
| 48 | |
| 49 | .PHONY: lint |
| 50 | lint: vet golint lint-fmt lint-thrift-testing |
| 51 | |
| 52 | .PHONY: vet |
| 53 | vet: |
| 54 | $(GOVET) $(PACKAGES) |
| 55 | |
| 56 | .PHONY: golint |
| 57 | golint: |
| 58 | @cat /dev/null > $(LINT_LOG) |
| 59 | @$(foreach pkg, $(PACKAGES), $(GOLINT) $(pkg) | grep -v crossdock/thrift >> $(LINT_LOG) || true;) |
| 60 | @[ ! -s "$(LINT_LOG)" ] || (echo "Lint Failures" | cat - $(LINT_LOG) && false) |
| 61 | |
| 62 | .PHONY: lint-fmt |
| 63 | lint-fmt: |
| 64 | @$(GOFMT) -e -s -l $(ALL_SRC) > $(FMT_LOG) |
| 65 | ./scripts/updateLicenses.sh >> $(FMT_LOG) |
| 66 | @[ ! -s "$(FMT_LOG)" ] || (echo "go fmt or license check failures, run 'make fmt'" | cat - $(FMT_LOG) && false) |
| 67 | |
| 68 | # make sure thrift/ module does not import "testing" |
| 69 | .PHONY: lint-thrift-testing |
| 70 | lint-thrift-testing: |
| 71 | @cat /dev/null > $(LINT_LOG) |
| 72 | @(grep -rn '"testing"' thrift | grep -v README.md > $(LINT_LOG)) || true |
| 73 | @[ ! -s "$(LINT_LOG)" ] || (echo '"thrift" module must not import "testing", see issue #585' | cat - $(LINT_LOG) && false) |
| 74 | |
| 75 | .PHONY: install |
| 76 | install: |
| 77 | @echo install: USE_DEP=$(USE_DEP) USE_GLIDE=$(USE_GLIDE) |
| 78 | ifeq ($(USE_DEP),true) |
| 79 | dep version || make install-dep |
| 80 | dep ensure -vendor-only -v |
| 81 | endif |
| 82 | ifeq ($(USE_GLIDE),true) |
| 83 | glide --version || go get github.com/Masterminds/glide |
| 84 | glide install |
| 85 | endif |
| 86 | |
| 87 | |
| 88 | .PHONY: cover |
| 89 | cover: |
| 90 | $(GOTEST) -cover -coverprofile cover.out $(PACKAGES) |
| 91 | |
| 92 | .PHONY: cover-html |
| 93 | cover-html: cover |
| 94 | go tool cover -html=cover.out -o cover.html |
| 95 | |
| 96 | # This is not part of the regular test target because we don't want to slow it |
| 97 | # down. |
| 98 | .PHONY: test-examples |
| 99 | test-examples: |
| 100 | make -C examples |
| 101 | |
| 102 | .PHONY: thrift |
| 103 | thrift: idl-submodule thrift-compile |
| 104 | |
| 105 | # TODO at the moment we're not generating tchan_*.go files |
| 106 | .PHONY: thrift-compile |
| 107 | thrift-compile: thrift-image |
| 108 | $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/$(THRIFT_GEN_DIR) /data/idl/thrift/agent.thrift |
| 109 | $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/$(THRIFT_GEN_DIR) /data/idl/thrift/sampling.thrift |
| 110 | $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/$(THRIFT_GEN_DIR) /data/idl/thrift/jaeger.thrift |
| 111 | $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/$(THRIFT_GEN_DIR) /data/idl/thrift/zipkincore.thrift |
| 112 | $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/$(THRIFT_GEN_DIR) /data/idl/thrift/baggage.thrift |
| 113 | $(THRIFT) -o /data --gen go:$(THRIFT_GO_ARGS) --out /data/crossdock/thrift/ /data/idl/thrift/crossdock/tracetest.thrift |
| 114 | sed -i '' 's|"zipkincore"|"$(PROJECT_ROOT)/thrift-gen/zipkincore"|g' $(THRIFT_GEN_DIR)/agent/*.go |
| 115 | sed -i '' 's|"jaeger"|"$(PROJECT_ROOT)/thrift-gen/jaeger"|g' $(THRIFT_GEN_DIR)/agent/*.go |
| 116 | sed -i '' 's|"github.com/apache/thrift/lib/go/thrift"|"github.com/uber/jaeger-client-go/thrift"|g' \ |
| 117 | $(THRIFT_GEN_DIR)/*/*.go crossdock/thrift/tracetest/*.go |
| 118 | rm -rf thrift-gen/*/*-remote |
| 119 | rm -rf crossdock/thrift/*/*-remote |
| 120 | rm -rf thrift-gen/jaeger/collector.go |
| 121 | |
| 122 | .PHONY: idl-submodule |
| 123 | idl-submodule: |
| 124 | git submodule init |
| 125 | git submodule update |
| 126 | |
| 127 | .PHONY: thrift-image |
| 128 | thrift-image: |
| 129 | $(THRIFT) -version |
| 130 | |
| 131 | .PHONY: install-dep |
| 132 | install-dep: |
| 133 | - curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o $$GOPATH/bin/dep |
| 134 | - chmod +x $$GOPATH/bin/dep |
| 135 | |
| 136 | .PHONY: install-ci |
| 137 | install-ci: install |
| 138 | go get github.com/wadey/gocovmerge |
| 139 | go get github.com/mattn/goveralls |
| 140 | go get golang.org/x/tools/cmd/cover |
| 141 | go get golang.org/x/lint/golint |
| 142 | |
| 143 | .PHONY: test-ci |
| 144 | test-ci: cover |
| 145 | ifeq ($(CI_SKIP_LINT),true) |
| 146 | echo 'skipping lint' |
| 147 | else |
| 148 | make lint |
| 149 | endif |